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 537667 : ~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 708545 : SwNode& GetNode() const { return *pNd; }
94 : };
95 :
96 : // SwRange
97 :
98 2959 : 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 1643128 : inline sal_uLong SwNodeIndex::GetIndex() const
121 : {
122 1643128 : return pNd->GetIndex();
123 : }
124 111326 : inline const SwNodes& SwNodeIndex::GetNodes() const
125 : {
126 111326 : return pNd->GetNodes();
127 : }
128 65276 : inline SwNodes& SwNodeIndex::GetNodes()
129 : {
130 65276 : return pNd->GetNodes();
131 : }
132 9300 : inline sal_Bool SwNodeIndex::operator< ( sal_uLong nWert ) const
133 : {
134 9300 : return pNd->GetIndex() < nWert;
135 : }
136 156 : inline sal_Bool SwNodeIndex::operator<=( sal_uLong nWert ) const
137 : {
138 156 : return pNd->GetIndex() <= nWert;
139 : }
140 39 : inline sal_Bool SwNodeIndex::operator> ( sal_uLong nWert ) const
141 : {
142 39 : return pNd->GetIndex() > nWert;
143 : }
144 221 : inline sal_Bool SwNodeIndex::operator>=( sal_uLong nWert ) const
145 : {
146 221 : return pNd->GetIndex() >= nWert;
147 : }
148 6124 : inline sal_Bool SwNodeIndex::operator==( sal_uLong nWert ) const
149 : {
150 6124 : return pNd->GetIndex() == nWert;
151 : }
152 877 : inline sal_Bool SwNodeIndex::operator!=( sal_uLong nWert ) const
153 : {
154 877 : return pNd->GetIndex() != nWert;
155 : }
156 128545 : inline sal_Bool SwNodeIndex::operator<( const SwNodeIndex& rIndex ) const
157 : {
158 128545 : return pNd->GetIndex() < rIndex.GetIndex();
159 : }
160 10928 : inline sal_Bool SwNodeIndex::operator<=( const SwNodeIndex& rIndex ) const
161 : {
162 10928 : return pNd->GetIndex() <= rIndex.GetIndex();
163 : }
164 74805 : inline sal_Bool SwNodeIndex::operator>( const SwNodeIndex& rIndex ) const
165 : {
166 74805 : return pNd->GetIndex() > rIndex.GetIndex();
167 : }
168 10510 : inline sal_Bool SwNodeIndex::operator>=( const SwNodeIndex& rIndex ) const
169 : {
170 10510 : return pNd->GetIndex() >= rIndex.GetIndex();
171 : }
172 168305 : inline sal_Bool SwNodeIndex::operator==( const SwNodeIndex& rIdx ) const
173 : {
174 168305 : return pNd == rIdx.pNd;
175 : }
176 47272 : inline sal_Bool SwNodeIndex::operator!=( const SwNodeIndex& rIdx ) const
177 : {
178 47272 : return pNd != rIdx.pNd;
179 : }
180 :
181 12690 : inline sal_uLong SwNodeIndex::operator++()
182 : {
183 12690 : 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 5332 : inline sal_uLong SwNodeIndex::operator++(int)
190 : {
191 5332 : sal_uLong nOldIndex = pNd->GetIndex();
192 5332 : pNd = GetNodes()[ nOldIndex + 1 ];
193 5332 : return nOldIndex;
194 : }
195 2048 : inline sal_uLong SwNodeIndex::operator--(int)
196 : {
197 2048 : sal_uLong nOldIndex = pNd->GetIndex();
198 2048 : pNd = GetNodes()[ nOldIndex - 1 ];
199 2048 : return nOldIndex;
200 : }
201 :
202 463 : inline sal_uLong SwNodeIndex::operator+=( sal_uLong nWert )
203 : {
204 463 : return ( pNd = GetNodes()[ pNd->GetIndex() + nWert ] )->GetIndex();
205 : }
206 0 : inline sal_uLong SwNodeIndex::operator-=( sal_uLong nWert )
207 : {
208 0 : 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 24293 : inline SwNodeIndex& SwNodeIndex::operator=( sal_uLong nWert )
220 : {
221 24293 : pNd = GetNodes()[ nWert ];
222 24293 : return *this;
223 : }
224 :
225 : #endif
226 :
227 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|