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