LibreOffice Module sw (master) 1
contentindex.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#pragma once
20
21#include <sal/types.h>
22#include "swdllapi.h"
23
25
26#include <iostream>
27
28class SwContentNode;
30struct SwPosition;
31class SwRangeRedline;
32
33namespace sw::mark { class IMark; }
34
37{
38private:
39 friend class SwContentIndexReg;
40
41 sal_Int32 m_nIndex;
43 // doubly linked list of Indexes registered at m_pIndexReg
46
48 SwRangeRedline * m_pRangeRedline = nullptr;
49
52
53 SwContentIndex& ChgValue( const SwContentIndex& rIdx, sal_Int32 nNewValue );
54 void Init(sal_Int32 const nIdx);
55 void Remove();
56
57public:
58 explicit SwContentIndex(const SwContentNode * pContentNode, sal_Int32 const nIdx = 0);
60 SwContentIndex( const SwContentIndex &, short nDiff );
62
63 SwContentIndex& operator=( sal_Int32 const );
64 SwContentIndex& operator=( const SwContentIndex & );
65
66 sal_Int32 operator++();
67 sal_Int32 operator--();
68 sal_Int32 operator--(int);
69
70 sal_Int32 operator+=( sal_Int32 const );
71 sal_Int32 operator-=( sal_Int32 const );
72
73 bool operator< ( const SwContentIndex& ) const;
74 bool operator<=( const SwContentIndex& ) const;
75 bool operator> ( const SwContentIndex& ) const;
76 bool operator>=( const SwContentIndex& ) const;
77
78 bool operator< ( sal_Int32 const nVal ) const { return m_nIndex < nVal; }
79 bool operator<=( sal_Int32 const nVal ) const { return m_nIndex <= nVal; }
80 bool operator> ( sal_Int32 const nVal ) const { return m_nIndex > nVal; }
81 bool operator>=( sal_Int32 const nVal ) const { return m_nIndex >= nVal; }
82 bool operator==( sal_Int32 const nVal ) const { return m_nIndex == nVal; }
83 bool operator!=( sal_Int32 const nVal ) const { return m_nIndex != nVal; }
84
85 bool operator==( const SwContentIndex& rSwContentIndex ) const
86 {
87 return (m_nIndex == rSwContentIndex.m_nIndex)
88 && (m_pContentNode == rSwContentIndex.m_pContentNode);
89 }
90
91 bool operator!=( const SwContentIndex& rSwContentIndex ) const
92 {
93 return (m_nIndex != rSwContentIndex.m_nIndex)
94 || (m_pContentNode != rSwContentIndex.m_pContentNode);
95 }
96
97 sal_Int32 GetIndex() const { return m_nIndex; }
98
99 // Assignments without creating a temporary object.
100 SwContentIndex &Assign(const SwContentNode *, sal_Int32);
101
102 // Returns pointer to SwContentNode (for RTTI at SwContentIndexReg).
103 const SwContentNode* GetContentNode() const { return m_pContentNode; }
104 const SwContentIndex* GetNext() const { return m_pNext; }
105
106 const sw::mark::IMark* GetMark() const { return m_pMark; }
107 void SetMark(const sw::mark::IMark* pMark);
108
109 SwRangeRedline* GetRedline() const { return m_pRangeRedline; }
110 void SetRedline(SwRangeRedline* pRangeRedline) { m_pRangeRedline = pRangeRedline; }
111};
112
113SW_DLLPUBLIC std::ostream& operator <<(std::ostream& s, const SwContentIndex& index);
114
117{
118 friend class SwContentIndex;
119
122
123public:
124 enum class UpdateMode {
125 Default = 0,
126 Negative = (1<<0),
127 Delete = (1<<1),
128 Replace = (1<<2),
129 };
130
131protected:
132 virtual void Update( SwContentIndex const & rPos, const sal_Int32 nChangeLen,
133 UpdateMode eMode);
134
135 bool HasAnyIndex() const { return nullptr != m_pFirst; }
136
138public:
139 virtual ~SwContentIndexReg();
140
141 void MoveTo( SwContentNode& rArr );
142 const SwContentIndex* GetFirstIndex() const { return m_pFirst; }
143};
144
145namespace o3tl
146{
147 template<> struct typed_flags<SwContentIndexReg::UpdateMode> : is_typed_flags<SwContentIndexReg::UpdateMode, 0x07> {};
148}
149
150#ifndef DBG_UTIL
151
152inline sal_Int32 SwContentIndex::operator++()
153{
154 return ChgValue( *this, m_nIndex+1 ).m_nIndex;
155}
156
157inline sal_Int32 SwContentIndex::operator--()
158{
159 return ChgValue( *this, m_nIndex-1 ).m_nIndex;
160}
161
162inline sal_Int32 SwContentIndex::operator--(int)
163{
164 sal_Int32 const nOldIndex = m_nIndex;
165 ChgValue( *this, m_nIndex-1 );
166 return nOldIndex;
167}
168
169inline sal_Int32 SwContentIndex::operator+=( sal_Int32 const nVal )
170{
171 return ChgValue( *this, m_nIndex + nVal ).m_nIndex;
172}
173
174inline sal_Int32 SwContentIndex::operator-=( sal_Int32 const nVal )
175{
176 return ChgValue( *this, m_nIndex - nVal ).m_nIndex;
177}
178
179inline bool SwContentIndex::operator< ( const SwContentIndex& rIndex ) const
180{
181 return m_nIndex < rIndex.m_nIndex;
182}
183
184inline bool SwContentIndex::operator<=( const SwContentIndex& rIndex ) const
185{
186 return m_nIndex <= rIndex.m_nIndex;
187}
188
189inline bool SwContentIndex::operator> ( const SwContentIndex& rIndex ) const
190{
191 return m_nIndex > rIndex.m_nIndex;
192}
193
194inline bool SwContentIndex::operator>=( const SwContentIndex& rIndex ) const
195{
196 return m_nIndex >= rIndex.m_nIndex;
197}
198
199inline SwContentIndex& SwContentIndex::operator= ( sal_Int32 const nVal )
200{
201 if (m_nIndex != nVal)
202 {
203 ChgValue( *this, nVal );
204 }
205 return *this;
206}
207
208#endif // ifndef DBG_UTIL
209
210/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
bool operator<=(const BigInt &rVal1, const BigInt &rVal2)
bool operator>=(const BigInt &rVal1, const BigInt &rVal2)
Helper base class for SwContentNode to manage the list of attached SwContentIndex.
bool HasAnyIndex() const
friend class SwContentIndex
const SwContentIndex * GetFirstIndex() const
const SwContentIndex * m_pFirst
const SwContentIndex * m_pLast
Marks a character position inside a document model content node (SwContentNode)
bool operator==(const SwContentIndex &rSwContentIndex) const
sal_Int32 operator+=(sal_Int32 const)
Definition: index.cxx:330
bool operator>(const SwContentIndex &) const
Definition: index.cxx:358
const sw::mark::IMark * m_pMark
Pointer to a mark that owns this position to allow fast lookup of marks of an SwContentIndexReg.
friend class SwContentIndexReg
sal_Int32 operator--()
Definition: index.cxx:323
const SwContentIndex * GetNext() const
SwContentNode * m_pContentNode
sal_Int32 m_nIndex
SwContentIndex & operator=(sal_Int32 const)
Definition: index.cxx:372
bool operator<=(const SwContentIndex &) const
Definition: index.cxx:351
bool operator!=(const SwContentIndex &rSwContentIndex) const
SwContentIndex & ChgValue(const SwContentIndex &rIdx, sal_Int32 nNewValue)
Definition: index.cxx:79
bool operator==(sal_Int32 const nVal) const
sal_Int32 operator++()
Definition: index.cxx:304
SwContentIndex * m_pPrev
bool operator>=(const SwContentIndex &) const
Definition: index.cxx:365
bool operator<(const SwContentIndex &) const
Definition: index.cxx:344
const sw::mark::IMark * GetMark() const
bool operator!=(sal_Int32 const nVal) const
SwContentIndex * m_pNext
sal_Int32 GetIndex() const
const SwContentNode * GetContentNode() const
SwRangeRedline * GetRedline() const
void SetRedline(SwRangeRedline *pRangeRedline)
bool operator<=(sal_Int32 const nVal) const
bool operator>=(sal_Int32 const nVal) const
sal_Int32 operator-=(sal_Int32 const)
Definition: index.cxx:337
void Init()
SW_DLLPUBLIC std::ostream & operator<<(std::ostream &s, const SwContentIndex &index)
Definition: index.cxx:382
SotClipboardFormatId & operator++(SotClipboardFormatId &eFormat)
timeval & operator-=(timeval &t1, const timeval &t2)
Marks a position in the document model.
Definition: pam.hxx:37
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:841