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 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)) {}
61 : m_pNode( rNds[ nIdx ] )
62 {
63 RegisterIndex( rNds );
64 };
65 SwNodeIndex( const SwNodeIndex& rIdx, sal_Int32 nDiff ) : 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
76 SwNodeIndex( const SwNode& rNd, sal_Int32 nDiff ) : SwNodeIndex(rNd, SwNodeOffset(nDiff)) {}
77 SwNodeIndex( const SwNode& rNd, SwNodeOffset nDiff = SwNodeOffset(0) )
78 {
79 if( nDiff )
80 m_pNode = rNd.GetNodes()[ rNd.GetIndex() + nDiff ];
81 else
82 m_pNode = const_cast<SwNode*>(&rNd);
83 RegisterIndex( m_pNode->GetNodes() );
84 }
85
86 virtual ~SwNodeIndex() override
87 { DeRegisterIndex( m_pNode->GetNodes() ); }
88
89 inline SwNodeOffset operator++();
90 inline SwNodeOffset operator--();
91 inline SwNodeOffset operator++(int);
92 inline SwNodeOffset operator--(int);
93
96
97 inline bool operator< ( const SwNodeIndex& ) const;
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
104 inline bool operator< ( SwNodeOffset ) const;
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
111 inline SwNodeIndex& operator=( SwNodeOffset );
112 inline SwNodeIndex& operator=( const SwNodeIndex& );
113 inline SwNodeIndex& operator=( const SwNode& );
114
115 // Return value of index as SwNodeOffset.
116 inline SwNodeOffset GetIndex() const;
117
118 // Enables assignments without creation of a temporary object.
119 inline SwNodeIndex& Assign( SwNodes const & rNds, SwNodeOffset );
120 SwNodeIndex& Assign( const SwNode& rNd, sal_Int32 nOffset ) { return Assign(rNd, SwNodeOffset(nOffset)); }
121 inline SwNodeIndex& Assign( const SwNode& rNd, SwNodeOffset nOffset = SwNodeOffset(0) );
122
123 // Gets pointer on NodesArray.
124 inline const SwNodes& GetNodes() const;
125 inline SwNodes& GetNodes();
126
128 SwNode& GetNode() const { return *m_pNode; }
129};
130
131inline std::ostream &operator <<(std::ostream& s, const SwNodeIndex& index)
132{
133 return s << "SwNodeIndex (node " << sal_Int32(index.GetIndex()) << ")";
134};
135
136// SwRange
137
139{
140public:
143
144 SwNodeRange( const SwNodeIndex &rS, const SwNodeIndex &rE )
145 : aStart( rS ), aEnd( rE ) {};
146 SwNodeRange( const SwNodeRange &rRange )
147 : aStart( rRange.aStart ), aEnd( rRange.aEnd ) {};
148
150 : aStart( rNds, nSttIdx ), aEnd( rNds, nEndIdx ) {};
151
152 SwNodeRange( const SwNodeIndex& rS, SwNodeOffset nSttDiff, const SwNodeIndex& rE, SwNodeOffset nEndDiff = SwNodeOffset(0) )
153 : aStart( rS, nSttDiff ), aEnd( rE, nEndDiff ) {};
154 SwNodeRange( const SwNode& rS, SwNodeOffset nSttDiff, const SwNode& rE, SwNodeOffset nEndDiff = SwNodeOffset(0) )
155 : aStart( rS, nSttDiff ), aEnd( rE, nEndDiff ) {};
156};
157
158// For inlines node.hxx is needed which in turn needs this one.
159// Therefore all inlines accessing m_pNode are implemented here.
160
162{
163 return m_pNode->GetIndex();
164}
165inline const SwNodes& SwNodeIndex::GetNodes() const
166{
167 return m_pNode->GetNodes();
168}
170{
171 return m_pNode->GetNodes();
172}
173inline bool SwNodeIndex::operator< ( SwNodeOffset const nOther ) const
174{
175 return m_pNode->GetIndex() < nOther;
176}
177inline bool SwNodeIndex::operator<=( SwNodeOffset const nOther ) const
178{
179 return m_pNode->GetIndex() <= nOther;
180}
181inline bool SwNodeIndex::operator> ( SwNodeOffset const nOther ) const
182{
183 return m_pNode->GetIndex() > nOther;
184}
185inline bool SwNodeIndex::operator>=( SwNodeOffset const nOther ) const
186{
187 return m_pNode->GetIndex() >= nOther;
188}
189inline bool SwNodeIndex::operator==( SwNodeOffset const nOther ) const
190{
191 return m_pNode->GetIndex() == nOther;
192}
193inline bool SwNodeIndex::operator!=( SwNodeOffset const nOther ) const
194{
195 return m_pNode->GetIndex() != nOther;
196}
197inline bool SwNodeIndex::operator<( const SwNodeIndex& rIndex ) const
198{
199 return m_pNode->GetIndex() < rIndex.GetIndex();
200}
201inline bool SwNodeIndex::operator<=( const SwNodeIndex& rIndex ) const
202{
203 return m_pNode->GetIndex() <= rIndex.GetIndex();
204}
205inline bool SwNodeIndex::operator>( const SwNodeIndex& rIndex ) const
206{
207 return m_pNode->GetIndex() > rIndex.GetIndex();
208}
209inline bool SwNodeIndex::operator>=( const SwNodeIndex& rIndex ) const
210{
211 return m_pNode->GetIndex() >= rIndex.GetIndex();
212}
213inline bool SwNodeIndex::operator==( const SwNodeIndex& rIdx ) const
214{
215 return m_pNode == rIdx.m_pNode;
216}
217inline bool SwNodeIndex::operator!=( const SwNodeIndex& rIdx ) const
218{
219 return m_pNode != rIdx.m_pNode;
220}
221
223{
224 m_pNode = GetNodes()[ m_pNode->GetIndex() + 1 ];
225 return m_pNode->GetIndex();
226}
228{
229 m_pNode = GetNodes()[ m_pNode->GetIndex() - 1 ];
230 return m_pNode->GetIndex();
231}
233{
234 SwNodeOffset nOldIndex = m_pNode->GetIndex();
235 m_pNode = GetNodes()[ nOldIndex + 1 ];
236 return nOldIndex;
237}
239{
240 SwNodeOffset nOldIndex = m_pNode->GetIndex();
241 m_pNode = GetNodes()[ nOldIndex - 1 ];
242 return nOldIndex;
243}
244
246{
247 m_pNode = GetNodes()[ m_pNode->GetIndex() + nOffset ];
248 return m_pNode->GetIndex();
249}
251{
252 m_pNode = GetNodes()[ m_pNode->GetIndex() - nOffset ];
253 return m_pNode->GetIndex();
254}
255
257{
258 m_pNode = GetNodes()[ nNew ];
259 return *this;
260}
261
263{
264 *this = *(rIdx.m_pNode);
265 return *this;
266}
267
269{
270 if (&m_pNode->GetNodes() != &rNd.GetNodes())
271 {
273 m_pNode = const_cast<SwNode*>(&rNd);
275 }
276 else
277 m_pNode = const_cast<SwNode*>(&rNd);
278 return *this;
279}
280
282{
283 *this = *rNds[ nIdx ];
284 return *this;
285}
286
288{
289 *this = rNd;
290
291 if( nOffset )
292 m_pNode = m_pNode->GetNodes()[ m_pNode->GetIndex() + nOffset ];
293
294 return *this;
295}
296
297#endif
298
299/* 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:281
bool operator>(const SwNodeIndex &) const
Definition: ndindex.hxx:205
bool operator==(const SwNodeIndex &) const
Definition: ndindex.hxx:213
bool operator<(const SwNodeIndex &) const
Definition: ndindex.hxx:197
const SwNodes & GetNodes() const
Definition: ndindex.hxx:165
SwNodeOffset operator--()
Definition: ndindex.hxx:227
SwNodeIndex * GetNext()
Definition: ndindex.hxx:127
bool operator>=(const SwNodeIndex &) const
Definition: ndindex.hxx:209
SwNodeOffset operator+=(SwNodeOffset)
Definition: ndindex.hxx:245
SwNodeIndex(const SwNode &rNd, sal_Int32 nDiff)
Definition: ndindex.hxx:76
SwNodeOffset operator-=(SwNodeOffset)
Definition: ndindex.hxx:250
SwNodeIndex(const SwNodeIndex &rIdx, sal_Int32 nDiff)
Definition: ndindex.hxx:65
bool operator!=(const SwNodeIndex &) const
Definition: ndindex.hxx:217
void RegisterIndex(SwNodes &rNodes)
Definition: ndindex.hxx:34
SwNode & GetNode() const
Definition: ndindex.hxx:128
bool operator<=(const SwNodeIndex &) const
Definition: ndindex.hxx:201
virtual ~SwNodeIndex() override
Definition: ndindex.hxx:86
SwNodeIndex & Assign(const SwNode &rNd, sal_Int32 nOffset)
Definition: ndindex.hxx:120
SwNodeOffset GetIndex() const
Definition: ndindex.hxx:161
void DeRegisterIndex(SwNodes &rNodes)
Definition: ndindex.hxx:49
SwNodeOffset operator++()
Definition: ndindex.hxx:222
SwNodeIndex(SwNodes &rNds, sal_Int32 nIdx)
Definition: ndindex.hxx:59
SwNodeIndex(const SwNode &rNd, SwNodeOffset nDiff=SwNodeOffset(0))
Definition: ndindex.hxx:77
SwNodeIndex(SwNodes &rNds, SwNodeOffset nIdx=SwNodeOffset(0))
Definition: ndindex.hxx:60
SwNodeIndex(const SwNodeIndex &rIdx, SwNodeOffset nDiff=SwNodeOffset(0))
Definition: ndindex.hxx:66
SwNodeIndex & operator=(SwNodeOffset)
Definition: ndindex.hxx:256
SwNode * m_pNode
Definition: ndindex.hxx:32
SwNodeRange(const SwNodeRange &rRange)
Definition: ndindex.hxx:146
SwNodeRange(SwNodes &rNds, SwNodeOffset nSttIdx, SwNodeOffset nEndIdx=SwNodeOffset(0))
Definition: ndindex.hxx:149
SwNodeIndex aStart
Definition: ndindex.hxx:141
SwNodeRange(const SwNodeIndex &rS, const SwNodeIndex &rE)
Definition: ndindex.hxx:144
SwNodeRange(const SwNode &rS, SwNodeOffset nSttDiff, const SwNode &rE, SwNodeOffset nEndDiff=SwNodeOffset(0))
Definition: ndindex.hxx:154
SwNodeRange(const SwNodeIndex &rS, SwNodeOffset nSttDiff, const SwNodeIndex &rE, SwNodeOffset nEndDiff=SwNodeOffset(0))
Definition: ndindex.hxx:152
SwNodeIndex aEnd
Definition: ndindex.hxx:142
Base class of the Writer document model elements.
Definition: node.hxx:83
SwNodeOffset GetIndex() const
Definition: node.hxx:292
SwNodes & GetNodes()
Node is in which nodes-array/doc?
Definition: node.hxx:705
SwNodeIndex * m_vIndices
ring of all indices on nodes.
Definition: ndarr.hxx:97
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:131
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
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)