Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : : #ifndef SW_NDINDEX_HXX
29 : : #define SW_NDINDEX_HXX
30 : :
31 : : #include <limits.h>
32 : :
33 : : #include <tools/solar.h>
34 : :
35 : : #include <node.hxx>
36 : :
37 : :
38 : : class SwNode;
39 : : class SwNodes;
40 : :
41 : : /// Marks a node in the document model.
42 : : class SW_DLLPUBLIC SwNodeIndex
43 : : {
44 : : friend void SwNodes::RegisterIndex( SwNodeIndex& );
45 : : friend void SwNodes::DeRegisterIndex( SwNodeIndex& );
46 : : friend void SwNodes::RemoveNode( sal_uLong, sal_uLong, sal_Bool );
47 : :
48 : : SwNode* pNd;
49 : : SwNodeIndex *pNext, *pPrev;
50 : :
51 : : void Remove();
52 : :
53 : : // These are not allowed!
54 : : SwNodeIndex( SwNodes& rNds, sal_uInt16 nIdx );
55 : : SwNodeIndex( SwNodes& rNds, int nIdx );
56 : :
57 : : public:
58 : : SwNodeIndex( SwNodes& rNds, sal_uLong nIdx = 0 );
59 : : SwNodeIndex( const SwNodeIndex &, long nDiff = 0 );
60 : : SwNodeIndex( const SwNode&, long nDiff = 0 );
61 : 2560589 : ~SwNodeIndex() { Remove(); }
62 : :
63 : : inline sal_uLong operator++();
64 : : inline sal_uLong operator--();
65 : : inline sal_uLong operator++(int);
66 : : inline sal_uLong operator--(int);
67 : :
68 : : inline sal_uLong operator+=( sal_uLong );
69 : : inline sal_uLong operator-=( sal_uLong );
70 : : inline sal_uLong operator+=( const SwNodeIndex& );
71 : : inline sal_uLong operator-=( const SwNodeIndex& );
72 : :
73 : : inline sal_Bool operator< ( const SwNodeIndex& ) const;
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 : :
80 : : inline sal_Bool operator< ( sal_uLong nWert ) const;
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 : :
87 : : inline SwNodeIndex& operator=( sal_uLong );
88 : : SwNodeIndex& operator=( const SwNodeIndex& );
89 : : SwNodeIndex& operator=( const SwNode& );
90 : :
91 : : // Return value of index as sal_uLong.
92 : : inline sal_uLong GetIndex() const;
93 : :
94 : : // Enables assignments without creation of a temporary object.
95 : : SwNodeIndex& Assign( SwNodes& rNds, sal_uLong );
96 : : SwNodeIndex& Assign( const SwNode& rNd, long nOffset = 0 );
97 : :
98 : : // Gets pointer on NodesArray.
99 : : inline const SwNodes& GetNodes() const;
100 : : inline SwNodes& GetNodes();
101 : :
102 : 8896061 : SwNode& GetNode() const { return *pNd; }
103 : : };
104 : :
105 : : // SwRange
106 : :
107 [ + - ]: 6235 : class SW_DLLPUBLIC SwNodeRange
108 : : {
109 : : public:
110 : : SwNodeIndex aStart;
111 : : SwNodeIndex aEnd;
112 : :
113 : : SwNodeRange( const SwNodeIndex &rS, const SwNodeIndex &rE );
114 : : SwNodeRange( const SwNodeRange &rRange );
115 : :
116 : : SwNodeRange( SwNodes& rArr, sal_uLong nSttIdx = 0, sal_uLong nEndIdx = 0 );
117 : : SwNodeRange( const SwNodeIndex& rS, long nSttDiff,
118 : : const SwNodeIndex& rE, long nEndDiff = 0 );
119 : : SwNodeRange( const SwNode& rS, long nSttDiff,
120 : : const SwNode& rE, long nEndDiff = 0 );
121 : : };
122 : :
123 : :
124 : :
125 : :
126 : : // For inlines node.hxx is needed which in turn needs this one.
127 : : // Therefore all inlines accessing pNd are implemented here.
128 : :
129 : 10955819 : inline sal_uLong SwNodeIndex::GetIndex() const
130 : : {
131 : 10955819 : return pNd->GetIndex();
132 : : }
133 : 192134 : inline const SwNodes& SwNodeIndex::GetNodes() const
134 : : {
135 : 192134 : return pNd->GetNodes();
136 : : }
137 : 174739 : inline SwNodes& SwNodeIndex::GetNodes()
138 : : {
139 : 174739 : return pNd->GetNodes();
140 : : }
141 : 45082 : inline sal_Bool SwNodeIndex::operator< ( sal_uLong nWert ) const
142 : : {
143 : 45082 : return pNd->GetIndex() < nWert;
144 : : }
145 : 188 : inline sal_Bool SwNodeIndex::operator<=( sal_uLong nWert ) const
146 : : {
147 : 188 : return pNd->GetIndex() <= nWert;
148 : : }
149 : 1358 : inline sal_Bool SwNodeIndex::operator> ( sal_uLong nWert ) const
150 : : {
151 : 1358 : return pNd->GetIndex() > nWert;
152 : : }
153 : 697 : inline sal_Bool SwNodeIndex::operator>=( sal_uLong nWert ) const
154 : : {
155 : 697 : return pNd->GetIndex() >= nWert;
156 : : }
157 : 32980 : inline sal_Bool SwNodeIndex::operator==( sal_uLong nWert ) const
158 : : {
159 : 32980 : return pNd->GetIndex() == nWert;
160 : : }
161 : 1167 : inline sal_Bool SwNodeIndex::operator!=( sal_uLong nWert ) const
162 : : {
163 : 1167 : return pNd->GetIndex() != nWert;
164 : : }
165 : 3462028 : inline sal_Bool SwNodeIndex::operator<( const SwNodeIndex& rIndex ) const
166 : : {
167 : 3462028 : return pNd->GetIndex() < rIndex.GetIndex();
168 : : }
169 : 3100 : inline sal_Bool SwNodeIndex::operator<=( const SwNodeIndex& rIndex ) const
170 : : {
171 : 3100 : return pNd->GetIndex() <= rIndex.GetIndex();
172 : : }
173 : 5569821 : inline sal_Bool SwNodeIndex::operator>( const SwNodeIndex& rIndex ) const
174 : : {
175 : 5569821 : return pNd->GetIndex() > rIndex.GetIndex();
176 : : }
177 : 2582 : inline sal_Bool SwNodeIndex::operator>=( const SwNodeIndex& rIndex ) const
178 : : {
179 : 2582 : return pNd->GetIndex() >= rIndex.GetIndex();
180 : : }
181 : 9106545 : inline sal_Bool SwNodeIndex::operator==( const SwNodeIndex& rIdx ) const
182 : : {
183 : 9106545 : return pNd == rIdx.pNd;
184 : : }
185 : 951809 : inline sal_Bool SwNodeIndex::operator!=( const SwNodeIndex& rIdx ) const
186 : : {
187 : 951809 : return pNd != rIdx.pNd;
188 : : }
189 : :
190 : 1573 : inline sal_uLong SwNodeIndex::operator++()
191 : : {
192 : 1573 : return ( pNd = GetNodes()[ pNd->GetIndex()+1 ] )->GetIndex();
193 : : }
194 : 0 : inline sal_uLong SwNodeIndex::operator--()
195 : : {
196 : 0 : return ( pNd = GetNodes()[ pNd->GetIndex()-1 ] )->GetIndex();
197 : : }
198 : 66918 : inline sal_uLong SwNodeIndex::operator++(int)
199 : : {
200 : 66918 : sal_uLong nOldIndex = pNd->GetIndex();
201 : 66918 : pNd = GetNodes()[ nOldIndex + 1 ];
202 : 66918 : return nOldIndex;
203 : : }
204 : 8374 : inline sal_uLong SwNodeIndex::operator--(int)
205 : : {
206 : 8374 : sal_uLong nOldIndex = pNd->GetIndex();
207 : 8374 : pNd = GetNodes()[ nOldIndex - 1 ];
208 : 8374 : return nOldIndex;
209 : : }
210 : :
211 : 1349 : inline sal_uLong SwNodeIndex::operator+=( sal_uLong nWert )
212 : : {
213 : 1349 : return ( pNd = GetNodes()[ pNd->GetIndex() + nWert ] )->GetIndex();
214 : : }
215 : 168 : inline sal_uLong SwNodeIndex::operator-=( sal_uLong nWert )
216 : : {
217 : 168 : return ( pNd = GetNodes()[ pNd->GetIndex() - nWert ] )->GetIndex();
218 : : }
219 : : inline sal_uLong SwNodeIndex::operator+=( const SwNodeIndex& rIndex )
220 : : {
221 : : return ( pNd = GetNodes()[ pNd->GetIndex() + rIndex.GetIndex() ] )->GetIndex();
222 : : }
223 : : inline sal_uLong SwNodeIndex::operator-=( const SwNodeIndex& rIndex )
224 : : {
225 : : return ( pNd = GetNodes()[ pNd->GetIndex() - rIndex.GetIndex() ] )->GetIndex();
226 : : }
227 : :
228 : 23302 : inline SwNodeIndex& SwNodeIndex::operator=( sal_uLong nWert )
229 : : {
230 : 23302 : pNd = GetNodes()[ nWert ];
231 : 23302 : return *this;
232 : : }
233 : :
234 : : #endif
235 : :
236 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|