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 INCLUDED_SW_INC_NDINDEX_HXX
20 : #define INCLUDED_SW_INC_NDINDEX_HXX
21 :
22 : #include <limits.h>
23 :
24 : #include <tools/solar.h>
25 :
26 : #include <node.hxx>
27 :
28 : class SwNode;
29 : class SwNodes;
30 :
31 : /// Marks a node in the document model.
32 : class SW_DLLPUBLIC SwNodeIndex
33 : {
34 : friend void SwNodes::RegisterIndex( SwNodeIndex& );
35 : friend void SwNodes::DeRegisterIndex( SwNodeIndex& );
36 : friend void SwNodes::RemoveNode( sal_uLong, sal_uLong, sal_Bool );
37 :
38 : SwNode* pNd;
39 : SwNodeIndex *pNext, *pPrev;
40 :
41 : void Remove();
42 :
43 : // These are not allowed!
44 : SwNodeIndex( SwNodes& rNds, sal_uInt16 nIdx );
45 : SwNodeIndex( SwNodes& rNds, int nIdx );
46 :
47 : public:
48 : SwNodeIndex( SwNodes& rNds, sal_uLong nIdx = 0 );
49 : SwNodeIndex( const SwNodeIndex &, long nDiff = 0 );
50 : SwNodeIndex( const SwNode&, long nDiff = 0 );
51 0 : ~SwNodeIndex() { Remove(); }
52 :
53 : inline sal_uLong operator++();
54 : inline sal_uLong operator--();
55 : inline sal_uLong operator++(int);
56 : inline sal_uLong operator--(int);
57 :
58 : inline sal_uLong operator+=( sal_uLong );
59 : inline sal_uLong operator-=( sal_uLong );
60 : inline sal_uLong operator+=( const SwNodeIndex& );
61 : inline sal_uLong operator-=( const SwNodeIndex& );
62 :
63 : inline sal_Bool operator< ( const SwNodeIndex& ) const;
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 :
70 : inline sal_Bool operator< ( sal_uLong nWert ) const;
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 :
77 : inline SwNodeIndex& operator=( sal_uLong );
78 : SwNodeIndex& operator=( const SwNodeIndex& );
79 : SwNodeIndex& operator=( const SwNode& );
80 :
81 : // Return value of index as sal_uLong.
82 : inline sal_uLong GetIndex() const;
83 :
84 : // Enables assignments without creation of a temporary object.
85 : SwNodeIndex& Assign( SwNodes& rNds, sal_uLong );
86 : SwNodeIndex& Assign( const SwNode& rNd, long nOffset = 0 );
87 :
88 : // Gets pointer on NodesArray.
89 : inline const SwNodes& GetNodes() const;
90 : inline SwNodes& GetNodes();
91 :
92 0 : SwNode& GetNode() const { return *pNd; }
93 : };
94 :
95 : // SwRange
96 :
97 0 : class SW_DLLPUBLIC SwNodeRange
98 : {
99 : public:
100 : SwNodeIndex aStart;
101 : SwNodeIndex aEnd;
102 :
103 : SwNodeRange( const SwNodeIndex &rS, const SwNodeIndex &rE );
104 : SwNodeRange( const SwNodeRange &rRange );
105 :
106 : SwNodeRange( SwNodes& rArr, sal_uLong nSttIdx = 0, sal_uLong nEndIdx = 0 );
107 : SwNodeRange( const SwNodeIndex& rS, long nSttDiff,
108 : const SwNodeIndex& rE, long nEndDiff = 0 );
109 : SwNodeRange( const SwNode& rS, long nSttDiff,
110 : const SwNode& rE, long nEndDiff = 0 );
111 : };
112 :
113 : // For inlines node.hxx is needed which in turn needs this one.
114 : // Therefore all inlines accessing pNd are implemented here.
115 :
116 0 : inline sal_uLong SwNodeIndex::GetIndex() const
117 : {
118 0 : return pNd->GetIndex();
119 : }
120 0 : inline const SwNodes& SwNodeIndex::GetNodes() const
121 : {
122 0 : return pNd->GetNodes();
123 : }
124 0 : inline SwNodes& SwNodeIndex::GetNodes()
125 : {
126 0 : return pNd->GetNodes();
127 : }
128 0 : inline sal_Bool SwNodeIndex::operator< ( sal_uLong nWert ) const
129 : {
130 0 : return pNd->GetIndex() < nWert;
131 : }
132 0 : inline sal_Bool SwNodeIndex::operator<=( sal_uLong nWert ) const
133 : {
134 0 : return pNd->GetIndex() <= nWert;
135 : }
136 0 : inline sal_Bool SwNodeIndex::operator> ( sal_uLong nWert ) const
137 : {
138 0 : return pNd->GetIndex() > nWert;
139 : }
140 0 : inline sal_Bool SwNodeIndex::operator>=( sal_uLong nWert ) const
141 : {
142 0 : return pNd->GetIndex() >= nWert;
143 : }
144 0 : inline sal_Bool SwNodeIndex::operator==( sal_uLong nWert ) const
145 : {
146 0 : return pNd->GetIndex() == nWert;
147 : }
148 0 : inline sal_Bool SwNodeIndex::operator!=( sal_uLong nWert ) const
149 : {
150 0 : return pNd->GetIndex() != nWert;
151 : }
152 0 : inline sal_Bool SwNodeIndex::operator<( const SwNodeIndex& rIndex ) const
153 : {
154 0 : return pNd->GetIndex() < rIndex.GetIndex();
155 : }
156 0 : inline sal_Bool SwNodeIndex::operator<=( const SwNodeIndex& rIndex ) const
157 : {
158 0 : return pNd->GetIndex() <= rIndex.GetIndex();
159 : }
160 0 : inline sal_Bool SwNodeIndex::operator>( const SwNodeIndex& rIndex ) const
161 : {
162 0 : return pNd->GetIndex() > rIndex.GetIndex();
163 : }
164 0 : inline sal_Bool SwNodeIndex::operator>=( const SwNodeIndex& rIndex ) const
165 : {
166 0 : return pNd->GetIndex() >= rIndex.GetIndex();
167 : }
168 0 : inline sal_Bool SwNodeIndex::operator==( const SwNodeIndex& rIdx ) const
169 : {
170 0 : return pNd == rIdx.pNd;
171 : }
172 0 : inline sal_Bool SwNodeIndex::operator!=( const SwNodeIndex& rIdx ) const
173 : {
174 0 : return pNd != rIdx.pNd;
175 : }
176 :
177 0 : inline sal_uLong SwNodeIndex::operator++()
178 : {
179 0 : return ( pNd = GetNodes()[ pNd->GetIndex()+1 ] )->GetIndex();
180 : }
181 0 : inline sal_uLong SwNodeIndex::operator--()
182 : {
183 0 : return ( pNd = GetNodes()[ pNd->GetIndex()-1 ] )->GetIndex();
184 : }
185 0 : inline sal_uLong SwNodeIndex::operator++(int)
186 : {
187 0 : sal_uLong nOldIndex = pNd->GetIndex();
188 0 : pNd = GetNodes()[ nOldIndex + 1 ];
189 0 : return nOldIndex;
190 : }
191 0 : inline sal_uLong SwNodeIndex::operator--(int)
192 : {
193 0 : sal_uLong nOldIndex = pNd->GetIndex();
194 0 : pNd = GetNodes()[ nOldIndex - 1 ];
195 0 : return nOldIndex;
196 : }
197 :
198 0 : inline sal_uLong SwNodeIndex::operator+=( sal_uLong nWert )
199 : {
200 0 : return ( pNd = GetNodes()[ pNd->GetIndex() + nWert ] )->GetIndex();
201 : }
202 0 : inline sal_uLong SwNodeIndex::operator-=( sal_uLong nWert )
203 : {
204 0 : return ( pNd = GetNodes()[ pNd->GetIndex() - nWert ] )->GetIndex();
205 : }
206 : inline sal_uLong SwNodeIndex::operator+=( const SwNodeIndex& rIndex )
207 : {
208 : return ( pNd = GetNodes()[ pNd->GetIndex() + rIndex.GetIndex() ] )->GetIndex();
209 : }
210 : inline sal_uLong SwNodeIndex::operator-=( const SwNodeIndex& rIndex )
211 : {
212 : return ( pNd = GetNodes()[ pNd->GetIndex() - rIndex.GetIndex() ] )->GetIndex();
213 : }
214 :
215 0 : inline SwNodeIndex& SwNodeIndex::operator=( sal_uLong nWert )
216 : {
217 0 : pNd = GetNodes()[ nWert ];
218 0 : return *this;
219 : }
220 :
221 : #endif
222 :
223 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|