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
35 {
36 SwNodes& rNodes = GetNodes();
37 if(!rNodes.m_vIndices)
38 {
39#if defined(__GNUC__) && (__GNUC__ == 12 || __GNUC__ == 13)
40#pragma GCC diagnostic push
41#pragma GCC diagnostic ignored "-Wdangling-pointer"
42#endif
43 rNodes.m_vIndices = this;
44#if defined(__GNUC__) && (__GNUC__ == 12 || __GNUC__ == 13)
45#pragma GCC diagnostic pop
46#endif
47 }
48 MoveTo(rNodes.m_vIndices);
49 }
51 {
52 SwNodes& rNodes = GetNodes();
53 if(rNodes.m_vIndices == this)
54 rNodes.m_vIndices = GetNextInRing();
55 MoveTo(nullptr);
56 if(rNodes.m_vIndices == this)
57 rNodes.m_vIndices = nullptr;
58 }
59
60 SwNodeIndex(SwNode* pNode) : m_pNode(pNode) { RegisterIndex(); }
61
62public:
63 SwNodeIndex( SwNodes& rNds, sal_Int32 nIdx ) : SwNodeIndex(rNds, SwNodeOffset(nIdx)) {}
64 explicit SwNodeIndex( SwNodes& rNds, SwNodeOffset nIdx = SwNodeOffset(0) )
65 : SwNodeIndex( rNds[ nIdx ] ) {}
66
67 SwNodeIndex( const SwNodeIndex& rIdx, sal_Int32 nDiff ) : SwNodeIndex(rIdx, SwNodeOffset(nDiff)) {}
69 : SwNodeIndex( nDiff ? rIdx.GetNodes()[ rIdx.GetIndex() + nDiff ] : rIdx.m_pNode ) {}
70
71 SwNodeIndex( const SwNode& rNd, sal_Int32 nDiff ) : SwNodeIndex(rNd, SwNodeOffset(nDiff)) {}
72 explicit SwNodeIndex( const SwNode& rNd )
73 : SwNodeIndex( const_cast<SwNode*>(&rNd) ) {}
74 explicit SwNodeIndex( const SwNode& rNd, SwNodeOffset nDiff )
75 : SwNodeIndex( nDiff ? *rNd.GetNodes()[ rNd.GetIndex() + nDiff ] : rNd ) {}
76
77 virtual ~SwNodeIndex() override { DeRegisterIndex(); }
78
81
82 SwNodeIndex& operator+=( SwNodeOffset nOffset ) { return operator=(GetIndex() + nOffset); }
83 SwNodeIndex& operator-=( SwNodeOffset nOffset ) { return operator=(GetIndex() - nOffset); }
84
85 bool operator<( const SwNodeIndex& rIndex ) const { return operator<(rIndex.GetNode()); }
86 bool operator<=( const SwNodeIndex& rIndex ) const { return operator<=(rIndex.GetNode()); }
87 bool operator>( const SwNodeIndex& rIndex ) const { return operator>(rIndex.GetNode()); }
88 bool operator>=( const SwNodeIndex& rIndex ) const { return operator>=(rIndex.GetNode()); }
89 bool operator==( const SwNodeIndex& rIndex ) const { return operator==(rIndex.GetNode()); }
90 bool operator!=( const SwNodeIndex& rIndex ) const { return operator!=(rIndex.GetNode()); }
91
92 bool operator<( SwNodeOffset nOther ) const { return GetIndex() < nOther; }
93 bool operator<=( SwNodeOffset nOther ) const { return GetIndex() <= nOther; }
94 bool operator>( SwNodeOffset nOther ) const { return GetIndex() > nOther; }
95 bool operator>=( SwNodeOffset nOther ) const { return GetIndex() >= nOther; }
96 bool operator==( SwNodeOffset nOther ) const { return GetIndex() == nOther; }
97 bool operator!=( SwNodeOffset nOther ) const { return GetIndex() != nOther; }
98
99 bool operator<( const SwNode& rNd ) const { assert(&GetNodes() == &rNd.GetNodes()); return operator<(rNd.GetIndex()); }
100 bool operator<=( const SwNode& rNd ) const { return operator==(rNd) || operator<(rNd); }
101 bool operator>( const SwNode& rNd ) const { assert(&GetNodes() == &rNd.GetNodes()); return operator>(rNd.GetIndex()); }
102 bool operator>=( const SwNode& rNd ) const { return operator==(rNd) || operator>(rNd); }
103 bool operator==( const SwNode& rNd ) const { return m_pNode == &rNd; }
104 bool operator!=( const SwNode& rNd ) const { return m_pNode != &rNd; }
105
106 inline SwNodeIndex& operator=( SwNodeOffset );
107 SwNodeIndex& operator=( const SwNodeIndex& rIdx ) { return operator=(*rIdx.m_pNode); }
108 inline SwNodeIndex& operator=( const SwNode& );
109
110 // Return value of index as SwNodeOffset.
111 SwNodeOffset GetIndex() const { return m_pNode->GetIndex(); }
112
113 // Enables assignments without creation of a temporary object.
114 SwNodeIndex& Assign( SwNodes const & rNds, SwNodeOffset nIdx ) { return operator=(*rNds[nIdx]); }
115 SwNodeIndex& Assign( const SwNode& rNd, sal_Int32 nOffset ) { return Assign(rNd, SwNodeOffset(nOffset)); }
116 inline SwNodeIndex& Assign( const SwNode& rNd, SwNodeOffset nOffset = SwNodeOffset(0) );
117
118 // Gets pointer on NodesArray.
119 const SwNodes& GetNodes() const { return m_pNode->GetNodes(); }
120 SwNodes& GetNodes() { return m_pNode->GetNodes(); }
121
122 const SwNodeIndex* GetNext() const { return GetNextInRing(); }
123 SwNode& GetNode() const { return *m_pNode; }
124};
125
126inline std::ostream &operator <<(std::ostream& s, const SwNodeIndex& index)
127{
128 return s << "SwNodeIndex (node " << sal_Int32(index.GetIndex()) << ")";
129}
130
131// SwRange
132
134{
135public:
138
139 SwNodeRange( const SwNodeIndex &rS, const SwNodeIndex &rE )
140 : aStart( rS ), aEnd( rE ) {}
141 SwNodeRange( const SwNode &rS, const SwNode &rE )
142 : aStart( rS ), aEnd( rE ) {}
143 SwNodeRange( const SwNodeRange &rRange ) = default;
144
146 : aStart( rNds, nSttIdx ), aEnd( rNds, nEndIdx ) {}
147
148 SwNodeRange( const SwNodeIndex& rS, SwNodeOffset nSttDiff, const SwNodeIndex& rE, SwNodeOffset nEndDiff = SwNodeOffset(0) )
149 : aStart( rS, nSttDiff ), aEnd( rE, nEndDiff ) {}
150 SwNodeRange( const SwNode& rS, SwNodeOffset nSttDiff, const SwNode& rE, SwNodeOffset nEndDiff = SwNodeOffset(0) )
151 : aStart( rS, nSttDiff ), aEnd( rE, nEndDiff ) {}
152};
153
154// For inlines node.hxx is needed which in turn needs this one.
155// Therefore all inlines accessing m_pNode are implemented here.
156
158{
159 m_pNode = GetNodes()[ nNew ];
160 return *this;
161}
162
164{
165 if (&GetNodes() != &rNd.GetNodes())
166 {
168 m_pNode = const_cast<SwNode*>(&rNd);
170 }
171 else
172 m_pNode = const_cast<SwNode*>(&rNd);
173 return *this;
174}
175
177{
178 *this = rNd;
179
180 if( nOffset )
181 m_pNode = GetNodes()[ GetIndex() + nOffset ];
182
183 return *this;
184}
185
186#endif
187
188/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Marks a node in the document model.
Definition: ndindex.hxx:31
bool operator==(SwNodeOffset nOther) const
Definition: ndindex.hxx:96
bool operator==(const SwNode &rNd) const
Definition: ndindex.hxx:103
bool operator<(const SwNodeIndex &rIndex) const
Definition: ndindex.hxx:85
bool operator!=(const SwNode &rNd) const
Definition: ndindex.hxx:104
bool operator>(const SwNode &rNd) const
Definition: ndindex.hxx:101
SwNodeIndex(SwNode *pNode)
Definition: ndindex.hxx:60
SwNodeIndex & operator-=(SwNodeOffset nOffset)
Definition: ndindex.hxx:83
bool operator<(SwNodeOffset nOther) const
Definition: ndindex.hxx:92
bool operator<=(const SwNodeIndex &rIndex) const
Definition: ndindex.hxx:86
bool operator>(SwNodeOffset nOther) const
Definition: ndindex.hxx:94
const SwNodes & GetNodes() const
Definition: ndindex.hxx:119
bool operator>=(const SwNode &rNd) const
Definition: ndindex.hxx:102
SwNodeIndex & operator=(const SwNodeIndex &rIdx)
Definition: ndindex.hxx:107
SwNodeIndex(const SwNode &rNd, sal_Int32 nDiff)
Definition: ndindex.hxx:71
bool operator!=(const SwNodeIndex &rIndex) const
Definition: ndindex.hxx:90
SwNodeIndex & operator--()
Definition: ndindex.hxx:80
bool operator==(const SwNodeIndex &rIndex) const
Definition: ndindex.hxx:89
SwNodeIndex(const SwNodeIndex &rIdx, sal_Int32 nDiff)
Definition: ndindex.hxx:67
SwNodeIndex & operator+=(SwNodeOffset nOffset)
Definition: ndindex.hxx:82
SwNodeIndex(const SwNode &rNd, SwNodeOffset nDiff)
Definition: ndindex.hxx:74
SwNodes & GetNodes()
Definition: ndindex.hxx:120
bool operator!=(SwNodeOffset nOther) const
Definition: ndindex.hxx:97
bool operator<(const SwNode &rNd) const
Definition: ndindex.hxx:99
SwNode & GetNode() const
Definition: ndindex.hxx:123
void DeRegisterIndex()
Definition: ndindex.hxx:50
bool operator>=(const SwNodeIndex &rIndex) const
Definition: ndindex.hxx:88
virtual ~SwNodeIndex() override
Definition: ndindex.hxx:77
SwNodeIndex & operator++()
Definition: ndindex.hxx:79
SwNodeIndex & Assign(const SwNode &rNd, sal_Int32 nOffset)
Definition: ndindex.hxx:115
SwNodeOffset GetIndex() const
Definition: ndindex.hxx:111
bool operator<=(SwNodeOffset nOther) const
Definition: ndindex.hxx:93
bool operator>=(SwNodeOffset nOther) const
Definition: ndindex.hxx:95
bool operator<=(const SwNode &rNd) const
Definition: ndindex.hxx:100
SwNodeIndex(const SwNode &rNd)
Definition: ndindex.hxx:72
SwNodeIndex(SwNodes &rNds, sal_Int32 nIdx)
Definition: ndindex.hxx:63
SwNodeIndex(SwNodes &rNds, SwNodeOffset nIdx=SwNodeOffset(0))
Definition: ndindex.hxx:64
SwNodeIndex(const SwNodeIndex &rIdx, SwNodeOffset nDiff=SwNodeOffset(0))
Definition: ndindex.hxx:68
bool operator>(const SwNodeIndex &rIndex) const
Definition: ndindex.hxx:87
const SwNodeIndex * GetNext() const
Definition: ndindex.hxx:122
SwNodeIndex & Assign(SwNodes const &rNds, SwNodeOffset nIdx)
Definition: ndindex.hxx:114
SwNodeIndex & operator=(SwNodeOffset)
Definition: ndindex.hxx:157
SwNode * m_pNode
Definition: ndindex.hxx:32
void RegisterIndex()
Definition: ndindex.hxx:34
SwNodeRange(const SwNodeRange &rRange)=default
SwNodeRange(SwNodes &rNds, SwNodeOffset nSttIdx, SwNodeOffset nEndIdx=SwNodeOffset(0))
Definition: ndindex.hxx:145
SwNodeIndex aStart
Definition: ndindex.hxx:136
SwNodeRange(const SwNodeIndex &rS, const SwNodeIndex &rE)
Definition: ndindex.hxx:139
SwNodeRange(const SwNode &rS, SwNodeOffset nSttDiff, const SwNode &rE, SwNodeOffset nEndDiff=SwNodeOffset(0))
Definition: ndindex.hxx:150
SwNodeRange(const SwNode &rS, const SwNode &rE)
Definition: ndindex.hxx:141
SwNodeRange(const SwNodeIndex &rS, SwNodeOffset nSttDiff, const SwNodeIndex &rE, SwNodeOffset nEndDiff=SwNodeOffset(0))
Definition: ndindex.hxx:148
SwNodeIndex aEnd
Definition: ndindex.hxx:137
Base class of the Writer document model elements.
Definition: node.hxx:98
SwNodeOffset GetIndex() const
Definition: node.hxx:312
SwNodes & GetNodes()
Node is in which nodes-array/doc?
Definition: node.hxx:706
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
index
bool operator>(const Style &rL, const Style &rR)
std::ostream & operator<<(std::ostream &s, const SwNodeIndex &index)
Definition: ndindex.hxx:126
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:885
bool operator==(const XclFontData &rLeft, const XclFontData &rRight)