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