xref: /trunk/main/sw/inc/index.hxx (revision 914d351e5f5b84e4342a86d6ab8d4aca7308b9bd)
1*1d2dbeb0SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*1d2dbeb0SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*1d2dbeb0SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*1d2dbeb0SAndrew Rist  * distributed with this work for additional information
6*1d2dbeb0SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*1d2dbeb0SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*1d2dbeb0SAndrew Rist  * "License"); you may not use this file except in compliance
9*1d2dbeb0SAndrew Rist  * with the License.  You may obtain a copy of the License at
10cdf0e10cSrcweir  *
11*1d2dbeb0SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir  *
13*1d2dbeb0SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*1d2dbeb0SAndrew Rist  * software distributed under the License is distributed on an
15*1d2dbeb0SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*1d2dbeb0SAndrew Rist  * KIND, either express or implied.  See the License for the
17*1d2dbeb0SAndrew Rist  * specific language governing permissions and limitations
18*1d2dbeb0SAndrew Rist  * under the License.
19cdf0e10cSrcweir  *
20*1d2dbeb0SAndrew Rist  *************************************************************/
21*1d2dbeb0SAndrew Rist 
22*1d2dbeb0SAndrew Rist 
23cdf0e10cSrcweir #ifndef _INDEX_HXX
24cdf0e10cSrcweir #define _INDEX_HXX
25cdf0e10cSrcweir 
26cdf0e10cSrcweir #include <limits.h>
27cdf0e10cSrcweir #include <tools/solar.h>
28cdf0e10cSrcweir #include <tools/rtti.hxx>               // for RTTI of SwIndexReg
29cdf0e10cSrcweir #include <tools/string.hxx>             // for xub_StrLen
30cdf0e10cSrcweir #include <swdllapi.h>
31cdf0e10cSrcweir 
32cdf0e10cSrcweir #define INVALID_INDEX STRING_NOTFOUND
33cdf0e10cSrcweir 
34cdf0e10cSrcweir // Maximale Anzahl von Indizies im IndexArray (zum Abtesten auf Ueberlaeufe)
35cdf0e10cSrcweir class SwIndex;
36cdf0e10cSrcweir class SwIndexReg;
37cdf0e10cSrcweir struct SwPosition;
38cdf0e10cSrcweir 
39cdf0e10cSrcweir #ifndef DBG_UTIL
40cdf0e10cSrcweir #define INLINE inline
41cdf0e10cSrcweir #else
42cdf0e10cSrcweir #define INLINE
43cdf0e10cSrcweir #endif
44cdf0e10cSrcweir 
45cdf0e10cSrcweir class SW_DLLPUBLIC SwIndex
46cdf0e10cSrcweir {
47cdf0e10cSrcweir     friend class SwIndexReg;
48cdf0e10cSrcweir 
49cdf0e10cSrcweir #ifdef DBG_UTIL
50cdf0e10cSrcweir     static int nSerial;
51cdf0e10cSrcweir     int MySerial;
52cdf0e10cSrcweir #endif
53cdf0e10cSrcweir 
54cdf0e10cSrcweir     xub_StrLen  nIndex;
55cdf0e10cSrcweir     SwIndexReg* pArray;
56cdf0e10cSrcweir     SwIndex *pNext, *pPrev;
57cdf0e10cSrcweir 
58cdf0e10cSrcweir     SwIndex& ChgValue( const SwIndex& rIdx, xub_StrLen nNewValue );
59cdf0e10cSrcweir     void Remove();                  // Ausketten
60cdf0e10cSrcweir 
61cdf0e10cSrcweir public:
62cdf0e10cSrcweir     explicit SwIndex(SwIndexReg *const pReg, xub_StrLen const nIdx = 0);
63cdf0e10cSrcweir     SwIndex( const SwIndex & );
64cdf0e10cSrcweir     SwIndex( const SwIndex &, short nDiff );
~SwIndex()65cdf0e10cSrcweir     ~SwIndex() { Remove(); }
66cdf0e10cSrcweir 
67cdf0e10cSrcweir     INLINE xub_StrLen operator++();
68cdf0e10cSrcweir     INLINE xub_StrLen operator--();
69cdf0e10cSrcweir #ifndef CFRONT
70cdf0e10cSrcweir     INLINE xub_StrLen operator++(int);
71cdf0e10cSrcweir     INLINE xub_StrLen operator--(int);
72cdf0e10cSrcweir #endif
73cdf0e10cSrcweir 
74cdf0e10cSrcweir     INLINE xub_StrLen operator+=( xub_StrLen );
75cdf0e10cSrcweir     INLINE xub_StrLen operator-=( xub_StrLen );
76cdf0e10cSrcweir     INLINE xub_StrLen operator+=( const SwIndex& );
77cdf0e10cSrcweir     INLINE xub_StrLen operator-=( const SwIndex& );
78cdf0e10cSrcweir 
79cdf0e10cSrcweir     INLINE sal_Bool operator<( const SwIndex& ) const;
80cdf0e10cSrcweir     INLINE sal_Bool operator<=( const SwIndex& ) const;
81cdf0e10cSrcweir     INLINE sal_Bool operator>( const SwIndex& ) const;
82cdf0e10cSrcweir     INLINE sal_Bool operator>=( const SwIndex& ) const;
operator ==(const SwIndex & rSwIndex) const83cdf0e10cSrcweir     sal_Bool operator==( const SwIndex& rSwIndex ) const
84cdf0e10cSrcweir     { return (nIndex == rSwIndex.nIndex) &&  (pArray == rSwIndex.pArray); }
85cdf0e10cSrcweir 
operator !=(const SwIndex & rSwIndex) const86cdf0e10cSrcweir     sal_Bool operator!=( const SwIndex& rSwIndex ) const
87cdf0e10cSrcweir     { return (nIndex != rSwIndex.nIndex) ||  (pArray != rSwIndex.pArray); }
88cdf0e10cSrcweir 
operator <(xub_StrLen nWert) const89cdf0e10cSrcweir     sal_Bool operator<( xub_StrLen nWert ) const    { return nIndex <  nWert; }
operator <=(xub_StrLen nWert) const90cdf0e10cSrcweir     sal_Bool operator<=( xub_StrLen nWert ) const   { return nIndex <= nWert; }
operator >(xub_StrLen nWert) const91cdf0e10cSrcweir     sal_Bool operator>( xub_StrLen nWert ) const    { return nIndex >  nWert; }
operator >=(xub_StrLen nWert) const92cdf0e10cSrcweir     sal_Bool operator>=( xub_StrLen nWert ) const   { return nIndex >= nWert; }
operator ==(xub_StrLen nWert) const93cdf0e10cSrcweir     sal_Bool operator==( xub_StrLen nWert ) const   { return nIndex == nWert; }
operator !=(xub_StrLen nWert) const94cdf0e10cSrcweir     sal_Bool operator!=( xub_StrLen nWert ) const   { return nIndex != nWert; }
95cdf0e10cSrcweir 
96cdf0e10cSrcweir     INLINE SwIndex& operator=( xub_StrLen );
97cdf0e10cSrcweir     SwIndex& operator=( const SwIndex & );
98cdf0e10cSrcweir 
99cdf0e10cSrcweir     // gebe den Wert vom Index als xub_StrLen zurueck
GetIndex() const100cdf0e10cSrcweir     xub_StrLen GetIndex() const { return nIndex; }
101cdf0e10cSrcweir 
102cdf0e10cSrcweir     // ermoeglicht Zuweisungen ohne Erzeugen eines temporaeren
103cdf0e10cSrcweir     // Objektes
104cdf0e10cSrcweir     SwIndex &Assign(SwIndexReg *,xub_StrLen);
105cdf0e10cSrcweir 
106cdf0e10cSrcweir         // Herausgabe des Pointers auf das IndexArray,
107cdf0e10cSrcweir         // (fuers RTTI am SwIndexReg)
GetIdxReg() const108cdf0e10cSrcweir     const SwIndexReg* GetIdxReg() const { return pArray; }
109cdf0e10cSrcweir };
110cdf0e10cSrcweir 
111cdf0e10cSrcweir #undef INLINE
112cdf0e10cSrcweir 
113cdf0e10cSrcweir class SwIndexReg
114cdf0e10cSrcweir {
115cdf0e10cSrcweir     friend class SwIndex;
116cdf0e10cSrcweir     friend bool lcl_PosOk(const SwPosition & aPos);
117cdf0e10cSrcweir 
118cdf0e10cSrcweir     const SwIndex *pFirst, *pLast, *pMiddle;
119cdf0e10cSrcweir 
120cdf0e10cSrcweir     // ein globales Array, in das Indizies verschoben werden, die mal
121cdf0e10cSrcweir     // temporaer "ausgelagert" werden muessen; oder die zum Zeitpunkt des
122cdf0e10cSrcweir     // anlegens kein gueltiges Array kennen (SwPaM/SwPosition!)
123cdf0e10cSrcweir     friend void _InitCore();
124cdf0e10cSrcweir     friend void _FinitCore();
125cdf0e10cSrcweir     static SwIndexReg* pEmptyIndexArray;
126cdf0e10cSrcweir 
127cdf0e10cSrcweir protected:
128cdf0e10cSrcweir     virtual void Update( SwIndex const & rPos, const xub_StrLen nChangeLen,
129cdf0e10cSrcweir                  const bool bNegative = false, const bool bDelete = false );
130cdf0e10cSrcweir 
131cdf0e10cSrcweir     void ChkArr();
132cdf0e10cSrcweir 
HasAnyIndex() const133cdf0e10cSrcweir     sal_Bool HasAnyIndex() const { return 0 != pFirst; }
134cdf0e10cSrcweir 
135cdf0e10cSrcweir public:
136cdf0e10cSrcweir     SwIndexReg();
137cdf0e10cSrcweir     virtual ~SwIndexReg();
138cdf0e10cSrcweir 
139cdf0e10cSrcweir     // rtti, abgeleitete moegens gleichtun oder nicht. Wenn sie es gleichtun
140cdf0e10cSrcweir     // kann ueber das SwIndexReg typsicher gecastet werden.
141cdf0e10cSrcweir     TYPEINFO();
142cdf0e10cSrcweir 
143cdf0e10cSrcweir     void MoveTo( SwIndexReg& rArr );
144cdf0e10cSrcweir };
145cdf0e10cSrcweir 
146cdf0e10cSrcweir #ifndef DBG_UTIL
147cdf0e10cSrcweir 
operator ++()148cdf0e10cSrcweir inline xub_StrLen SwIndex::operator++()
149cdf0e10cSrcweir {
150cdf0e10cSrcweir     return ChgValue( *this, nIndex+1 ).nIndex;
151cdf0e10cSrcweir }
operator --()152cdf0e10cSrcweir inline xub_StrLen SwIndex::operator--()
153cdf0e10cSrcweir {
154cdf0e10cSrcweir     return ChgValue( *this, nIndex-1 ).nIndex;
155cdf0e10cSrcweir }
156cdf0e10cSrcweir #ifndef CFRONT
operator ++(int)157cdf0e10cSrcweir inline xub_StrLen SwIndex::operator++(int)
158cdf0e10cSrcweir {
159cdf0e10cSrcweir     xub_StrLen nOldIndex = nIndex;
160cdf0e10cSrcweir     ChgValue( *this, nIndex+1 );
161cdf0e10cSrcweir     return nOldIndex;
162cdf0e10cSrcweir }
operator --(int)163cdf0e10cSrcweir inline xub_StrLen SwIndex::operator--(int)
164cdf0e10cSrcweir {
165cdf0e10cSrcweir     xub_StrLen nOldIndex = nIndex;
166cdf0e10cSrcweir     ChgValue( *this, nIndex-1 );
167cdf0e10cSrcweir     return nOldIndex;
168cdf0e10cSrcweir }
169cdf0e10cSrcweir #endif
170cdf0e10cSrcweir 
operator +=(xub_StrLen nWert)171cdf0e10cSrcweir inline xub_StrLen SwIndex::operator+=( xub_StrLen nWert )
172cdf0e10cSrcweir {
173cdf0e10cSrcweir     return ChgValue( *this, nIndex + nWert ).nIndex;
174cdf0e10cSrcweir }
operator -=(xub_StrLen nWert)175cdf0e10cSrcweir inline xub_StrLen SwIndex::operator-=( xub_StrLen nWert )
176cdf0e10cSrcweir {
177cdf0e10cSrcweir     return ChgValue( *this, nIndex - nWert ).nIndex;
178cdf0e10cSrcweir }
operator +=(const SwIndex & rIndex)179cdf0e10cSrcweir inline xub_StrLen SwIndex::operator+=( const  SwIndex& rIndex )
180cdf0e10cSrcweir {
181cdf0e10cSrcweir     return ChgValue( *this, nIndex + rIndex.nIndex ).nIndex;
182cdf0e10cSrcweir }
operator -=(const SwIndex & rIndex)183cdf0e10cSrcweir inline xub_StrLen SwIndex::operator-=( const SwIndex& rIndex )
184cdf0e10cSrcweir {
185cdf0e10cSrcweir     return ChgValue( *this, nIndex - rIndex.nIndex ).nIndex;
186cdf0e10cSrcweir }
187cdf0e10cSrcweir 
operator <(const SwIndex & rIndex) const188cdf0e10cSrcweir inline sal_Bool SwIndex::operator<( const SwIndex& rIndex ) const
189cdf0e10cSrcweir {
190cdf0e10cSrcweir     return nIndex < rIndex.nIndex;
191cdf0e10cSrcweir }
operator <=(const SwIndex & rIndex) const192cdf0e10cSrcweir inline sal_Bool SwIndex::operator<=( const SwIndex& rIndex ) const
193cdf0e10cSrcweir {
194cdf0e10cSrcweir     return nIndex <= rIndex.nIndex;
195cdf0e10cSrcweir }
operator >(const SwIndex & rIndex) const196cdf0e10cSrcweir inline sal_Bool SwIndex::operator>( const SwIndex& rIndex ) const
197cdf0e10cSrcweir {
198cdf0e10cSrcweir     return nIndex > rIndex.nIndex;
199cdf0e10cSrcweir }
operator >=(const SwIndex & rIndex) const200cdf0e10cSrcweir inline sal_Bool SwIndex::operator>=( const SwIndex& rIndex ) const
201cdf0e10cSrcweir {
202cdf0e10cSrcweir     return nIndex >= rIndex.nIndex;
203cdf0e10cSrcweir }
operator =(xub_StrLen nWert)204cdf0e10cSrcweir inline SwIndex& SwIndex::operator=( xub_StrLen nWert )
205cdf0e10cSrcweir {
206cdf0e10cSrcweir     if( nIndex != nWert )
207cdf0e10cSrcweir         ChgValue( *this, nWert );
208cdf0e10cSrcweir     return *this;
209cdf0e10cSrcweir }
210cdf0e10cSrcweir 
211cdf0e10cSrcweir #endif // PRODUCT
212cdf0e10cSrcweir 
213cdf0e10cSrcweir #endif
214