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>
30 namespace sw::mark
{ class IMark
; }
32 /// Marks a character position inside a document model node.
33 class SAL_WARN_UNUSED SW_DLLPUBLIC SwIndex
36 friend class SwIndexReg
;
39 SwIndexReg
* m_pIndexReg
;
40 // doubly linked list of Indexes registered at m_pIndexReg
44 /// Pointer to a mark that owns this position to allow fast lookup of marks of an SwIndexReg.
45 const sw::mark::IMark
* m_pMark
;
47 SwIndex
& ChgValue( const SwIndex
& rIdx
, sal_Int32 nNewValue
);
48 void Init(sal_Int32
const nIdx
);
52 explicit SwIndex(SwIndexReg
*const pReg
, sal_Int32
const nIdx
= 0);
53 SwIndex( const SwIndex
& );
54 SwIndex( const SwIndex
&, short nDiff
);
55 ~SwIndex() { Remove(); }
57 SwIndex
& operator=( sal_Int32
const );
58 SwIndex
& operator=( const SwIndex
& );
60 sal_Int32
operator++();
61 sal_Int32
operator--();
62 sal_Int32
operator--(int);
64 sal_Int32
operator+=( sal_Int32
const );
65 sal_Int32
operator-=( sal_Int32
const );
67 bool operator< ( const SwIndex
& ) const;
68 bool operator<=( const SwIndex
& ) const;
69 bool operator> ( const SwIndex
& ) const;
70 bool operator>=( const SwIndex
& ) const;
72 bool operator< ( sal_Int32
const nVal
) const { return m_nIndex
< nVal
; }
73 bool operator<=( sal_Int32
const nVal
) const { return m_nIndex
<= nVal
; }
74 bool operator> ( sal_Int32
const nVal
) const { return m_nIndex
> nVal
; }
75 bool operator>=( sal_Int32
const nVal
) const { return m_nIndex
>= nVal
; }
76 bool operator==( sal_Int32
const nVal
) const { return m_nIndex
== nVal
; }
77 bool operator!=( sal_Int32
const nVal
) const { return m_nIndex
!= nVal
; }
79 bool operator==( const SwIndex
& rSwIndex
) const
81 return (m_nIndex
== rSwIndex
.m_nIndex
)
82 && (m_pIndexReg
== rSwIndex
.m_pIndexReg
);
85 bool operator!=( const SwIndex
& rSwIndex
) const
87 return (m_nIndex
!= rSwIndex
.m_nIndex
)
88 || (m_pIndexReg
!= rSwIndex
.m_pIndexReg
);
91 sal_Int32
GetIndex() const { return m_nIndex
; }
93 // Assignments without creating a temporary object.
94 SwIndex
&Assign(SwIndexReg
*, sal_Int32
);
96 // Returns pointer to IndexArray (for RTTI at SwIndexReg).
97 const SwIndexReg
* GetIdxReg() const { return m_pIndexReg
; }
98 const SwIndex
* GetNext() const { return m_pNext
; }
100 const sw::mark::IMark
* GetMark() const { return m_pMark
; }
101 void SetMark(const sw::mark::IMark
* pMark
);
104 SW_DLLPUBLIC
std::ostream
& operator <<(std::ostream
& s
, const SwIndex
& index
);
106 class SAL_WARN_UNUSED SwIndexReg
108 friend class SwIndex
;
109 friend bool sw_PosOk(const SwPosition
& aPos
);
111 const SwIndex
* m_pFirst
;
112 const SwIndex
* m_pLast
;
115 virtual void Update( SwIndex
const & rPos
, const sal_Int32 nChangeLen
,
116 const bool bNegative
= false, const bool bDelete
= false );
118 bool HasAnyIndex() const { return nullptr != m_pFirst
; }
122 virtual ~SwIndexReg();
124 void MoveTo( SwIndexReg
& rArr
);
125 const SwIndex
* GetFirstIndex() const { return m_pFirst
; }
130 inline sal_Int32
SwIndex::operator++()
132 return ChgValue( *this, m_nIndex
+1 ).m_nIndex
;
135 inline sal_Int32
SwIndex::operator--()
137 return ChgValue( *this, m_nIndex
-1 ).m_nIndex
;
140 inline sal_Int32
SwIndex::operator--(int)
142 sal_Int32
const nOldIndex
= m_nIndex
;
143 ChgValue( *this, m_nIndex
-1 );
147 inline sal_Int32
SwIndex::operator+=( sal_Int32
const nVal
)
149 return ChgValue( *this, m_nIndex
+ nVal
).m_nIndex
;
152 inline sal_Int32
SwIndex::operator-=( sal_Int32
const nVal
)
154 return ChgValue( *this, m_nIndex
- nVal
).m_nIndex
;
157 inline bool SwIndex::operator< ( const SwIndex
& rIndex
) const
159 return m_nIndex
< rIndex
.m_nIndex
;
162 inline bool SwIndex::operator<=( const SwIndex
& rIndex
) const
164 return m_nIndex
<= rIndex
.m_nIndex
;
167 inline bool SwIndex::operator> ( const SwIndex
& rIndex
) const
169 return m_nIndex
> rIndex
.m_nIndex
;
172 inline bool SwIndex::operator>=( const SwIndex
& rIndex
) const
174 return m_nIndex
>= rIndex
.m_nIndex
;
177 inline SwIndex
& SwIndex::operator= ( sal_Int32
const nVal
)
179 if (m_nIndex
!= nVal
)
181 ChgValue( *this, nVal
);
186 #endif // ifndef DBG_UTIL
190 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */