update credits
[LibreOffice.git] / sw / inc / ndindex.hxx
blob9141c597ce6fa241c568dcc2c3ef6c8bc208f8c3
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
19 #ifndef SW_NDINDEX_HXX
20 #define SW_NDINDEX_HXX
22 #include <limits.h>
24 #include <tools/solar.h>
26 #include <node.hxx>
29 class SwNode;
30 class SwNodes;
32 /// Marks a node in the document model.
33 class SW_DLLPUBLIC SwNodeIndex
35 friend void SwNodes::RegisterIndex( SwNodeIndex& );
36 friend void SwNodes::DeRegisterIndex( SwNodeIndex& );
37 friend void SwNodes::RemoveNode( sal_uLong, sal_uLong, sal_Bool );
39 SwNode* pNd;
40 SwNodeIndex *pNext, *pPrev;
42 void Remove();
44 // These are not allowed!
45 SwNodeIndex( SwNodes& rNds, sal_uInt16 nIdx );
46 SwNodeIndex( SwNodes& rNds, int nIdx );
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 ~SwNodeIndex() { Remove(); }
54 inline sal_uLong operator++();
55 inline sal_uLong operator--();
56 inline sal_uLong operator++(int);
57 inline sal_uLong operator--(int);
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& );
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;
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;
78 inline SwNodeIndex& operator=( sal_uLong );
79 SwNodeIndex& operator=( const SwNodeIndex& );
80 SwNodeIndex& operator=( const SwNode& );
82 // Return value of index as sal_uLong.
83 inline sal_uLong GetIndex() const;
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 );
89 // Gets pointer on NodesArray.
90 inline const SwNodes& GetNodes() const;
91 inline SwNodes& GetNodes();
93 SwNode& GetNode() const { return *pNd; }
96 // SwRange
98 class SW_DLLPUBLIC SwNodeRange
100 public:
101 SwNodeIndex aStart;
102 SwNodeIndex aEnd;
104 SwNodeRange( const SwNodeIndex &rS, const SwNodeIndex &rE );
105 SwNodeRange( const SwNodeRange &rRange );
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 );
117 // For inlines node.hxx is needed which in turn needs this one.
118 // Therefore all inlines accessing pNd are implemented here.
120 inline sal_uLong SwNodeIndex::GetIndex() const
122 return pNd->GetIndex();
124 inline const SwNodes& SwNodeIndex::GetNodes() const
126 return pNd->GetNodes();
128 inline SwNodes& SwNodeIndex::GetNodes()
130 return pNd->GetNodes();
132 inline sal_Bool SwNodeIndex::operator< ( sal_uLong nWert ) const
134 return pNd->GetIndex() < nWert;
136 inline sal_Bool SwNodeIndex::operator<=( sal_uLong nWert ) const
138 return pNd->GetIndex() <= nWert;
140 inline sal_Bool SwNodeIndex::operator> ( sal_uLong nWert ) const
142 return pNd->GetIndex() > nWert;
144 inline sal_Bool SwNodeIndex::operator>=( sal_uLong nWert ) const
146 return pNd->GetIndex() >= nWert;
148 inline sal_Bool SwNodeIndex::operator==( sal_uLong nWert ) const
150 return pNd->GetIndex() == nWert;
152 inline sal_Bool SwNodeIndex::operator!=( sal_uLong nWert ) const
154 return pNd->GetIndex() != nWert;
156 inline sal_Bool SwNodeIndex::operator<( const SwNodeIndex& rIndex ) const
158 return pNd->GetIndex() < rIndex.GetIndex();
160 inline sal_Bool SwNodeIndex::operator<=( const SwNodeIndex& rIndex ) const
162 return pNd->GetIndex() <= rIndex.GetIndex();
164 inline sal_Bool SwNodeIndex::operator>( const SwNodeIndex& rIndex ) const
166 return pNd->GetIndex() > rIndex.GetIndex();
168 inline sal_Bool SwNodeIndex::operator>=( const SwNodeIndex& rIndex ) const
170 return pNd->GetIndex() >= rIndex.GetIndex();
172 inline sal_Bool SwNodeIndex::operator==( const SwNodeIndex& rIdx ) const
174 return pNd == rIdx.pNd;
176 inline sal_Bool SwNodeIndex::operator!=( const SwNodeIndex& rIdx ) const
178 return pNd != rIdx.pNd;
181 inline sal_uLong SwNodeIndex::operator++()
183 return ( pNd = GetNodes()[ pNd->GetIndex()+1 ] )->GetIndex();
185 inline sal_uLong SwNodeIndex::operator--()
187 return ( pNd = GetNodes()[ pNd->GetIndex()-1 ] )->GetIndex();
189 inline sal_uLong SwNodeIndex::operator++(int)
191 sal_uLong nOldIndex = pNd->GetIndex();
192 pNd = GetNodes()[ nOldIndex + 1 ];
193 return nOldIndex;
195 inline sal_uLong SwNodeIndex::operator--(int)
197 sal_uLong nOldIndex = pNd->GetIndex();
198 pNd = GetNodes()[ nOldIndex - 1 ];
199 return nOldIndex;
202 inline sal_uLong SwNodeIndex::operator+=( sal_uLong nWert )
204 return ( pNd = GetNodes()[ pNd->GetIndex() + nWert ] )->GetIndex();
206 inline sal_uLong SwNodeIndex::operator-=( sal_uLong nWert )
208 return ( pNd = GetNodes()[ pNd->GetIndex() - nWert ] )->GetIndex();
210 inline sal_uLong SwNodeIndex::operator+=( const SwNodeIndex& rIndex )
212 return ( pNd = GetNodes()[ pNd->GetIndex() + rIndex.GetIndex() ] )->GetIndex();
214 inline sal_uLong SwNodeIndex::operator-=( const SwNodeIndex& rIndex )
216 return ( pNd = GetNodes()[ pNd->GetIndex() - rIndex.GetIndex() ] )->GetIndex();
219 inline SwNodeIndex& SwNodeIndex::operator=( sal_uLong nWert )
221 pNd = GetNodes()[ nWert ];
222 return *this;
225 #endif
227 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */