Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 : #ifndef SW_NDINDEX_HXX
20 : #define SW_NDINDEX_HXX
21 :
22 : #include <limits.h>
23 :
24 : #include <tools/solar.h>
25 :
26 : #include <node.hxx>
27 :
28 :
29 : class SwNode;
30 : class SwNodes;
31 :
32 : /// Marks a node in the document model.
33 : class SW_DLLPUBLIC SwNodeIndex
34 : {
35 : friend void SwNodes::RegisterIndex( SwNodeIndex& );
36 : friend void SwNodes::DeRegisterIndex( SwNodeIndex& );
37 : friend void SwNodes::RemoveNode( sal_uLong, sal_uLong, sal_Bool );
38 :
39 : SwNode* pNd;
40 : SwNodeIndex *pNext, *pPrev;
41 :
42 : void Remove();
43 :
44 : // These are not allowed!
45 : SwNodeIndex( SwNodes& rNds, sal_uInt16 nIdx );
46 : SwNodeIndex( SwNodes& rNds, int nIdx );
47 :
48 : public:
49 : SwNodeIndex( SwNodes& rNds, sal_uLong nIdx = 0 );
50 : SwNodeIndex( const SwNodeIndex &, long nDiff = 0 );
51 : SwNodeIndex( const SwNode&, long nDiff = 0 );
52 1531451 : ~SwNodeIndex() { Remove(); }
53 :
54 : inline sal_uLong operator++();
55 : inline sal_uLong operator--();
56 : inline sal_uLong operator++(int);
57 : inline sal_uLong operator--(int);
58 :
59 : inline sal_uLong operator+=( sal_uLong );
60 : inline sal_uLong operator-=( sal_uLong );
61 : inline sal_uLong operator+=( const SwNodeIndex& );
62 : inline sal_uLong operator-=( const SwNodeIndex& );
63 :
64 : inline sal_Bool operator< ( const SwNodeIndex& ) const;
65 : inline sal_Bool operator<=( const SwNodeIndex& ) const;
66 : inline sal_Bool operator> ( const SwNodeIndex& ) const;
67 : inline sal_Bool operator>=( const SwNodeIndex& ) const;
68 : inline sal_Bool operator==( const SwNodeIndex& ) const;
69 : inline sal_Bool operator!=( const SwNodeIndex& ) const;
70 :
71 : inline sal_Bool operator< ( sal_uLong nWert ) const;
72 : inline sal_Bool operator<=( sal_uLong nWert ) const;
73 : inline sal_Bool operator> ( sal_uLong nWert ) const;
74 : inline sal_Bool operator>=( sal_uLong nWert ) const;
75 : inline sal_Bool operator==( sal_uLong nWert ) const;
76 : inline sal_Bool operator!=( sal_uLong nWert ) const;
77 :
78 : inline SwNodeIndex& operator=( sal_uLong );
79 : SwNodeIndex& operator=( const SwNodeIndex& );
80 : SwNodeIndex& operator=( const SwNode& );
81 :
82 : // Return value of index as sal_uLong.
83 : inline sal_uLong GetIndex() const;
84 :
85 : // Enables assignments without creation of a temporary object.
86 : SwNodeIndex& Assign( SwNodes& rNds, sal_uLong );
87 : SwNodeIndex& Assign( const SwNode& rNd, long nOffset = 0 );
88 :
89 : // Gets pointer on NodesArray.
90 : inline const SwNodes& GetNodes() const;
91 : inline SwNodes& GetNodes();
92 :
93 4348731 : SwNode& GetNode() const { return *pNd; }
94 : };
95 :
96 : // SwRange
97 :
98 6601 : class SW_DLLPUBLIC SwNodeRange
99 : {
100 : public:
101 : SwNodeIndex aStart;
102 : SwNodeIndex aEnd;
103 :
104 : SwNodeRange( const SwNodeIndex &rS, const SwNodeIndex &rE );
105 : SwNodeRange( const SwNodeRange &rRange );
106 :
107 : SwNodeRange( SwNodes& rArr, sal_uLong nSttIdx = 0, sal_uLong nEndIdx = 0 );
108 : SwNodeRange( const SwNodeIndex& rS, long nSttDiff,
109 : const SwNodeIndex& rE, long nEndDiff = 0 );
110 : SwNodeRange( const SwNode& rS, long nSttDiff,
111 : const SwNode& rE, long nEndDiff = 0 );
112 : };
113 :
114 :
115 :
116 :
117 : // For inlines node.hxx is needed which in turn needs this one.
118 : // Therefore all inlines accessing pNd are implemented here.
119 :
120 6460869 : inline sal_uLong SwNodeIndex::GetIndex() const
121 : {
122 6460869 : return pNd->GetIndex();
123 : }
124 173949 : inline const SwNodes& SwNodeIndex::GetNodes() const
125 : {
126 173949 : return pNd->GetNodes();
127 : }
128 136677 : inline SwNodes& SwNodeIndex::GetNodes()
129 : {
130 136677 : return pNd->GetNodes();
131 : }
132 32088 : inline sal_Bool SwNodeIndex::operator< ( sal_uLong nWert ) const
133 : {
134 32088 : return pNd->GetIndex() < nWert;
135 : }
136 188 : inline sal_Bool SwNodeIndex::operator<=( sal_uLong nWert ) const
137 : {
138 188 : return pNd->GetIndex() <= nWert;
139 : }
140 874 : inline sal_Bool SwNodeIndex::operator> ( sal_uLong nWert ) const
141 : {
142 874 : return pNd->GetIndex() > nWert;
143 : }
144 380 : inline sal_Bool SwNodeIndex::operator>=( sal_uLong nWert ) const
145 : {
146 380 : return pNd->GetIndex() >= nWert;
147 : }
148 23399 : inline sal_Bool SwNodeIndex::operator==( sal_uLong nWert ) const
149 : {
150 23399 : return pNd->GetIndex() == nWert;
151 : }
152 1336 : inline sal_Bool SwNodeIndex::operator!=( sal_uLong nWert ) const
153 : {
154 1336 : return pNd->GetIndex() != nWert;
155 : }
156 1794360 : inline sal_Bool SwNodeIndex::operator<( const SwNodeIndex& rIndex ) const
157 : {
158 1794360 : return pNd->GetIndex() < rIndex.GetIndex();
159 : }
160 12563 : inline sal_Bool SwNodeIndex::operator<=( const SwNodeIndex& rIndex ) const
161 : {
162 12563 : return pNd->GetIndex() <= rIndex.GetIndex();
163 : }
164 2611671 : inline sal_Bool SwNodeIndex::operator>( const SwNodeIndex& rIndex ) const
165 : {
166 2611671 : return pNd->GetIndex() > rIndex.GetIndex();
167 : }
168 10893 : inline sal_Bool SwNodeIndex::operator>=( const SwNodeIndex& rIndex ) const
169 : {
170 10893 : return pNd->GetIndex() >= rIndex.GetIndex();
171 : }
172 4446408 : inline sal_Bool SwNodeIndex::operator==( const SwNodeIndex& rIdx ) const
173 : {
174 4446408 : return pNd == rIdx.pNd;
175 : }
176 503470 : inline sal_Bool SwNodeIndex::operator!=( const SwNodeIndex& rIdx ) const
177 : {
178 503470 : return pNd != rIdx.pNd;
179 : }
180 :
181 40077 : inline sal_uLong SwNodeIndex::operator++()
182 : {
183 40077 : return ( pNd = GetNodes()[ pNd->GetIndex()+1 ] )->GetIndex();
184 : }
185 0 : inline sal_uLong SwNodeIndex::operator--()
186 : {
187 0 : return ( pNd = GetNodes()[ pNd->GetIndex()-1 ] )->GetIndex();
188 : }
189 10183 : inline sal_uLong SwNodeIndex::operator++(int)
190 : {
191 10183 : sal_uLong nOldIndex = pNd->GetIndex();
192 10183 : pNd = GetNodes()[ nOldIndex + 1 ];
193 10183 : return nOldIndex;
194 : }
195 5762 : inline sal_uLong SwNodeIndex::operator--(int)
196 : {
197 5762 : sal_uLong nOldIndex = pNd->GetIndex();
198 5762 : pNd = GetNodes()[ nOldIndex - 1 ];
199 5762 : return nOldIndex;
200 : }
201 :
202 1030 : inline sal_uLong SwNodeIndex::operator+=( sal_uLong nWert )
203 : {
204 1030 : return ( pNd = GetNodes()[ pNd->GetIndex() + nWert ] )->GetIndex();
205 : }
206 91 : inline sal_uLong SwNodeIndex::operator-=( sal_uLong nWert )
207 : {
208 91 : return ( pNd = GetNodes()[ pNd->GetIndex() - nWert ] )->GetIndex();
209 : }
210 : inline sal_uLong SwNodeIndex::operator+=( const SwNodeIndex& rIndex )
211 : {
212 : return ( pNd = GetNodes()[ pNd->GetIndex() + rIndex.GetIndex() ] )->GetIndex();
213 : }
214 : inline sal_uLong SwNodeIndex::operator-=( const SwNodeIndex& rIndex )
215 : {
216 : return ( pNd = GetNodes()[ pNd->GetIndex() - rIndex.GetIndex() ] )->GetIndex();
217 : }
218 :
219 35247 : inline SwNodeIndex& SwNodeIndex::operator=( sal_uLong nWert )
220 : {
221 35247 : pNd = GetNodes()[ nWert ];
222 35247 : return *this;
223 : }
224 :
225 : #endif
226 :
227 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|