LibreOffice Module sw (master) 1
ndindex.hxx
Go to the documentation of this file.
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 <iostream>
23
24#include "node.hxx"
25#include "ring.hxx"
26#include "ndarr.hxx"
27#include "nodeoffset.hxx"
28
30class SAL_WARN_UNUSED SW_DLLPUBLIC SwNodeIndex final : public sw::Ring<SwNodeIndex>
31{
33
34 void RegisterIndex( SwNodes& rNodes )
35 {
36 if(!rNodes.m_vIndices)
37 {
38#if defined(__GNUC__) && __GNUC__ == 12
39#pragma GCC diagnostic push
40#pragma GCC diagnostic ignored "-Wdangling-pointer"
41#endif
42 rNodes.m_vIndices = this;
43#if defined(__GNUC__) && __GNUC__ == 12
44#pragma GCC diagnostic pop
45#endif
46 }
47 MoveTo(rNodes.m_vIndices);
48 }
49 void DeRegisterIndex( SwNodes& rNodes )
50 {
51 if(rNodes.m_vIndices == this)
52 rNodes.m_vIndices = GetNextInRing();
53 MoveTo(nullptr);
54 if(rNodes.m_vIndices == this)
55 rNodes.m_vIndices = nullptr;
56 }
57
58public:
59 SwNodeIndex( SwNodes& rNds, sal_Int32 nIdx ) : SwNodeIndex(rNds, SwNodeOffset(nIdx)) {}
60 explicit SwNodeIndex( SwNodes& rNds, SwNodeOffset nIdx = SwNodeOffset(0) )
61 : m_pNode( rNds[ nIdx ] )
62 {
63 RegisterIndex( rNds );
64 };
65 SwNodeIndex( const SwNodeIndex& rIdx, sal_Int32 nDiff ) : SwNodeIndex(rIdx, SwNodeOffset(nDiff)) {}
66 SwNodeIndex( const SwNodeIndex& rIdx, SwNodeOffset nDiff )
67 : sw::Ring<SwNodeIndex>()
68 {
69 if( nDiff )
70 m_pNode = rIdx.GetNodes()[ rIdx.GetIndex() + nDiff ];
71 else
72 m_pNode = rIdx.m_pNode;
73 RegisterIndex( m_pNode->GetNodes() );
74 }
75 SwNodeIndex( const SwNodeIndex& rIdx ) : SwNodeIndex(rIdx, 0) {}
76
77 SwNodeIndex( const SwNode& rNd, sal_Int32 nDiff ) : SwNodeIndex(rNd, SwNodeOffset(nDiff)) {}
78 explicit SwNodeIndex( const SwNode& rNd, SwNodeOffset nDiff = SwNodeOffset(0) )
79 {
80 if( nDiff )
81 m_pNode = rNd.GetNodes()[ rNd.GetIndex() + nDiff ];
82 else
83 m_pNode = const_cast<SwNode*>(&rNd);
84 RegisterIndex( m_pNode->GetNodes() );
85 }
86
87 virtual ~SwNodeIndex() override
88 { DeRegisterIndex( m_pNode->GetNodes() ); }
89
90 inline SwNodeOffset operator++();
91 inline SwNodeOffset operator--();
92 inline SwNodeOffset operator++(int);
93 inline SwNodeOffset operator--(int);
94
97
98 inline bool operator< ( const SwNodeIndex& ) const;
99 inline bool operator<=( const SwNodeIndex& ) const;
100 inline bool operator> ( const SwNodeIndex& ) const;
101 inline bool operator>=( const SwNodeIndex& ) const;
102 inline bool operator==( const SwNodeIndex& ) const;
103 inline bool operator!=( const SwNodeIndex& ) const;
104
105 inline bool operator< ( SwNodeOffset ) const;
106 inline bool operator<=( SwNodeOffset ) const;
107 inline bool operator> ( SwNodeOffset ) const;
108 inline bool operator>=( SwNodeOffset ) const;
109 inline bool operator==( SwNodeOffset ) const;
110 inline bool operator!=( SwNodeOffset ) const;
111
112 bool operator<( const SwNode& rNd ) const { return operator<(rNd.GetIndex()); }
113 bool operator<=( const SwNode& rNd ) const { return operator<=(rNd.GetIndex()); }
114 bool operator>( const SwNode& rNd ) const { return operator>(rNd.GetIndex()); }
115 bool operator>=( const SwNode& rNd ) const { return operator>=(rNd.GetIndex()); }
116 bool operator==( const SwNode& rNd ) const { return m_pNode == &rNd; }
117 bool operator!=( const SwNode& rNd ) const { return m_pNode != &rNd; }
118
119 inline SwNodeIndex& operator=( SwNodeOffset );
120 inline SwNodeIndex& operator=( const SwNodeIndex& );
121 inline SwNodeIndex& operator=( const SwNode& );
122
123 // Return value of index as SwNodeOffset.
124 inline SwNodeOffset GetIndex() const;
125
126 // Enables assignments without creation of a temporary object.
127 inline SwNodeIndex& Assign( SwNodes const & rNds, SwNodeOffset );
128 SwNodeIndex& Assign( const SwNode& rNd, sal_Int32 nOffset ) { return Assign(rNd, SwNodeOffset(nOffset)); }
129 inline SwNodeIndex& Assign( const SwNode& rNd, SwNodeOffset nOffset = SwNodeOffset(0) );
130
131 // Gets pointer on NodesArray.
132 inline const SwNodes& GetNodes() const;
133 inline SwNodes& GetNodes();
134
136 SwNode& GetNode() const { return *m_pNode; }
137};
138
139inline std::ostream &operator <<(std::ostream& s, const SwNodeIndex& index)
140{
141 return s << "SwNodeIndex (node " << sal_Int32(index.GetIndex()) << ")";
142};
143
144// SwRange
145
147{
148public:
151
152 SwNodeRange( const SwNodeIndex &rS, const SwNodeIndex &rE )
153 : aStart( rS ), aEnd( rE ) {};
154 SwNodeRange( const SwNode &rS, const SwNode &rE )
155 : aStart( rS ), aEnd( rE ) {};
156 SwNodeRange( const SwNodeRange &rRange )
157 : aStart( rRange.aStart ), aEnd( rRange.aEnd ) {};
158
160 : aStart( rNds, nSttIdx ), aEnd( rNds, nEndIdx ) {};
161
162 SwNodeRange( const SwNodeIndex& rS, SwNodeOffset nSttDiff, const SwNodeIndex& rE, SwNodeOffset nEndDiff = SwNodeOffset(0) )
163 : aStart( rS, nSttDiff ), aEnd( rE, nEndDiff ) {};
164 SwNodeRange( const SwNode& rS, SwNodeOffset nSttDiff, const SwNode& rE, SwNodeOffset nEndDiff = SwNodeOffset(0) )
165 : aStart( rS, nSttDiff ), aEnd( rE, nEndDiff ) {};
166};
167
168// For inlines node.hxx is needed which in turn needs this one.
169// Therefore all inlines accessing m_pNode are implemented here.
170
172{
173 return m_pNode->GetIndex();
174}
175inline const SwNodes& SwNodeIndex::GetNodes() const
176{
177 return m_pNode->GetNodes();
178}
180{
181 return m_pNode->GetNodes();
182}
183inline bool SwNodeIndex::operator< ( SwNodeOffset const nOther ) const
184{
185 return m_pNode->GetIndex() < nOther;
186}
187inline bool SwNodeIndex::operator<=( SwNodeOffset const nOther ) const
188{
189 return m_pNode->GetIndex() <= nOther;
190}
191inline bool SwNodeIndex::operator> ( SwNodeOffset const nOther ) const
192{
193 return m_pNode->GetIndex() > nOther;
194}
195inline bool SwNodeIndex::operator>=( SwNodeOffset const nOther ) const
196{
197 return m_pNode->GetIndex() >= nOther;
198}
199inline bool SwNodeIndex::operator==( SwNodeOffset const nOther ) const
200{
201 return m_pNode->GetIndex() == nOther;
202}
203inline bool SwNodeIndex::operator!=( SwNodeOffset const nOther ) const
204{
205 return m_pNode->GetIndex() != nOther;
206}
207inline bool SwNodeIndex::operator<( const SwNodeIndex& rIndex ) const
208{
209 return m_pNode->GetIndex() < rIndex.GetIndex();
210}
211inline bool SwNodeIndex::operator<=( const SwNodeIndex& rIndex ) const
212{
213 return m_pNode->GetIndex() <= rIndex.GetIndex();
214}
215inline bool SwNodeIndex::operator>( const SwNodeIndex& rIndex ) const
216{
217 return m_pNode->GetIndex() > rIndex.GetIndex();
218}
219inline bool SwNodeIndex::operator>=( const SwNodeIndex& rIndex ) const
220{
221 return m_pNode->GetIndex() >= rIndex.GetIndex();
222}
223inline bool SwNodeIndex::operator==( const SwNodeIndex& rIdx ) const
224{
225 return m_pNode == rIdx.m_pNode;
226}
227inline bool SwNodeIndex::operator!=( const SwNodeIndex& rIdx ) const
228{
229 return m_pNode != rIdx.m_pNode;
230}
231
233{
234 m_pNode = GetNodes()[ m_pNode->GetIndex() + 1 ];
235 return m_pNode->GetIndex();
236}
238{
239 m_pNode = GetNodes()[ m_pNode->GetIndex() - 1 ];
240 return m_pNode->GetIndex();
241}
243{
244 SwNodeOffset nOldIndex = m_pNode->GetIndex();
245 m_pNode = GetNodes()[ nOldIndex + 1 ];
246 return nOldIndex;
247}
249{
250 SwNodeOffset nOldIndex = m_pNode->GetIndex();
251 m_pNode = GetNodes()[ nOldIndex - 1 ];
252 return nOldIndex;
253}
254
256{
257 m_pNode = GetNodes()[ m_pNode->GetIndex() + nOffset ];
258 return m_pNode->GetIndex();
259}
261{
262 m_pNode = GetNodes()[ m_pNode->GetIndex() - nOffset ];
263 return m_pNode->GetIndex();
264}
265
267{
268 m_pNode = GetNodes()[ nNew ];
269 return *this;
270}
271
273{
274 *this = *(rIdx.m_pNode);
275 return *this;
276}
277
279{
280 if (&m_pNode->GetNodes() != &rNd.GetNodes())
281 {
283 m_pNode = const_cast<SwNode*>(&rNd);
285 }
286 else
287 m_pNode = const_cast<SwNode*>(&rNd);
288 return *this;
289}
290
292{
293 *this = *rNds[ nIdx ];
294 return *this;
295}
296
298{
299 *this = rNd;
300
301 if( nOffset )
302 m_pNode = m_pNode->GetNodes()[ m_pNode->GetIndex() + nOffset ];
303
304 return *this;
305}
306
307#endif
308
309/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
bool operator<=(const BigInt &rVal1, const BigInt &rVal2)
bool operator>=(const BigInt &rVal1, const BigInt &rVal2)
Marks a node in the document model.
Definition: ndindex.hxx:31
SwNodeIndex & Assign(SwNodes const &rNds, SwNodeOffset)
Definition: ndindex.hxx:291
bool operator>(const SwNodeIndex &) const
Definition: ndindex.hxx:215
bool operator==(const SwNodeIndex &) const
Definition: ndindex.hxx:223
bool operator<(const SwNodeIndex &) const
Definition: ndindex.hxx:207
bool operator==(const SwNode &rNd) const
Definition: ndindex.hxx:116
bool operator!=(const SwNode &rNd) const
Definition: ndindex.hxx:117
bool operator>(const SwNode &rNd) const
Definition: ndindex.hxx:114
const SwNodes & GetNodes() const
Definition: ndindex.hxx:175
SwNodeOffset operator--()
Definition: ndindex.hxx:237
SwNodeIndex * GetNext()
Definition: ndindex.hxx:135
SwNodeIndex(const SwNodeIndex &rIdx, SwNodeOffset nDiff)
Definition: ndindex.hxx:66
bool operator>=(const SwNode &rNd) const
Definition: ndindex.hxx:115
bool operator>=(const SwNodeIndex &) const
Definition: ndindex.hxx:219
SwNodeOffset operator+=(SwNodeOffset)
Definition: ndindex.hxx:255
SwNodeIndex(const SwNode &rNd, sal_Int32 nDiff)
Definition: ndindex.hxx:77
SwNodeOffset operator-=(SwNodeOffset)
Definition: ndindex.hxx:260
SwNodeIndex(const SwNodeIndex &rIdx, sal_Int32 nDiff)
Definition: ndindex.hxx:65
bool operator!=(const SwNodeIndex &) const
Definition: ndindex.hxx:227
bool operator<(const SwNode &rNd) const
Definition: ndindex.hxx:112
void RegisterIndex(SwNodes &rNodes)
Definition: ndindex.hxx:34
SwNode & GetNode() const
Definition: ndindex.hxx:136
SwNodeIndex(const SwNodeIndex &rIdx)
Definition: ndindex.hxx:75
bool operator<=(const SwNodeIndex &) const
Definition: ndindex.hxx:211
virtual ~SwNodeIndex() override
Definition: ndindex.hxx:87
SwNodeIndex & Assign(const SwNode &rNd, sal_Int32 nOffset)
Definition: ndindex.hxx:128
SwNodeOffset GetIndex() const
Definition: ndindex.hxx:171
void DeRegisterIndex(SwNodes &rNodes)
Definition: ndindex.hxx:49
SwNodeOffset operator++()
Definition: ndindex.hxx:232
bool operator<=(const SwNode &rNd) const
Definition: ndindex.hxx:113
SwNodeIndex(SwNodes &rNds, sal_Int32 nIdx)
Definition: ndindex.hxx:59
SwNodeIndex(const SwNode &rNd, SwNodeOffset nDiff=SwNodeOffset(0))
Definition: ndindex.hxx:78
SwNodeIndex(SwNodes &rNds, SwNodeOffset nIdx=SwNodeOffset(0))
Definition: ndindex.hxx:60
SwNodeIndex & operator=(SwNodeOffset)
Definition: ndindex.hxx:266
SwNode * m_pNode
Definition: ndindex.hxx:32
SwNodeRange(const SwNodeRange &rRange)
Definition: ndindex.hxx:156
SwNodeRange(SwNodes &rNds, SwNodeOffset nSttIdx, SwNodeOffset nEndIdx=SwNodeOffset(0))
Definition: ndindex.hxx:159
SwNodeIndex aStart
Definition: ndindex.hxx:149
SwNodeRange(const SwNodeIndex &rS, const SwNodeIndex &rE)
Definition: ndindex.hxx:152
SwNodeRange(const SwNode &rS, SwNodeOffset nSttDiff, const SwNode &rE, SwNodeOffset nEndDiff=SwNodeOffset(0))
Definition: ndindex.hxx:164
SwNodeRange(const SwNode &rS, const SwNode &rE)
Definition: ndindex.hxx:154
SwNodeRange(const SwNodeIndex &rS, SwNodeOffset nSttDiff, const SwNodeIndex &rE, SwNodeOffset nEndDiff=SwNodeOffset(0))
Definition: ndindex.hxx:162
SwNodeIndex aEnd
Definition: ndindex.hxx:150
Base class of the Writer document model elements.
Definition: node.hxx:84
SwNodeOffset GetIndex() const
Definition: node.hxx:296
SwNodes & GetNodes()
Node is in which nodes-array/doc?
Definition: node.hxx:721
SwNodeIndex * m_vIndices
ring of all indices on nodes.
Definition: ndarr.hxx:98
void MoveTo(value_type *pDestRing)
Removes this item from its current ring container and adds it to another ring container.
Definition: ring.hxx:135
value_type * GetNextInRing()
Definition: ring.hxx:84
SotClipboardFormatId & operator++(SotClipboardFormatId &eFormat)
index
Dialog to specify the properties of date form field.
std::ostream & operator<<(std::ostream &s, const SwNodeIndex &index)
Definition: ndindex.hxx:139
o3tl::strong_int< sal_Int32, struct Tag_SwNodeOffset > SwNodeOffset
Definition: nodeoffset.hxx:16
timeval & operator-=(timeval &t1, const timeval &t2)
TOOLS_DLLPUBLIC tools::Rectangle & operator+=(tools::Rectangle &rRect, const SvBorder &rBorder)
#define SW_DLLPUBLIC
Definition: swdllapi.h:28
#define SAL_WARN_UNUSED
bool operator<(const wwFont &r1, const wwFont &r2)
Definition: wrtw8sty.cxx:841
bool operator!=(const XclExpString &rLeft, const XclExpString &rRight)
bool operator==(const XclFontData &rLeft, const XclFontData &rRight)