Update ooo320-m1
[ooovba.git] / writerfilter / source / doctok / WW8CpAndFc.hxx
blobb06b36705632882981a4a4429f652954acac4174
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: WW8CpAndFc.hxx,v $
10 * $Revision: 1.5 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #ifndef INCLUDED_WW8_CP_AND_FC_HXX
32 #define INCLUDED_WW8_CP_AND_FC_HXX
34 #include <sal/types.h>
35 #ifndef INCLUDED_DOCUMENT_HXX
36 #include <doctok/WW8Document.hxx>
37 #endif
38 #include <set>
39 #include <hash_map>
40 #include <iostream>
42 namespace writerfilter {
43 namespace doctok
45 using namespace ::std;
47 template <class T>
48 bool operator <= (const T & rA, const T & rB)
50 return ! ( rB < rA );
53 /**
54 A character position.
56 This is a wrapper to make the type for WW8 character position (CP)
57 distinct from WW8 file character positions (FC).
59 struct Cp
61 sal_uInt32 nCp; // the WW8 character position
63 Cp() : nCp(0) {}
65 Cp(sal_uInt32 nCp_) : nCp(nCp_) {}
67 /**
68 Returns the WW8 character position.
70 @return the WW8 character position
72 sal_uInt32 get() const { return nCp; }
74 /**
75 Sets the WW8 character position.
77 @param nCp_ the WW8 character position to set
79 void set(sal_uInt32 nCp_) { nCp = nCp_; }
81 /**
82 Calculate CP moved backward.
84 None of the involved CPs is changed.
86 @param n amount of movement
88 @return CP moved @n steps backward
90 sal_uInt32 operator - (const Cp & rCp) const
91 { return nCp - rCp.nCp; }
93 /**
94 Calculate CP moved forward.
96 None of the involved CPs is changed.
98 @param n amount of movement
100 @return CP moved @n steps forward
102 Cp operator + (sal_uInt32 n) const
103 { return Cp(nCp + n); }
106 Advance CP forward.
108 @attention The CP is altered.
110 @param n amount of movement
112 @return CP moved @n steps forward
114 Cp & operator += (sal_uInt32 n)
116 nCp += n;
118 return *this;
122 Return string representation of CP.
124 string toString() const;
126 friend bool operator < (const Cp & rA, const Cp & rB);
127 friend bool operator == (const Cp & rA, const Cp & rB);
128 friend ostream & operator << (ostream & o, const Cp & rCp);
132 A file character position.
134 This is a wrapper to make the type for WW8 character position (CP)
135 distinct from WW8 file character positions (FC).
137 \see{Cp}
139 struct Fc
141 sal_uInt32 mnFc; // the WW8 character position
142 bool mbComplex;
144 Fc() : mnFc(0), mbComplex(false) {}
146 Fc(sal_uInt32 nFc, bool bComplex = true)
147 : mnFc(nFc), mbComplex(bComplex)
150 sal_uInt32 complexFactor() const { return mbComplex ? 1 : 2; }
153 Returns the WW8 character position.
155 @return the WW8 character position
157 sal_uInt32 get() const { return mnFc; }
160 Sets the WW8 file character position.
162 @param nFc the WW8 file character position to set
164 void set(sal_uInt32 nFc) { mnFc = nFc; }
167 Set if the FC is complex.
169 @param bComplex true if FC is set to be complex
171 void setComplex(bool bComplex) { mbComplex = bComplex; }
174 Return if FC is complex.
176 @retval true FC is complex
177 @retval false else
179 bool isComplex() const { return mbComplex; }
182 Distance of FCs.
184 None of the involved FCs is changed.
186 @param rFc FC to calculate distance to
188 @return Distance from @a rFc to this FC
190 sal_uInt32 operator - (const Fc & rFc) const
191 { return (mnFc - rFc.mnFc) / complexFactor(); }
194 Calculate FC moved backward.
196 None of the involved FCs is changed.
198 @param n amount of movement
200 @return FC moved @n steps backward
202 Fc operator - (sal_uInt32 n) const
203 { return Fc(mnFc - n * complexFactor(), mbComplex); }
206 Calculate FC moved forward.
208 None of the involved FCs is changed.
210 @param n amount of movement
212 @return FC moved @n steps Forward
214 Fc operator + (sal_uInt32 n) const
215 { return Fc(mnFc + n * complexFactor(), mbComplex); }
218 Return string representation of FC.
220 string toString() const;
222 friend bool operator < (const Fc & rA, const Fc & rB);
223 friend bool operator == (const Fc & rA, const Fc & rB);
224 friend ostream & operator << (ostream & o, const Fc & rFc);
228 A character position and a corresponding file character position
229 paired.
231 class CpAndFc
233 private:
235 character position
237 Cp mCp;
240 file character position
242 Fc mFc;
245 property type
247 PropertyType mType;
249 public:
250 CpAndFc() {}
251 CpAndFc(const Cp & rCp, const Fc & rFc, PropertyType eType_);
254 Return character position.
256 const Cp & getCp() const { return mCp; }
259 Return file character position.
261 const Fc & getFc() const { return mFc; }
264 Return property type.
266 PropertyType getType() const { return mType; }
269 Return if FC is complex.
271 @retval true FC is complex
272 @retval false else
274 bool isComplex() const { return mFc.isComplex(); }
277 Return the distance to other CpAndFc.
279 @param rCpAndFc the other CpAndFc
281 @return the distance from the CP in @a rCpAndFc to the CP in
282 CpAndFc.
284 sal_uInt32 operator-(const CpAndFc & rCpAndFc) const
285 { return mCp - rCpAndFc.mCp; }
288 Return string representation of the CpAndFc.
290 string toString() const;
292 friend bool operator < (const CpAndFc & rA, const CpAndFc & rB);
293 friend bool operator == (const CpAndFc & rA, const CpAndFc & rB);
294 friend ostream & operator << (ostream & o, const CpAndFc & rCpAndFc);
297 struct CpAndFcLess
299 CpAndFcLess()
303 bool operator()(const CpAndFc & rA, const CpAndFc & rB) const
305 return rA < rB;
308 bool operator()(const CpAndFc & rA, const Cp & rB) const
310 return rA.getCp() < rB;
313 bool operator()(const Cp & rA, const CpAndFc & rB) const
315 return rA < rB.getCp();
320 typedef set<CpAndFc, CpAndFcLess> CpAndFcs;
322 ostream & operator << (ostream & o, const CpAndFcs & rCpAndFcs);
324 struct CpHash
326 size_t operator()(const Cp & rCp) const
328 return rCp.get();
332 struct FcHash
334 size_t operator()(const Fc & rFc) const
336 return rFc.get();
340 struct CpEq
342 bool operator() (const Cp & rA, const Cp &rB) const
344 return rA == rB;
348 struct CpAndFcHash
350 size_t operator()(const CpAndFc & rCpAndFc) const
352 CpHash aHash;
354 return aHash(rCpAndFc.getCp());
358 typedef hash_map<Cp, Fc, CpHash, CpEq> Cp2FcHashMap_t;
360 } // namespace doctok
361 } // namespace writerfilter
363 #endif // INCLUDED_WW8_CP_AND_FC_HXX