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