xref: /trunk/main/sw/inc/ndindex.hxx (revision 1ecadb572e7010ff3b3382ad9bf179dbc6efadbb)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 #ifndef SW_NDINDEX_HXX
28 #define SW_NDINDEX_HXX
29 
30 #include <limits.h>
31 
32 #include <tools/solar.h>
33 
34 #include <node.hxx>
35 
36 
37 class SwNode;
38 class SwNodes;
39 
40 class SW_DLLPUBLIC SwNodeIndex
41 {
42     friend void SwNodes::RegisterIndex( SwNodeIndex& );
43     friend void SwNodes::DeRegisterIndex( SwNodeIndex& );
44     friend void SwNodes::RemoveNode( sal_uLong, sal_uLong, sal_Bool );
45 
46 #ifdef DBG_UTIL
47     static int nSerial;
48     int MySerial;
49 #endif
50 
51     SwNode* pNd;
52     SwNodeIndex *pNext, *pPrev;
53 
54     void Remove();                  // Ausketten
55 
56     // diese sind nicht erlaubt!
57     SwNodeIndex( SwNodes& rNds, sal_uInt16 nIdx );
58     SwNodeIndex( SwNodes& rNds, int nIdx );
59 
60 public:
61     SwNodeIndex( SwNodes& rNds, sal_uLong nIdx = 0 );
62     SwNodeIndex( const SwNodeIndex &, long nDiff = 0 );
63     SwNodeIndex( const SwNode&, long nDiff = 0 );
64     ~SwNodeIndex() { Remove(); }
65 
66     inline sal_uLong operator++();
67     inline sal_uLong operator--();
68 #ifndef CFRONT
69     inline sal_uLong operator++(int);
70     inline sal_uLong operator--(int);
71 #endif
72 
73     inline sal_uLong operator+=( sal_uLong );
74     inline sal_uLong operator-=( sal_uLong );
75     inline sal_uLong operator+=( const  SwNodeIndex& );
76     inline sal_uLong operator-=( const SwNodeIndex& );
77 
78     inline sal_Bool operator< ( const SwNodeIndex& ) const;
79     inline sal_Bool operator<=( const SwNodeIndex& ) const;
80     inline sal_Bool operator> ( const SwNodeIndex& ) const;
81     inline sal_Bool operator>=( const SwNodeIndex& ) const;
82     inline sal_Bool operator==( const SwNodeIndex& ) const;
83     inline sal_Bool operator!=( const SwNodeIndex& ) const;
84 
85     inline sal_Bool operator< ( sal_uLong nWert ) const;
86     inline sal_Bool operator<=( sal_uLong nWert ) const;
87     inline sal_Bool operator> ( sal_uLong nWert ) const;
88     inline sal_Bool operator>=( sal_uLong nWert ) const;
89     inline sal_Bool operator==( sal_uLong nWert ) const;
90     inline sal_Bool operator!=( sal_uLong nWert ) const;
91 
92     inline SwNodeIndex& operator=( sal_uLong );
93            SwNodeIndex& operator=( const SwNodeIndex& );
94            SwNodeIndex& operator=( const SwNode& );
95 
96     // gebe den Wert vom Index als sal_uLong zurueck
97     inline sal_uLong GetIndex() const;
98 
99     // ermoeglicht Zuweisungen ohne Erzeugen eines temporaeren Objektes
100     SwNodeIndex& Assign( SwNodes& rNds, sal_uLong );
101     SwNodeIndex& Assign( const SwNode& rNd, long nOffset = 0 );
102 
103         // Herausgabe des Pointers auf das NodesArray,
104     inline const SwNodes& GetNodes() const;
105     inline       SwNodes& GetNodes();
106 
107     SwNode& GetNode() const { return *pNd; }
108 };
109 
110 /*
111  * SwRange
112  */
113 class SW_DLLPUBLIC SwNodeRange
114 {
115 public:
116     SwNodeIndex aStart;
117     SwNodeIndex aEnd;
118 
119     SwNodeRange( const SwNodeIndex &rS, const SwNodeIndex &rE );
120     SwNodeRange( const SwNodeRange &rRange );
121 
122     SwNodeRange( SwNodes& rArr, sal_uLong nSttIdx = 0, sal_uLong nEndIdx = 0 );
123     SwNodeRange( const SwNodeIndex& rS, long nSttDiff,
124                  const SwNodeIndex& rE, long nEndDiff = 0 );
125     SwNodeRange( const SwNode& rS, long nSttDiff,
126                  const SwNode& rE, long nEndDiff = 0 );
127 };
128 
129 
130 
131 
132 // fuer die inlines wird aber der node.hxx benoetigt. Dieses braucht aber
133 // auch wieder dieses. Also alle Inlines, die auf pNd zugreifen werden
134 // hier implementiert.
135 
136 inline sal_uLong SwNodeIndex::GetIndex() const
137 {
138     return pNd->GetIndex();
139 }
140 inline const SwNodes& SwNodeIndex::GetNodes() const
141 {
142     return pNd->GetNodes();
143 }
144 inline SwNodes& SwNodeIndex::GetNodes()
145 {
146     return pNd->GetNodes();
147 }
148 inline sal_Bool SwNodeIndex::operator< ( sal_uLong nWert ) const
149 {
150     return pNd->GetIndex() < nWert;
151 }
152 inline sal_Bool SwNodeIndex::operator<=( sal_uLong nWert ) const
153 {
154     return pNd->GetIndex() <= nWert;
155 }
156 inline sal_Bool SwNodeIndex::operator> ( sal_uLong nWert ) const
157 {
158     return pNd->GetIndex() > nWert;
159 }
160 inline sal_Bool SwNodeIndex::operator>=( sal_uLong nWert ) const
161 {
162     return pNd->GetIndex() >= nWert;
163 }
164 inline sal_Bool SwNodeIndex::operator==( sal_uLong nWert ) const
165 {
166     return pNd->GetIndex() == nWert;
167 }
168 inline sal_Bool SwNodeIndex::operator!=( sal_uLong nWert ) const
169 {
170     return pNd->GetIndex() != nWert;
171 }
172 inline sal_Bool SwNodeIndex::operator<( const SwNodeIndex& rIndex ) const
173 {
174     return pNd->GetIndex() < rIndex.GetIndex();
175 }
176 inline sal_Bool SwNodeIndex::operator<=( const SwNodeIndex& rIndex ) const
177 {
178     return pNd->GetIndex() <= rIndex.GetIndex();
179 }
180 inline sal_Bool SwNodeIndex::operator>( const SwNodeIndex& rIndex ) const
181 {
182     return pNd->GetIndex() > rIndex.GetIndex();
183 }
184 inline sal_Bool SwNodeIndex::operator>=( const SwNodeIndex& rIndex ) const
185 {
186     return pNd->GetIndex() >= rIndex.GetIndex();
187 }
188 inline sal_Bool SwNodeIndex::operator==( const SwNodeIndex& rIdx ) const
189 {
190     return pNd == rIdx.pNd;
191 }
192 inline sal_Bool SwNodeIndex::operator!=( const SwNodeIndex& rIdx ) const
193 {
194     return pNd != rIdx.pNd;
195 }
196 
197 inline sal_uLong SwNodeIndex::operator++()
198 {
199     return ( pNd = GetNodes()[ pNd->GetIndex()+1 ] )->GetIndex();
200 }
201 inline sal_uLong SwNodeIndex::operator--()
202 {
203     return ( pNd = GetNodes()[ pNd->GetIndex()-1 ] )->GetIndex();
204 }
205 #ifndef CFRONT
206 inline sal_uLong SwNodeIndex::operator++(int)
207 {
208     sal_uLong nOldIndex = pNd->GetIndex();
209     pNd = GetNodes()[ nOldIndex + 1 ];
210     return nOldIndex;
211 }
212 inline sal_uLong SwNodeIndex::operator--(int)
213 {
214     sal_uLong nOldIndex = pNd->GetIndex();
215     pNd = GetNodes()[ nOldIndex - 1 ];
216     return nOldIndex;
217 }
218 #endif
219 
220 inline sal_uLong SwNodeIndex::operator+=( sal_uLong nWert )
221 {
222     return ( pNd = GetNodes()[ pNd->GetIndex() + nWert ] )->GetIndex();
223 }
224 inline sal_uLong SwNodeIndex::operator-=( sal_uLong nWert )
225 {
226     return ( pNd = GetNodes()[ pNd->GetIndex() - nWert ] )->GetIndex();
227 }
228 inline sal_uLong SwNodeIndex::operator+=( const  SwNodeIndex& rIndex )
229 {
230     return ( pNd = GetNodes()[ pNd->GetIndex() + rIndex.GetIndex() ] )->GetIndex();
231 }
232 inline sal_uLong SwNodeIndex::operator-=( const SwNodeIndex& rIndex )
233 {
234     return ( pNd = GetNodes()[ pNd->GetIndex() - rIndex.GetIndex() ] )->GetIndex();
235 }
236 
237 inline SwNodeIndex& SwNodeIndex::operator=( sal_uLong nWert )
238 {
239     pNd = GetNodes()[ nWert ];
240     return *this;
241 }
242 
243 #endif
244