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 
119  SwNode& GetNode() const { return *m_pNode; }
120 };
121 
122 inline std::ostream &operator <<(std::ostream& s, const SwNodeIndex& index)
123 {
124  return s << "SwNodeIndex (node " << index.GetIndex() << ")";
125 };
126 
127 // SwRange
128 
130 {
131 public:
134 
135  SwNodeRange( const SwNodeIndex &rS, const SwNodeIndex &rE )
136  : aStart( rS ), aEnd( rE ) {};
137  SwNodeRange( const SwNodeRange &rRange )
138  : aStart( rRange.aStart ), aEnd( rRange.aEnd ) {};
139 
140  SwNodeRange( SwNodes& rNds, sal_uLong nSttIdx, sal_uLong nEndIdx = 0 )
141  : aStart( rNds, nSttIdx ), aEnd( rNds, nEndIdx ) {};
142 
143  SwNodeRange( const SwNodeIndex& rS, long nSttDiff, const SwNodeIndex& rE, long nEndDiff = 0 )
144  : aStart( rS, nSttDiff ), aEnd( rE, nEndDiff ) {};
145  SwNodeRange( const SwNode& rS, long nSttDiff, const SwNode& rE, long nEndDiff = 0 )
146  : aStart( rS, nSttDiff ), aEnd( rE, nEndDiff ) {};
147 };
148 
149 // For inlines node.hxx is needed which in turn needs this one.
150 // Therefore all inlines accessing m_pNode are implemented here.
151 
153 {
154  return m_pNode->GetIndex();
155 }
156 inline const SwNodes& SwNodeIndex::GetNodes() const
157 {
158  return m_pNode->GetNodes();
159 }
161 {
162  return m_pNode->GetNodes();
163 }
164 inline bool SwNodeIndex::operator< ( sal_uLong const nOther ) const
165 {
166  return m_pNode->GetIndex() < nOther;
167 }
168 inline bool SwNodeIndex::operator<=( sal_uLong const nOther ) const
169 {
170  return m_pNode->GetIndex() <= nOther;
171 }
172 inline bool SwNodeIndex::operator> ( sal_uLong const nOther ) const
173 {
174  return m_pNode->GetIndex() > nOther;
175 }
176 inline bool SwNodeIndex::operator>=( sal_uLong const nOther ) const
177 {
178  return m_pNode->GetIndex() >= nOther;
179 }
180 inline bool SwNodeIndex::operator==( sal_uLong const nOther ) const
181 {
182  return m_pNode->GetIndex() == nOther;
183 }
184 inline bool SwNodeIndex::operator!=( sal_uLong const nOther ) const
185 {
186  return m_pNode->GetIndex() != nOther;
187 }
188 inline bool SwNodeIndex::operator<( const SwNodeIndex& rIndex ) const
189 {
190  return m_pNode->GetIndex() < rIndex.GetIndex();
191 }
192 inline bool SwNodeIndex::operator<=( const SwNodeIndex& rIndex ) const
193 {
194  return m_pNode->GetIndex() <= rIndex.GetIndex();
195 }
196 inline bool SwNodeIndex::operator>( const SwNodeIndex& rIndex ) const
197 {
198  return m_pNode->GetIndex() > rIndex.GetIndex();
199 }
200 inline bool SwNodeIndex::operator>=( const SwNodeIndex& rIndex ) const
201 {
202  return m_pNode->GetIndex() >= rIndex.GetIndex();
203 }
204 inline bool SwNodeIndex::operator==( const SwNodeIndex& rIdx ) const
205 {
206  return m_pNode == rIdx.m_pNode;
207 }
208 inline bool SwNodeIndex::operator!=( const SwNodeIndex& rIdx ) const
209 {
210  return m_pNode != rIdx.m_pNode;
211 }
212 
214 {
215  m_pNode = GetNodes()[ m_pNode->GetIndex()+1 ];
216  return m_pNode->GetIndex();
217 }
219 {
220  m_pNode = GetNodes()[ m_pNode->GetIndex()-1 ];
221  return m_pNode->GetIndex();
222 }
224 {
225  sal_uLong nOldIndex = m_pNode->GetIndex();
226  m_pNode = GetNodes()[ nOldIndex + 1 ];
227  return nOldIndex;
228 }
230 {
231  sal_uLong nOldIndex = m_pNode->GetIndex();
232  m_pNode = GetNodes()[ nOldIndex - 1 ];
233  return nOldIndex;
234 }
235 
237 {
238  m_pNode = GetNodes()[ m_pNode->GetIndex() + nOffset ];
239  return m_pNode->GetIndex();
240 }
242 {
243  m_pNode = GetNodes()[ m_pNode->GetIndex() - nOffset ];
244  return m_pNode->GetIndex();
245 }
246 
248 {
249  m_pNode = GetNodes()[ nNew ];
250  return *this;
251 }
252 
254 {
255  *this = *(rIdx.m_pNode);
256  return *this;
257 }
258 
260 {
261  if (&m_pNode->GetNodes() != &rNd.GetNodes())
262  {
264  m_pNode = const_cast<SwNode*>(&rNd);
265  RegisterIndex( m_pNode->GetNodes() );
266  }
267  else
268  m_pNode = const_cast<SwNode*>(&rNd);
269  return *this;
270 }
271 
273 {
274  *this = *rNds[ nIdx ];
275  return *this;
276 }
277 
278 SwNodeIndex& SwNodeIndex::Assign( const SwNode& rNd, long nOffset )
279 {
280  *this = rNd;
281 
282  if( nOffset )
283  m_pNode = m_pNode->GetNodes()[ m_pNode->GetIndex() + nOffset ];
284 
285  return *this;
286 }
287 
288 #endif
289 
290 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
sal_uLong operator--()
Definition: ndindex.hxx:218
sal_uLong GetIndex() const
Definition: node.hxx:282
bool operator<(const SwTextGlyphsKey &l, const SwTextGlyphsKey &r)
Definition: fntcache.cxx:132
bool operator>=(const BigInt &rVal1, const BigInt &rVal2)
SwNodeRange(const SwNodeRange &rRange)
Definition: ndindex.hxx:137
sal_uIntPtr sal_uLong
std::ostream & operator<<(std::ostream &s, const SwNodeIndex &index)
Definition: ndindex.hxx:122
bool operator>=(const SwNodeIndex &) const
Definition: ndindex.hxx:200
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:119
SwNodeIndex * GetNext()
Definition: ndindex.hxx:118
bool operator<=(const BigInt &rVal1, const BigInt &rVal2)
Dialog to specify the properties of date form field.
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:192
SwNodeIndex aStart
Definition: ndindex.hxx:132
sal_uLong GetIndex() const
Definition: ndindex.hxx:152
bool operator!=(const SwNodeIndex &) const
Definition: ndindex.hxx:208
SwNodeIndex & operator=(sal_uLong)
Definition: ndindex.hxx:247
SwNode * m_pNode
Definition: ndindex.hxx:33
value_type * GetNextInRing()
Definition: ring.hxx:84
sal_uLong operator-=(sal_uLong)
Definition: ndindex.hxx:241
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:143
#define SW_DLLPUBLIC
Definition: swdllapi.h:28
SwNodeRange(const SwNodeIndex &rS, const SwNodeIndex &rE)
Definition: ndindex.hxx:135
bool operator>(const SwNodeIndex &) const
Definition: ndindex.hxx:196
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:145
const SwNodes & GetNodes() const
Definition: ndindex.hxx:156
sal_uLong operator++()
Definition: ndindex.hxx:213
SwNodeIndex aEnd
Definition: ndindex.hxx:133
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:236
bool operator<(const SwNodeIndex &) const
Definition: ndindex.hxx:188
SwNodeRange(SwNodes &rNds, sal_uLong nSttIdx, sal_uLong nEndIdx=0)
Definition: ndindex.hxx:140
bool operator==(const ScCsvLayoutData &rData1, const ScCsvLayoutData &rData2)
bool operator==(const SwNodeIndex &) const
Definition: ndindex.hxx:204
void DeRegisterIndex(SwNodes &rNodes)
Definition: ndindex.hxx:44
SwNodeIndex & Assign(SwNodes const &rNds, sal_uLong)
Definition: ndindex.hxx:272
Base class of the Writer document model elements.
Definition: node.hxx:79