xref: /trunk/main/sw/inc/index.hxx (revision 1d2dbeb0)
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 #ifndef _INDEX_HXX
24 #define _INDEX_HXX
25 
26 #include <limits.h>
27 #include <tools/solar.h>
28 #include <tools/rtti.hxx>				// for RTTI of SwIndexReg
29 #include <tools/string.hxx>				// for xub_StrLen
30 #include <swdllapi.h>
31 
32 #define INVALID_INDEX STRING_NOTFOUND
33 
34 // Maximale Anzahl von Indizies im IndexArray (zum Abtesten auf Ueberlaeufe)
35 class SwIndex;
36 class SwIndexReg;
37 struct SwPosition;
38 
39 #ifndef DBG_UTIL
40 #define INLINE inline
41 #else
42 #define INLINE
43 #endif
44 
45 class SW_DLLPUBLIC SwIndex
46 {
47 	friend class SwIndexReg;
48 
49 #ifdef DBG_UTIL
50 	static int nSerial;
51 	int MySerial;
52 #endif
53 
54 	xub_StrLen	nIndex;
55 	SwIndexReg*	pArray;
56 	SwIndex *pNext, *pPrev;
57 
58 	SwIndex& ChgValue( const SwIndex& rIdx, xub_StrLen nNewValue );
59 	void Remove();					// Ausketten
60 
61 public:
62     explicit SwIndex(SwIndexReg *const pReg, xub_StrLen const nIdx = 0);
63 	SwIndex( const SwIndex & );
64 	SwIndex( const SwIndex &, short nDiff );
~SwIndex()65 	~SwIndex() { Remove(); }
66 
67     INLINE xub_StrLen operator++();
68     INLINE xub_StrLen operator--();
69 #ifndef CFRONT
70     INLINE xub_StrLen operator++(int);
71     INLINE xub_StrLen operator--(int);
72 #endif
73 
74     INLINE xub_StrLen operator+=( xub_StrLen );
75     INLINE xub_StrLen operator-=( xub_StrLen );
76     INLINE xub_StrLen operator+=( const SwIndex& );
77     INLINE xub_StrLen operator-=( const SwIndex& );
78 
79     INLINE sal_Bool operator<( const SwIndex& ) const;
80     INLINE sal_Bool operator<=( const SwIndex& ) const;
81     INLINE sal_Bool operator>( const SwIndex& ) const;
82     INLINE sal_Bool operator>=( const SwIndex& ) const;
operator ==(const SwIndex & rSwIndex) const83 	sal_Bool operator==( const SwIndex& rSwIndex ) const
84 	{ return (nIndex == rSwIndex.nIndex) &&  (pArray == rSwIndex.pArray); }
85 
operator !=(const SwIndex & rSwIndex) const86 	sal_Bool operator!=( const SwIndex& rSwIndex ) const
87 	{ return (nIndex != rSwIndex.nIndex) ||  (pArray != rSwIndex.pArray); }
88 
operator <(xub_StrLen nWert) const89 	sal_Bool operator<( xub_StrLen nWert ) const 	{ return nIndex <  nWert; }
operator <=(xub_StrLen nWert) const90 	sal_Bool operator<=( xub_StrLen nWert ) const   { return nIndex <= nWert; }
operator >(xub_StrLen nWert) const91 	sal_Bool operator>( xub_StrLen nWert ) const    { return nIndex >  nWert; }
operator >=(xub_StrLen nWert) const92 	sal_Bool operator>=( xub_StrLen nWert ) const   { return nIndex >= nWert; }
operator ==(xub_StrLen nWert) const93 	sal_Bool operator==( xub_StrLen nWert ) const   { return nIndex == nWert; }
operator !=(xub_StrLen nWert) const94 	sal_Bool operator!=( xub_StrLen nWert ) const   { return nIndex != nWert; }
95 
96     INLINE SwIndex& operator=( xub_StrLen );
97 	SwIndex& operator=( const SwIndex & );
98 
99 	// gebe den Wert vom Index als xub_StrLen zurueck
GetIndex() const100 	xub_StrLen GetIndex() const	{ return nIndex; }
101 
102 	// ermoeglicht Zuweisungen ohne Erzeugen eines temporaeren
103 	// Objektes
104 	SwIndex &Assign(SwIndexReg *,xub_StrLen);
105 
106 		// Herausgabe des Pointers auf das IndexArray,
107 		// (fuers RTTI am SwIndexReg)
GetIdxReg() const108 	const SwIndexReg* GetIdxReg() const { return pArray; }
109 };
110 
111 #undef INLINE
112 
113 class SwIndexReg
114 {
115 	friend class SwIndex;
116     friend bool lcl_PosOk(const SwPosition & aPos);
117 
118     const SwIndex *pFirst, *pLast, *pMiddle;
119 
120 	// ein globales Array, in das Indizies verschoben werden, die mal
121 	// temporaer "ausgelagert" werden muessen; oder die zum Zeitpunkt des
122 	// anlegens kein gueltiges Array kennen (SwPaM/SwPosition!)
123 	friend void _InitCore();
124 	friend void _FinitCore();
125 	static SwIndexReg* pEmptyIndexArray;
126 
127 protected:
128     virtual void Update( SwIndex const & rPos, const xub_StrLen nChangeLen,
129                  const bool bNegative = false, const bool bDelete = false );
130 
131 	void ChkArr();
132 
HasAnyIndex() const133 	sal_Bool HasAnyIndex() const { return 0 != pFirst; }
134 
135 public:
136 	SwIndexReg();
137     virtual ~SwIndexReg();
138 
139 	// rtti, abgeleitete moegens gleichtun oder nicht. Wenn sie es gleichtun
140 	// kann ueber das SwIndexReg typsicher gecastet werden.
141 	TYPEINFO();
142 
143     void MoveTo( SwIndexReg& rArr );
144 };
145 
146 #ifndef DBG_UTIL
147 
operator ++()148 inline xub_StrLen SwIndex::operator++()
149 {
150     return ChgValue( *this, nIndex+1 ).nIndex;
151 }
operator --()152 inline xub_StrLen SwIndex::operator--()
153 {
154     return ChgValue( *this, nIndex-1 ).nIndex;
155 }
156 #ifndef CFRONT
operator ++(int)157 inline xub_StrLen SwIndex::operator++(int)
158 {
159     xub_StrLen nOldIndex = nIndex;
160     ChgValue( *this, nIndex+1 );
161     return nOldIndex;
162 }
operator --(int)163 inline xub_StrLen SwIndex::operator--(int)
164 {
165     xub_StrLen nOldIndex = nIndex;
166     ChgValue( *this, nIndex-1 );
167     return nOldIndex;
168 }
169 #endif
170 
operator +=(xub_StrLen nWert)171 inline xub_StrLen SwIndex::operator+=( xub_StrLen nWert )
172 {
173     return ChgValue( *this, nIndex + nWert ).nIndex;
174 }
operator -=(xub_StrLen nWert)175 inline xub_StrLen SwIndex::operator-=( xub_StrLen nWert )
176 {
177     return ChgValue( *this, nIndex - nWert ).nIndex;
178 }
operator +=(const SwIndex & rIndex)179 inline xub_StrLen SwIndex::operator+=( const  SwIndex& rIndex )
180 {
181     return ChgValue( *this, nIndex + rIndex.nIndex ).nIndex;
182 }
operator -=(const SwIndex & rIndex)183 inline xub_StrLen SwIndex::operator-=( const SwIndex& rIndex )
184 {
185     return ChgValue( *this, nIndex - rIndex.nIndex ).nIndex;
186 }
187 
operator <(const SwIndex & rIndex) const188 inline sal_Bool SwIndex::operator<( const SwIndex& rIndex ) const
189 {
190     return nIndex < rIndex.nIndex;
191 }
operator <=(const SwIndex & rIndex) const192 inline sal_Bool SwIndex::operator<=( const SwIndex& rIndex ) const
193 {
194     return nIndex <= rIndex.nIndex;
195 }
operator >(const SwIndex & rIndex) const196 inline sal_Bool SwIndex::operator>( const SwIndex& rIndex ) const
197 {
198     return nIndex > rIndex.nIndex;
199 }
operator >=(const SwIndex & rIndex) const200 inline sal_Bool SwIndex::operator>=( const SwIndex& rIndex ) const
201 {
202     return nIndex >= rIndex.nIndex;
203 }
operator =(xub_StrLen nWert)204 inline SwIndex& SwIndex::operator=( xub_StrLen nWert )
205 {
206     if( nIndex != nWert )
207         ChgValue( *this, nWert );
208     return *this;
209 }
210 
211 #endif // PRODUCT
212 
213 #endif
214