merge the formfield patch from ooo-build
[ooovba.git] / sw / inc / index.hxx
blob755f3694f179aa723c95595733c8295462a67982
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: index.hxx,v $
10 * $Revision: 1.10 $
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 ************************************************************************/
30 #ifndef _INDEX_HXX
31 #define _INDEX_HXX
33 #include <limits.h>
34 #include <tools/solar.h>
35 #include <tools/rtti.hxx> // for RTTI of SwIndexReg
36 #include <tools/string.hxx> // for xub_StrLen
37 #include <swdllapi.h>
39 #define INVALID_INDEX STRING_NOTFOUND
41 // Maximale Anzahl von Indizies im IndexArray (zum Abtesten auf Ueberlaeufe)
42 class SwIndex;
43 class SwIndexReg;
44 struct SwPosition;
46 #ifdef PRODUCT
47 #define INLINE inline
48 #else
49 #define INLINE
50 #endif
52 class SW_DLLPUBLIC SwIndex
54 friend class SwIndexReg;
56 #ifndef PRODUCT
57 static int nSerial;
58 int MySerial;
59 #endif
61 xub_StrLen nIndex;
62 SwIndexReg* pArray;
63 SwIndex *pNext, *pPrev;
65 SwIndex& ChgValue( const SwIndex& rIdx, xub_StrLen nNewValue );
66 void Remove(); // Ausketten
68 public:
69 SwIndex( SwIndexReg * pReg, xub_StrLen nIdx = 0 );
70 SwIndex( const SwIndex & );
71 SwIndex( const SwIndex &, short nDiff );
72 ~SwIndex() { Remove(); }
74 INLINE xub_StrLen operator++();
75 INLINE xub_StrLen operator--();
76 #ifndef CFRONT
77 INLINE xub_StrLen operator++(int);
78 INLINE xub_StrLen operator--(int);
79 #endif
81 INLINE xub_StrLen operator+=( xub_StrLen );
82 INLINE xub_StrLen operator-=( xub_StrLen );
83 INLINE xub_StrLen operator+=( const SwIndex& );
84 INLINE xub_StrLen operator-=( const SwIndex& );
86 INLINE BOOL operator<( const SwIndex& ) const;
87 INLINE BOOL operator<=( const SwIndex& ) const;
88 INLINE BOOL operator>( const SwIndex& ) const;
89 INLINE BOOL operator>=( const SwIndex& ) const;
90 BOOL operator==( const SwIndex& rSwIndex ) const
91 { return (nIndex == rSwIndex.nIndex) && (pArray == rSwIndex.pArray); }
93 BOOL operator!=( const SwIndex& rSwIndex ) const
94 { return (nIndex != rSwIndex.nIndex) || (pArray != rSwIndex.pArray); }
96 BOOL operator<( xub_StrLen nWert ) const { return nIndex < nWert; }
97 BOOL operator<=( xub_StrLen nWert ) const { return nIndex <= nWert; }
98 BOOL operator>( xub_StrLen nWert ) const { return nIndex > nWert; }
99 BOOL operator>=( xub_StrLen nWert ) const { return nIndex >= nWert; }
100 BOOL operator==( xub_StrLen nWert ) const { return nIndex == nWert; }
101 BOOL operator!=( xub_StrLen nWert ) const { return nIndex != nWert; }
103 INLINE SwIndex& operator=( xub_StrLen );
104 SwIndex& operator=( const SwIndex & );
106 // gebe den Wert vom Index als xub_StrLen zurueck
107 xub_StrLen GetIndex() const { return nIndex; }
109 // ermoeglicht Zuweisungen ohne Erzeugen eines temporaeren
110 // Objektes
111 SwIndex &Assign(SwIndexReg *,xub_StrLen);
113 // Herausgabe des Pointers auf das IndexArray,
114 // (fuers RTTI am SwIndexReg)
115 const SwIndexReg* GetIdxReg() const { return pArray; }
118 #undef INLINE
120 class SwIndexReg
122 friend class SwIndex;
123 friend bool lcl_PosOk(const SwPosition & aPos);
125 const SwIndex *pFirst, *pLast, *pMiddle;
127 // ein globales Array, in das Indizies verschoben werden, die mal
128 // temporaer "ausgelagert" werden muessen; oder die zum Zeitpunkt des
129 // anlegens kein gueltiges Array kennen (SwPaM/SwPosition!)
130 friend void _InitCore();
131 friend void _FinitCore();
132 static SwIndexReg* pEmptyIndexArray;
134 protected:
135 virtual void Update( SwIndex const & rPos, const xub_StrLen nChangeLen,
136 const bool bNegative = false, const bool bDelete = false );
138 void ChkArr();
140 BOOL HasAnyIndex() const { return 0 != pFirst; }
142 public:
143 SwIndexReg();
144 virtual ~SwIndexReg();
146 // rtti, abgeleitete moegens gleichtun oder nicht. Wenn sie es gleichtun
147 // kann ueber das SwIndexReg typsicher gecastet werden.
148 TYPEINFO();
150 void MoveTo( SwIndexReg& rArr );
153 #ifdef PRODUCT
155 inline xub_StrLen SwIndex::operator++()
157 return ChgValue( *this, nIndex+1 ).nIndex;
159 inline xub_StrLen SwIndex::operator--()
161 return ChgValue( *this, nIndex-1 ).nIndex;
163 #ifndef CFRONT
164 inline xub_StrLen SwIndex::operator++(int)
166 xub_StrLen nOldIndex = nIndex;
167 ChgValue( *this, nIndex+1 );
168 return nOldIndex;
170 inline xub_StrLen SwIndex::operator--(int)
172 xub_StrLen nOldIndex = nIndex;
173 ChgValue( *this, nIndex-1 );
174 return nOldIndex;
176 #endif
178 inline xub_StrLen SwIndex::operator+=( xub_StrLen nWert )
180 return ChgValue( *this, nIndex + nWert ).nIndex;
182 inline xub_StrLen SwIndex::operator-=( xub_StrLen nWert )
184 return ChgValue( *this, nIndex - nWert ).nIndex;
186 inline xub_StrLen SwIndex::operator+=( const SwIndex& rIndex )
188 return ChgValue( *this, nIndex + rIndex.nIndex ).nIndex;
190 inline xub_StrLen SwIndex::operator-=( const SwIndex& rIndex )
192 return ChgValue( *this, nIndex - rIndex.nIndex ).nIndex;
195 inline BOOL SwIndex::operator<( const SwIndex& rIndex ) const
197 return nIndex < rIndex.nIndex;
199 inline BOOL SwIndex::operator<=( const SwIndex& rIndex ) const
201 return nIndex <= rIndex.nIndex;
203 inline BOOL SwIndex::operator>( const SwIndex& rIndex ) const
205 return nIndex > rIndex.nIndex;
207 inline BOOL SwIndex::operator>=( const SwIndex& rIndex ) const
209 return nIndex >= rIndex.nIndex;
211 inline SwIndex& SwIndex::operator=( xub_StrLen nWert )
213 if( nIndex != nWert )
214 ChgValue( *this, nWert );
215 return *this;
218 #endif // PRODUCT
220 #endif