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>
36 /// Marks a character position inside a document model node.
37 class SAL_WARN_UNUSED SW_DLLPUBLIC SwIndex
40 friend class SwIndexReg
;
43 SwIndexReg
* m_pIndexReg
;
44 // doubly linked list of Indexes registered at m_pIndexReg
48 /// Pointer to a mark that owns this position to allow fast lookup of marks of an SwIndexReg.
49 const sw::mark::IMark
* m_pMark
;
51 SwIndex
& ChgValue( const SwIndex
& rIdx
, sal_Int32 nNewValue
);
52 void Init(sal_Int32
const nIdx
);
56 explicit SwIndex(SwIndexReg
*const pReg
, sal_Int32
const nIdx
= 0);
57 SwIndex( const SwIndex
& );
58 SwIndex( const SwIndex
&, short nDiff
);
59 ~SwIndex() { Remove(); }
61 SwIndex
& operator=( sal_Int32
const );
62 SwIndex
& operator=( const SwIndex
& );
64 sal_Int32
operator++();
65 sal_Int32
operator--();
66 sal_Int32
operator--(int);
68 sal_Int32
operator+=( sal_Int32
const );
69 sal_Int32
operator-=( sal_Int32
const );
71 bool operator< ( const SwIndex
& ) const;
72 bool operator<=( const SwIndex
& ) const;
73 bool operator> ( const SwIndex
& ) const;
74 bool operator>=( const SwIndex
& ) const;
76 bool operator< ( sal_Int32
const nVal
) const { return m_nIndex
< nVal
; }
77 bool operator<=( sal_Int32
const nVal
) const { return m_nIndex
<= nVal
; }
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
; }
83 bool operator==( const SwIndex
& rSwIndex
) const
85 return (m_nIndex
== rSwIndex
.m_nIndex
)
86 && (m_pIndexReg
== rSwIndex
.m_pIndexReg
);
89 bool operator!=( const SwIndex
& rSwIndex
) const
91 return (m_nIndex
!= rSwIndex
.m_nIndex
)
92 || (m_pIndexReg
!= rSwIndex
.m_pIndexReg
);
95 sal_Int32
GetIndex() const { return m_nIndex
; }
97 // Assignments without creating a temporary object.
98 SwIndex
&Assign(SwIndexReg
*, sal_Int32
);
100 // Returns pointer to IndexArray (for RTTI at SwIndexReg).
101 const SwIndexReg
* GetIdxReg() const { return m_pIndexReg
; }
102 const SwIndex
* GetNext() const { return m_pNext
; }
104 const sw::mark::IMark
* GetMark() const { return m_pMark
; }
105 void SetMark(const sw::mark::IMark
* pMark
);
108 SW_DLLPUBLIC
std::ostream
& operator <<(std::ostream
& s
, const SwIndex
& index
);
110 class SAL_WARN_UNUSED SwIndexReg
112 friend class SwIndex
;
113 friend bool sw_PosOk(const SwPosition
& aPos
);
115 const SwIndex
* m_pFirst
;
116 const SwIndex
* m_pLast
;
119 virtual void Update( SwIndex
const & rPos
, const sal_Int32 nChangeLen
,
120 const bool bNegative
= false, const bool bDelete
= false );
122 bool HasAnyIndex() const { return nullptr != m_pFirst
; }
126 virtual ~SwIndexReg();
128 void MoveTo( SwIndexReg
& rArr
);
129 const SwIndex
* GetFirstIndex() const { return m_pFirst
; }
134 inline sal_Int32
SwIndex::operator++()
136 return ChgValue( *this, m_nIndex
+1 ).m_nIndex
;
139 inline sal_Int32
SwIndex::operator--()
141 return ChgValue( *this, m_nIndex
-1 ).m_nIndex
;
144 inline sal_Int32
SwIndex::operator--(int)
146 sal_Int32
const nOldIndex
= m_nIndex
;
147 ChgValue( *this, m_nIndex
-1 );
151 inline sal_Int32
SwIndex::operator+=( sal_Int32
const nVal
)
153 return ChgValue( *this, m_nIndex
+ nVal
).m_nIndex
;
156 inline sal_Int32
SwIndex::operator-=( sal_Int32
const nVal
)
158 return ChgValue( *this, m_nIndex
- nVal
).m_nIndex
;
161 inline bool SwIndex::operator< ( const SwIndex
& rIndex
) const
163 return m_nIndex
< rIndex
.m_nIndex
;
166 inline bool SwIndex::operator<=( const SwIndex
& rIndex
) const
168 return m_nIndex
<= rIndex
.m_nIndex
;
171 inline bool SwIndex::operator> ( const SwIndex
& rIndex
) const
173 return m_nIndex
> rIndex
.m_nIndex
;
176 inline bool SwIndex::operator>=( const SwIndex
& rIndex
) const
178 return m_nIndex
>= rIndex
.m_nIndex
;
181 inline SwIndex
& SwIndex::operator= ( sal_Int32
const nVal
)
183 if (m_nIndex
!= nVal
)
185 ChgValue( *this, nVal
);
190 #endif // ifndef DBG_UTIL
194 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */