bump product version to 4.1.6.2
[LibreOffice.git] / sw / inc / index.hxx
blobe664538a285a694d3d3528255635bf9ca3265472
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 SW_INDEX_HXX
20 #define SW_INDEX_HXX
22 #include <limits.h>
24 #include "rtl/instance.hxx"
25 #include <tools/solar.h>
26 #include <tools/rtti.hxx> // for RTTI of SwIndexReg
27 #include <swdllapi.h>
29 // Maximum index in IndexArray (for testing on overflows).
30 #define INVALID_INDEX STRING_NOTFOUND
32 class SwIndex;
33 class SwIndexReg;
34 struct SwPosition;
36 #ifdef DBG_UTIL
37 #define INLINE
38 #else
39 #define INLINE inline
40 #endif
42 /// Marks a character position inside a document model node.
43 class SW_DLLPUBLIC SwIndex
45 private:
46 friend class SwIndexReg;
48 xub_StrLen m_nIndex;
49 SwIndexReg * m_pIndexReg;
50 // doubly linked list of Indexes registered at m_pIndexReg
51 SwIndex * m_pNext;
52 SwIndex * m_pPrev;
54 SwIndex& ChgValue( const SwIndex& rIdx, xub_StrLen nNewValue );
55 void Init(xub_StrLen const nIdx);
56 void Remove();
58 public:
59 explicit SwIndex(SwIndexReg *const pReg, xub_StrLen const nIdx = 0);
60 SwIndex( const SwIndex & );
61 SwIndex( const SwIndex &, short nDiff );
62 ~SwIndex() { Remove(); }
64 INLINE SwIndex& operator=( xub_StrLen const );
65 SwIndex& operator=( const SwIndex & );
67 INLINE xub_StrLen operator++();
68 INLINE xub_StrLen operator--();
69 INLINE xub_StrLen operator++(int);
70 INLINE xub_StrLen operator--(int);
72 INLINE xub_StrLen operator+=( xub_StrLen const );
73 INLINE xub_StrLen operator-=( xub_StrLen const );
74 INLINE xub_StrLen operator+=( const SwIndex& );
75 INLINE xub_StrLen operator-=( const SwIndex& );
77 INLINE bool operator< ( const SwIndex& ) const;
78 INLINE bool operator<=( const SwIndex& ) const;
79 INLINE bool operator> ( const SwIndex& ) const;
80 INLINE bool operator>=( const SwIndex& ) const;
82 bool operator< ( xub_StrLen const nVal ) const { return m_nIndex < nVal; }
83 bool operator<=( xub_StrLen const nVal ) const { return m_nIndex <= nVal; }
84 bool operator> ( xub_StrLen const nVal ) const { return m_nIndex > nVal; }
85 bool operator>=( xub_StrLen const nVal ) const { return m_nIndex >= nVal; }
86 bool operator==( xub_StrLen const nVal ) const { return m_nIndex == nVal; }
87 bool operator!=( xub_StrLen const nVal ) const { return m_nIndex != nVal; }
89 bool operator==( const SwIndex& rSwIndex ) const
91 return (m_nIndex == rSwIndex.m_nIndex)
92 && (m_pIndexReg == rSwIndex.m_pIndexReg);
95 bool operator!=( const SwIndex& rSwIndex ) const
97 return (m_nIndex != rSwIndex.m_nIndex)
98 || (m_pIndexReg != rSwIndex.m_pIndexReg);
101 xub_StrLen GetIndex() const { return m_nIndex; }
103 // Assignments without creating a temporary object.
104 SwIndex &Assign(SwIndexReg *,xub_StrLen);
106 // Returns pointer to IndexArray (for RTTI at SwIndexReg).
107 const SwIndexReg* GetIdxReg() const { return m_pIndexReg; }
110 #undef INLINE
112 class SwIndexReg
114 friend class SwIndex;
115 friend bool sw_PosOk(const SwPosition & aPos);
117 const SwIndex * m_pFirst;
118 const SwIndex * m_pLast;
120 protected:
121 virtual void Update( SwIndex const & rPos, const xub_StrLen nChangeLen,
122 const bool bNegative = false, const bool bDelete = false );
124 void ChkArr();
126 bool HasAnyIndex() const { return 0 != m_pFirst; }
128 public:
129 explicit SwIndexReg();
130 virtual ~SwIndexReg();
132 /// rtti, derived classes might do the same. If so, one can cast typesavely
133 /// via SwIndexReg.
134 TYPEINFO();
136 void MoveTo( SwIndexReg& rArr );
140 #ifndef DBG_UTIL
142 inline xub_StrLen SwIndex::operator++()
144 return ChgValue( *this, m_nIndex+1 ).m_nIndex;
146 inline xub_StrLen SwIndex::operator--()
148 return ChgValue( *this, m_nIndex-1 ).m_nIndex;
150 inline xub_StrLen SwIndex::operator++(int)
152 xub_StrLen const nOldIndex = m_nIndex;
153 ChgValue( *this, m_nIndex+1 );
154 return nOldIndex;
156 inline xub_StrLen SwIndex::operator--(int)
158 xub_StrLen const nOldIndex = m_nIndex;
159 ChgValue( *this, m_nIndex-1 );
160 return nOldIndex;
163 inline xub_StrLen SwIndex::operator+=( xub_StrLen const nVal )
165 return ChgValue( *this, m_nIndex + nVal ).m_nIndex;
167 inline xub_StrLen SwIndex::operator-=( xub_StrLen const nVal )
169 return ChgValue( *this, m_nIndex - nVal ).m_nIndex;
171 inline xub_StrLen SwIndex::operator+=( const SwIndex& rIndex )
173 return ChgValue( *this, m_nIndex + rIndex.m_nIndex ).m_nIndex;
175 inline xub_StrLen SwIndex::operator-=( const SwIndex& rIndex )
177 return ChgValue( *this, m_nIndex - rIndex.m_nIndex ).m_nIndex;
180 inline bool SwIndex::operator< ( const SwIndex& rIndex ) const
182 return m_nIndex < rIndex.m_nIndex;
184 inline bool SwIndex::operator<=( const SwIndex& rIndex ) const
186 return m_nIndex <= rIndex.m_nIndex;
188 inline bool SwIndex::operator> ( const SwIndex& rIndex ) const
190 return m_nIndex > rIndex.m_nIndex;
192 inline bool SwIndex::operator>=( const SwIndex& rIndex ) const
194 return m_nIndex >= rIndex.m_nIndex;
196 inline SwIndex& SwIndex::operator= ( xub_StrLen const nVal )
198 if (m_nIndex != nVal)
200 ChgValue( *this, nVal );
202 return *this;
205 #endif // ifndef DBG_UTIL
207 #endif
209 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */