1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #ifndef INCLUDED_WW8_PIECE_TABLE_HXX
25 #define INCLUDED_WW8_PIECE_TABLE_HXX
26 
27 #include <sal/types.h>
28 #include <doctok/WW8Document.hxx>
29 
30 #include <boost/shared_ptr.hpp>
31 #include <iostream>
32 
33 namespace writerfilter {
34 namespace doctok {
35 
36 using namespace ::std;
37 
38 struct Cp;
39 struct Fc;
40 class CpAndFc;
41 
42 /**
43    The piece table of a Word document.
44 
45    The piece table associates character positions (CP) and File
46    character positions (FC). In a FC based view the piece table
47    defines intervals of FCs that contain consecutive text.
48 
49    CPs and FCs can be complex, i.e. the associated text is stored in
50    bytes. Otherwise the text encoding is UTF-16.
51  */
52 class WW8PieceTable
53 {
54 public:
~WW8PieceTable()55     virtual ~WW8PieceTable() {}
56     /**
57        Shared pointer to piece table
58      */
59     typedef boost::shared_ptr<WW8PieceTable> Pointer_t;
60 
61     /**
62        Convert CP to FC.
63 
64        @param aCpIn    CP to convert
65 
66        @return FC associated with CP
67      */
68     virtual Fc cp2fc(const Cp & aCpIn) const = 0;
69 
70     /**
71        Convert FC to CP.
72 
73        @param aFcIn    FC to convert
74 
75        @return CP associated with FC
76      */
77     virtual Cp fc2cp(const Fc & aFcIn) const = 0;
78 
79     /**
80        Check if CP is complex.
81 
82        @param  aCp    CP to check
83        @retval true   CP is complex
84        @retval false  else
85      */
86     virtual bool isComplex(const Cp & aCp) const = 0;
87 
88     /**
89        Check if FC is complex.
90 
91        @param  aFc    FC to check
92        @retval true   FC is complex
93        @retval false  else
94      */
95     virtual bool isComplex(const Fc & aFc) const = 0;
96 
97     /**
98        Return number of entries.
99      */
100     virtual sal_uInt32 getCount() const = 0;
101 
102     /**
103        Return first CP.
104      */
105     virtual Cp getFirstCp() const = 0;
106 
107     /**
108        Return first FC.
109     */
110     virtual Fc getFirstFc() const = 0;
111 
112     /**
113        Return last CP.
114     */
115     virtual Cp getLastCp() const = 0;
116 
117     /**
118         Return last FC.
119     */
120     virtual Fc getLastFc() const = 0;
121 
122     /**
123        Return CP at index.
124 
125        @param  nIndex    index of CP to return
126      */
127     virtual Cp getCp(sal_uInt32 nIndex) const = 0;
128 
129     /**
130        Return FC at index.
131 
132        @param nIndex     index of FC to return
133     */
134     virtual Fc getFc(sal_uInt32 nIndex) const = 0;
135 
136     /**
137         Create CpAndFc from Cp.
138 
139         @param rCp   the Cp
140 
141         @return CpAndFc containing rCp and corresponding Fc
142     */
143     virtual CpAndFc createCpAndFc(const Cp & rCp, PropertyType eType) const = 0;
144 
145     /**
146         Create CpAndFc from Fc.
147 
148         @param rFc   the Fc
149 
150         @return CpAndFc containing rFc and corresponding Cp
151     */
152     virtual CpAndFc createCpAndFc(const Fc & rFc, PropertyType eType) const = 0;
153 
154     /**
155        Dump piece table.
156 
157        @param o        stream to dump to
158     */
159     virtual void dump(ostream & o) const = 0;
160 };
161 
162 /**
163    Dump piece table.
164 
165    @param o             stream to dump to
166    @param rPieceTable   piece table to dump
167 */
168 ostream & operator << (ostream & o, const WW8PieceTable & rPieceTable);
169 }}
170 
171 #endif // INCLUDED_WW8_PIECE_TABLE_HXX
172