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 .
19 #ifndef INCLUDED_SW_INC_INDEX_HXX
20 #define INCLUDED_SW_INC_INDEX_HXX
22 #include <sal/types.h>
25 #include <o3tl/typed_flags_set.hxx>
38 /// Marks a character position inside a document model node.
39 class SAL_WARN_UNUSED SW_DLLPUBLIC SwIndex
42 friend class SwIndexReg
;
45 SwIndexReg
* m_pIndexReg
;
46 // doubly linked list of Indexes registered at m_pIndexReg
50 /// Pointer to a mark that owns this position to allow fast lookup of marks of an SwIndexReg.
51 const sw::mark::IMark
* m_pMark
;
53 SwIndex
& ChgValue( const SwIndex
& rIdx
, sal_Int32 nNewValue
);
54 void Init(sal_Int32
const nIdx
);
58 explicit SwIndex(SwIndexReg
*const pReg
, sal_Int32
const nIdx
= 0);
59 SwIndex( const SwIndex
& );
60 SwIndex( const SwIndex
&, short nDiff
);
61 ~SwIndex() { Remove(); }
63 SwIndex
& operator=( sal_Int32
const );
64 SwIndex
& operator=( const SwIndex
& );
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 SwIndex
& ) const;
74 bool operator<=( const SwIndex
& ) const;
75 bool operator> ( const SwIndex
& ) const;
76 bool operator>=( const SwIndex
& ) 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 SwIndex
& rSwIndex
) const
87 return (m_nIndex
== rSwIndex
.m_nIndex
)
88 && (m_pIndexReg
== rSwIndex
.m_pIndexReg
);
91 bool operator!=( const SwIndex
& rSwIndex
) const
93 return (m_nIndex
!= rSwIndex
.m_nIndex
)
94 || (m_pIndexReg
!= rSwIndex
.m_pIndexReg
);
97 sal_Int32
GetIndex() const { return m_nIndex
; }
99 // Assignments without creating a temporary object.
100 SwIndex
&Assign(SwIndexReg
*, sal_Int32
);
102 // Returns pointer to IndexArray (for RTTI at SwIndexReg).
103 const SwIndexReg
* GetIdxReg() const { return m_pIndexReg
; }
104 const SwIndex
* GetNext() const { return m_pNext
; }
106 const sw::mark::IMark
* GetMark() const { return m_pMark
; }
107 void SetMark(const sw::mark::IMark
* pMark
);
110 SW_DLLPUBLIC
std::ostream
& operator <<(std::ostream
& s
, const SwIndex
& index
);
112 class SAL_WARN_UNUSED SwIndexReg
114 friend class SwIndex
;
115 friend bool sw_PosOk(const SwPosition
& aPos
);
117 const SwIndex
* m_pFirst
;
118 const SwIndex
* m_pLast
;
121 enum class UpdateMode
{
129 virtual void Update( SwIndex
const & rPos
, const sal_Int32 nChangeLen
,
132 bool HasAnyIndex() const { return nullptr != m_pFirst
; }
136 virtual ~SwIndexReg();
138 void MoveTo( SwIndexReg
& rArr
);
139 const SwIndex
* GetFirstIndex() const { return m_pFirst
; }
144 template<> struct typed_flags
<SwIndexReg::UpdateMode
> : is_typed_flags
<SwIndexReg::UpdateMode
, 0x07> {};
149 inline sal_Int32
SwIndex::operator++()
151 return ChgValue( *this, m_nIndex
+1 ).m_nIndex
;
154 inline sal_Int32
SwIndex::operator--()
156 return ChgValue( *this, m_nIndex
-1 ).m_nIndex
;
159 inline sal_Int32
SwIndex::operator--(int)
161 sal_Int32
const nOldIndex
= m_nIndex
;
162 ChgValue( *this, m_nIndex
-1 );
166 inline sal_Int32
SwIndex::operator+=( sal_Int32
const nVal
)
168 return ChgValue( *this, m_nIndex
+ nVal
).m_nIndex
;
171 inline sal_Int32
SwIndex::operator-=( sal_Int32
const nVal
)
173 return ChgValue( *this, m_nIndex
- nVal
).m_nIndex
;
176 inline bool SwIndex::operator< ( const SwIndex
& rIndex
) const
178 return m_nIndex
< rIndex
.m_nIndex
;
181 inline bool SwIndex::operator<=( const SwIndex
& rIndex
) const
183 return m_nIndex
<= rIndex
.m_nIndex
;
186 inline bool SwIndex::operator> ( const SwIndex
& rIndex
) const
188 return m_nIndex
> rIndex
.m_nIndex
;
191 inline bool SwIndex::operator>=( const SwIndex
& rIndex
) const
193 return m_nIndex
>= rIndex
.m_nIndex
;
196 inline SwIndex
& SwIndex::operator= ( sal_Int32
const nVal
)
198 if (m_nIndex
!= nVal
)
200 ChgValue( *this, nVal
);
205 #endif // ifndef DBG_UTIL
209 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */