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 SW_NDINDEX_HXX
24cdf0e10cSrcweir #define SW_NDINDEX_HXX
25cdf0e10cSrcweir
26cdf0e10cSrcweir #include <limits.h>
27cdf0e10cSrcweir
28cdf0e10cSrcweir #include <tools/solar.h>
29cdf0e10cSrcweir
30cdf0e10cSrcweir #include <node.hxx>
31cdf0e10cSrcweir
32cdf0e10cSrcweir
33cdf0e10cSrcweir class SwNode;
34cdf0e10cSrcweir class SwNodes;
35cdf0e10cSrcweir
36cdf0e10cSrcweir class SW_DLLPUBLIC SwNodeIndex
37cdf0e10cSrcweir {
38cdf0e10cSrcweir friend void SwNodes::RegisterIndex( SwNodeIndex& );
39cdf0e10cSrcweir friend void SwNodes::DeRegisterIndex( SwNodeIndex& );
40cdf0e10cSrcweir friend void SwNodes::RemoveNode( sal_uLong, sal_uLong, sal_Bool );
41cdf0e10cSrcweir
42cdf0e10cSrcweir #ifdef DBG_UTIL
43cdf0e10cSrcweir static int nSerial;
44cdf0e10cSrcweir int MySerial;
45cdf0e10cSrcweir #endif
46cdf0e10cSrcweir
47cdf0e10cSrcweir SwNode* pNd;
48cdf0e10cSrcweir SwNodeIndex *pNext, *pPrev;
49cdf0e10cSrcweir
50cdf0e10cSrcweir void Remove(); // Ausketten
51cdf0e10cSrcweir
52cdf0e10cSrcweir // diese sind nicht erlaubt!
53cdf0e10cSrcweir SwNodeIndex( SwNodes& rNds, sal_uInt16 nIdx );
54cdf0e10cSrcweir SwNodeIndex( SwNodes& rNds, int nIdx );
55cdf0e10cSrcweir
56cdf0e10cSrcweir public:
57cdf0e10cSrcweir SwNodeIndex( SwNodes& rNds, sal_uLong nIdx = 0 );
58cdf0e10cSrcweir SwNodeIndex( const SwNodeIndex &, long nDiff = 0 );
59cdf0e10cSrcweir SwNodeIndex( const SwNode&, long nDiff = 0 );
~SwNodeIndex()60cdf0e10cSrcweir ~SwNodeIndex() { Remove(); }
61cdf0e10cSrcweir
62cdf0e10cSrcweir inline sal_uLong operator++();
63cdf0e10cSrcweir inline sal_uLong operator--();
64cdf0e10cSrcweir #ifndef CFRONT
65cdf0e10cSrcweir inline sal_uLong operator++(int);
66cdf0e10cSrcweir inline sal_uLong operator--(int);
67cdf0e10cSrcweir #endif
68cdf0e10cSrcweir
69cdf0e10cSrcweir inline sal_uLong operator+=( sal_uLong );
70cdf0e10cSrcweir inline sal_uLong operator-=( sal_uLong );
71cdf0e10cSrcweir inline sal_uLong operator+=( const SwNodeIndex& );
72cdf0e10cSrcweir inline sal_uLong operator-=( const SwNodeIndex& );
73cdf0e10cSrcweir
74cdf0e10cSrcweir inline sal_Bool operator< ( const SwNodeIndex& ) const;
75cdf0e10cSrcweir inline sal_Bool operator<=( const SwNodeIndex& ) const;
76cdf0e10cSrcweir inline sal_Bool operator> ( const SwNodeIndex& ) const;
77cdf0e10cSrcweir inline sal_Bool operator>=( const SwNodeIndex& ) const;
78cdf0e10cSrcweir inline sal_Bool operator==( const SwNodeIndex& ) const;
79cdf0e10cSrcweir inline sal_Bool operator!=( const SwNodeIndex& ) const;
80cdf0e10cSrcweir
81cdf0e10cSrcweir inline sal_Bool operator< ( sal_uLong nWert ) const;
82cdf0e10cSrcweir inline sal_Bool operator<=( sal_uLong nWert ) const;
83cdf0e10cSrcweir inline sal_Bool operator> ( sal_uLong nWert ) const;
84cdf0e10cSrcweir inline sal_Bool operator>=( sal_uLong nWert ) const;
85cdf0e10cSrcweir inline sal_Bool operator==( sal_uLong nWert ) const;
86cdf0e10cSrcweir inline sal_Bool operator!=( sal_uLong nWert ) const;
87cdf0e10cSrcweir
88cdf0e10cSrcweir inline SwNodeIndex& operator=( sal_uLong );
89cdf0e10cSrcweir SwNodeIndex& operator=( const SwNodeIndex& );
90cdf0e10cSrcweir SwNodeIndex& operator=( const SwNode& );
91cdf0e10cSrcweir
92cdf0e10cSrcweir // gebe den Wert vom Index als sal_uLong zurueck
93cdf0e10cSrcweir inline sal_uLong GetIndex() const;
94cdf0e10cSrcweir
95cdf0e10cSrcweir // ermoeglicht Zuweisungen ohne Erzeugen eines temporaeren Objektes
96cdf0e10cSrcweir SwNodeIndex& Assign( SwNodes& rNds, sal_uLong );
97cdf0e10cSrcweir SwNodeIndex& Assign( const SwNode& rNd, long nOffset = 0 );
98cdf0e10cSrcweir
99cdf0e10cSrcweir // Herausgabe des Pointers auf das NodesArray,
100cdf0e10cSrcweir inline const SwNodes& GetNodes() const;
101cdf0e10cSrcweir inline SwNodes& GetNodes();
102cdf0e10cSrcweir
GetNode() const103cdf0e10cSrcweir SwNode& GetNode() const { return *pNd; }
104cdf0e10cSrcweir };
105cdf0e10cSrcweir
106cdf0e10cSrcweir /*
107cdf0e10cSrcweir * SwRange
108cdf0e10cSrcweir */
109cdf0e10cSrcweir class SW_DLLPUBLIC SwNodeRange
110cdf0e10cSrcweir {
111cdf0e10cSrcweir public:
112cdf0e10cSrcweir SwNodeIndex aStart;
113cdf0e10cSrcweir SwNodeIndex aEnd;
114cdf0e10cSrcweir
115cdf0e10cSrcweir SwNodeRange( const SwNodeIndex &rS, const SwNodeIndex &rE );
116cdf0e10cSrcweir SwNodeRange( const SwNodeRange &rRange );
117cdf0e10cSrcweir
118cdf0e10cSrcweir SwNodeRange( SwNodes& rArr, sal_uLong nSttIdx = 0, sal_uLong nEndIdx = 0 );
119cdf0e10cSrcweir SwNodeRange( const SwNodeIndex& rS, long nSttDiff,
120cdf0e10cSrcweir const SwNodeIndex& rE, long nEndDiff = 0 );
121cdf0e10cSrcweir SwNodeRange( const SwNode& rS, long nSttDiff,
122cdf0e10cSrcweir const SwNode& rE, long nEndDiff = 0 );
123cdf0e10cSrcweir };
124cdf0e10cSrcweir
125cdf0e10cSrcweir
126cdf0e10cSrcweir
127cdf0e10cSrcweir
128cdf0e10cSrcweir // fuer die inlines wird aber der node.hxx benoetigt. Dieses braucht aber
129cdf0e10cSrcweir // auch wieder dieses. Also alle Inlines, die auf pNd zugreifen werden
130cdf0e10cSrcweir // hier implementiert.
131cdf0e10cSrcweir
GetIndex() const132cdf0e10cSrcweir inline sal_uLong SwNodeIndex::GetIndex() const
133cdf0e10cSrcweir {
134cdf0e10cSrcweir return pNd->GetIndex();
135cdf0e10cSrcweir }
GetNodes() const136cdf0e10cSrcweir inline const SwNodes& SwNodeIndex::GetNodes() const
137cdf0e10cSrcweir {
138cdf0e10cSrcweir return pNd->GetNodes();
139cdf0e10cSrcweir }
GetNodes()140cdf0e10cSrcweir inline SwNodes& SwNodeIndex::GetNodes()
141cdf0e10cSrcweir {
142cdf0e10cSrcweir return pNd->GetNodes();
143cdf0e10cSrcweir }
operator <(sal_uLong nWert) const144cdf0e10cSrcweir inline sal_Bool SwNodeIndex::operator< ( sal_uLong nWert ) const
145cdf0e10cSrcweir {
146cdf0e10cSrcweir return pNd->GetIndex() < nWert;
147cdf0e10cSrcweir }
operator <=(sal_uLong nWert) const148cdf0e10cSrcweir inline sal_Bool SwNodeIndex::operator<=( sal_uLong nWert ) const
149cdf0e10cSrcweir {
150cdf0e10cSrcweir return pNd->GetIndex() <= nWert;
151cdf0e10cSrcweir }
operator >(sal_uLong nWert) const152cdf0e10cSrcweir inline sal_Bool SwNodeIndex::operator> ( sal_uLong nWert ) const
153cdf0e10cSrcweir {
154cdf0e10cSrcweir return pNd->GetIndex() > nWert;
155cdf0e10cSrcweir }
operator >=(sal_uLong nWert) const156cdf0e10cSrcweir inline sal_Bool SwNodeIndex::operator>=( sal_uLong nWert ) const
157cdf0e10cSrcweir {
158cdf0e10cSrcweir return pNd->GetIndex() >= nWert;
159cdf0e10cSrcweir }
operator ==(sal_uLong nWert) const160cdf0e10cSrcweir inline sal_Bool SwNodeIndex::operator==( sal_uLong nWert ) const
161cdf0e10cSrcweir {
162cdf0e10cSrcweir return pNd->GetIndex() == nWert;
163cdf0e10cSrcweir }
operator !=(sal_uLong nWert) const164cdf0e10cSrcweir inline sal_Bool SwNodeIndex::operator!=( sal_uLong nWert ) const
165cdf0e10cSrcweir {
166cdf0e10cSrcweir return pNd->GetIndex() != nWert;
167cdf0e10cSrcweir }
operator <(const SwNodeIndex & rIndex) const168cdf0e10cSrcweir inline sal_Bool SwNodeIndex::operator<( const SwNodeIndex& rIndex ) const
169cdf0e10cSrcweir {
170cdf0e10cSrcweir return pNd->GetIndex() < rIndex.GetIndex();
171cdf0e10cSrcweir }
operator <=(const SwNodeIndex & rIndex) const172cdf0e10cSrcweir inline sal_Bool SwNodeIndex::operator<=( const SwNodeIndex& rIndex ) const
173cdf0e10cSrcweir {
174cdf0e10cSrcweir return pNd->GetIndex() <= rIndex.GetIndex();
175cdf0e10cSrcweir }
operator >(const SwNodeIndex & rIndex) const176cdf0e10cSrcweir inline sal_Bool SwNodeIndex::operator>( const SwNodeIndex& rIndex ) const
177cdf0e10cSrcweir {
178cdf0e10cSrcweir return pNd->GetIndex() > rIndex.GetIndex();
179cdf0e10cSrcweir }
operator >=(const SwNodeIndex & rIndex) const180cdf0e10cSrcweir inline sal_Bool SwNodeIndex::operator>=( const SwNodeIndex& rIndex ) const
181cdf0e10cSrcweir {
182cdf0e10cSrcweir return pNd->GetIndex() >= rIndex.GetIndex();
183cdf0e10cSrcweir }
operator ==(const SwNodeIndex & rIdx) const184cdf0e10cSrcweir inline sal_Bool SwNodeIndex::operator==( const SwNodeIndex& rIdx ) const
185cdf0e10cSrcweir {
186cdf0e10cSrcweir return pNd == rIdx.pNd;
187cdf0e10cSrcweir }
operator !=(const SwNodeIndex & rIdx) const188cdf0e10cSrcweir inline sal_Bool SwNodeIndex::operator!=( const SwNodeIndex& rIdx ) const
189cdf0e10cSrcweir {
190cdf0e10cSrcweir return pNd != rIdx.pNd;
191cdf0e10cSrcweir }
192cdf0e10cSrcweir
operator ++()193cdf0e10cSrcweir inline sal_uLong SwNodeIndex::operator++()
194cdf0e10cSrcweir {
195cdf0e10cSrcweir return ( pNd = GetNodes()[ pNd->GetIndex()+1 ] )->GetIndex();
196cdf0e10cSrcweir }
operator --()197cdf0e10cSrcweir inline sal_uLong SwNodeIndex::operator--()
198cdf0e10cSrcweir {
199cdf0e10cSrcweir return ( pNd = GetNodes()[ pNd->GetIndex()-1 ] )->GetIndex();
200cdf0e10cSrcweir }
201cdf0e10cSrcweir #ifndef CFRONT
operator ++(int)202cdf0e10cSrcweir inline sal_uLong SwNodeIndex::operator++(int)
203cdf0e10cSrcweir {
204cdf0e10cSrcweir sal_uLong nOldIndex = pNd->GetIndex();
205cdf0e10cSrcweir pNd = GetNodes()[ nOldIndex + 1 ];
206cdf0e10cSrcweir return nOldIndex;
207cdf0e10cSrcweir }
operator --(int)208cdf0e10cSrcweir inline sal_uLong SwNodeIndex::operator--(int)
209cdf0e10cSrcweir {
210cdf0e10cSrcweir sal_uLong nOldIndex = pNd->GetIndex();
211cdf0e10cSrcweir pNd = GetNodes()[ nOldIndex - 1 ];
212cdf0e10cSrcweir return nOldIndex;
213cdf0e10cSrcweir }
214cdf0e10cSrcweir #endif
215cdf0e10cSrcweir
operator +=(sal_uLong nWert)216cdf0e10cSrcweir inline sal_uLong SwNodeIndex::operator+=( sal_uLong nWert )
217cdf0e10cSrcweir {
218cdf0e10cSrcweir return ( pNd = GetNodes()[ pNd->GetIndex() + nWert ] )->GetIndex();
219cdf0e10cSrcweir }
operator -=(sal_uLong nWert)220cdf0e10cSrcweir inline sal_uLong SwNodeIndex::operator-=( sal_uLong nWert )
221cdf0e10cSrcweir {
222cdf0e10cSrcweir return ( pNd = GetNodes()[ pNd->GetIndex() - nWert ] )->GetIndex();
223cdf0e10cSrcweir }
operator +=(const SwNodeIndex & rIndex)224cdf0e10cSrcweir inline sal_uLong SwNodeIndex::operator+=( const SwNodeIndex& rIndex )
225cdf0e10cSrcweir {
226cdf0e10cSrcweir return ( pNd = GetNodes()[ pNd->GetIndex() + rIndex.GetIndex() ] )->GetIndex();
227cdf0e10cSrcweir }
operator -=(const SwNodeIndex & rIndex)228cdf0e10cSrcweir inline sal_uLong SwNodeIndex::operator-=( const SwNodeIndex& rIndex )
229cdf0e10cSrcweir {
230cdf0e10cSrcweir return ( pNd = GetNodes()[ pNd->GetIndex() - rIndex.GetIndex() ] )->GetIndex();
231cdf0e10cSrcweir }
232cdf0e10cSrcweir
operator =(sal_uLong nWert)233cdf0e10cSrcweir inline SwNodeIndex& SwNodeIndex::operator=( sal_uLong nWert )
234cdf0e10cSrcweir {
235cdf0e10cSrcweir pNd = GetNodes()[ nWert ];
236cdf0e10cSrcweir return *this;
237cdf0e10cSrcweir }
238cdf0e10cSrcweir
239cdf0e10cSrcweir #endif
240