1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
21 #include <sal/types.h>
24 #include <o3tl/typed_flags_set.hxx>
29 class SwContentIndexReg
;
33 namespace sw::mark
{ class IMark
; }
35 /// Marks a character position inside a document model content node (SwContentNode)
36 class SAL_WARN_UNUSED SW_DLLPUBLIC SwContentIndex
39 friend class SwContentIndexReg
;
42 SwContentNode
* m_pContentNode
;
43 // doubly linked list of Indexes registered at m_pIndexReg
44 SwContentIndex
* m_pNext
;
45 SwContentIndex
* m_pPrev
;
47 /// points to the SwRangeRedline (if any) that contains this SwIndex, via SwPosition and SwPaM
48 SwRangeRedline
* m_pRangeRedline
= nullptr;
50 /// Pointer to a mark that owns this position to allow fast lookup of marks of an SwContentIndexReg.
51 const sw::mark::IMark
* m_pMark
;
53 SwContentIndex
& ChgValue( const SwContentIndex
& rIdx
, sal_Int32 nNewValue
);
54 void Init(sal_Int32
const nIdx
);
58 explicit SwContentIndex(const SwContentNode
* pContentNode
, sal_Int32
const nIdx
= 0);
59 SwContentIndex( const SwContentIndex
& );
60 SwContentIndex( const SwContentIndex
&, short nDiff
);
61 ~SwContentIndex() { Remove(); }
63 SwContentIndex
& operator=( sal_Int32
const );
64 SwContentIndex
& operator=( const SwContentIndex
& );
66 sal_Int32
operator++();
67 sal_Int32
operator--();
68 sal_Int32
operator--(int);
70 sal_Int32
operator+=( sal_Int32
const );
71 sal_Int32
operator-=( sal_Int32
const );
73 bool operator< ( const SwContentIndex
& ) const;
74 bool operator<=( const SwContentIndex
& ) const;
75 bool operator> ( const SwContentIndex
& ) const;
76 bool operator>=( const SwContentIndex
& ) const;
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
; }
85 bool operator==( const SwContentIndex
& rSwContentIndex
) const
87 return (m_nIndex
== rSwContentIndex
.m_nIndex
)
88 && (m_pContentNode
== rSwContentIndex
.m_pContentNode
);
91 bool operator!=( const SwContentIndex
& rSwContentIndex
) const
93 return (m_nIndex
!= rSwContentIndex
.m_nIndex
)
94 || (m_pContentNode
!= rSwContentIndex
.m_pContentNode
);
97 sal_Int32
GetIndex() const { return m_nIndex
; }
99 // Assignments without creating a temporary object.
100 SwContentIndex
&Assign(const SwContentNode
*, sal_Int32
);
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
; }
106 const sw::mark::IMark
* GetMark() const { return m_pMark
; }
107 void SetMark(const sw::mark::IMark
* pMark
);
109 SwRangeRedline
* GetRedline() const { return m_pRangeRedline
; }
110 void SetRedline(SwRangeRedline
* pRangeRedline
) { m_pRangeRedline
= pRangeRedline
; }
113 SW_DLLPUBLIC
std::ostream
& operator <<(std::ostream
& s
, const SwContentIndex
& index
);
115 /// Helper base class for SwContentNode to manage the list of attached SwContentIndex
116 class SAL_WARN_UNUSED
SAL_LOPLUGIN_ANNOTATE("crosscast") SwContentIndexReg
118 friend class SwContentIndex
;
120 const SwContentIndex
* m_pFirst
;
121 const SwContentIndex
* m_pLast
;
124 enum class UpdateMode
{
132 virtual void Update( SwContentIndex
const & rPos
, const sal_Int32 nChangeLen
,
135 bool HasAnyIndex() const { return nullptr != m_pFirst
; }
139 virtual ~SwContentIndexReg();
141 void MoveTo( SwContentNode
& rArr
);
142 const SwContentIndex
* GetFirstIndex() const { return m_pFirst
; }
147 template<> struct typed_flags
<SwContentIndexReg::UpdateMode
> : is_typed_flags
<SwContentIndexReg::UpdateMode
, 0x07> {};
152 inline sal_Int32
SwContentIndex::operator++()
154 return ChgValue( *this, m_nIndex
+1 ).m_nIndex
;
157 inline sal_Int32
SwContentIndex::operator--()
159 return ChgValue( *this, m_nIndex
-1 ).m_nIndex
;
162 inline sal_Int32
SwContentIndex::operator--(int)
164 sal_Int32
const nOldIndex
= m_nIndex
;
165 ChgValue( *this, m_nIndex
-1 );
169 inline sal_Int32
SwContentIndex::operator+=( sal_Int32
const nVal
)
171 return ChgValue( *this, m_nIndex
+ nVal
).m_nIndex
;
174 inline sal_Int32
SwContentIndex::operator-=( sal_Int32
const nVal
)
176 return ChgValue( *this, m_nIndex
- nVal
).m_nIndex
;
179 inline bool SwContentIndex::operator< ( const SwContentIndex
& rIndex
) const
181 return m_nIndex
< rIndex
.m_nIndex
;
184 inline bool SwContentIndex::operator<=( const SwContentIndex
& rIndex
) const
186 return m_nIndex
<= rIndex
.m_nIndex
;
189 inline bool SwContentIndex::operator> ( const SwContentIndex
& rIndex
) const
191 return m_nIndex
> rIndex
.m_nIndex
;
194 inline bool SwContentIndex::operator>=( const SwContentIndex
& rIndex
) const
196 return m_nIndex
>= rIndex
.m_nIndex
;
199 inline SwContentIndex
& SwContentIndex::operator= ( sal_Int32
const nVal
)
201 if (m_nIndex
!= nVal
)
203 ChgValue( *this, nVal
);
208 #endif // ifndef DBG_UTIL
210 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */