Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 : #ifndef SW_INDEX_HXX
20 : #define SW_INDEX_HXX
21 :
22 : #include <limits.h>
23 :
24 : #include "rtl/instance.hxx"
25 : #include <tools/solar.h>
26 : #include <tools/rtti.hxx> // for RTTI of SwIndexReg
27 : #include <swdllapi.h>
28 :
29 : // Maximum index in IndexArray (for testing on overflows).
30 : #define INVALID_INDEX STRING_NOTFOUND
31 :
32 : class SwIndex;
33 : class SwIndexReg;
34 : struct SwPosition;
35 :
36 : #ifdef DBG_UTIL
37 : #define INLINE
38 : #else
39 : #define INLINE inline
40 : #endif
41 :
42 : /// Marks a character position inside a document model node.
43 : class SW_DLLPUBLIC SwIndex
44 : {
45 : private:
46 : friend class SwIndexReg;
47 :
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;
53 :
54 : SwIndex& ChgValue( const SwIndex& rIdx, xub_StrLen nNewValue );
55 : void Init(xub_StrLen const nIdx);
56 : void Remove();
57 :
58 : public:
59 : explicit SwIndex(SwIndexReg *const pReg, xub_StrLen const nIdx = 0);
60 : SwIndex( const SwIndex & );
61 : SwIndex( const SwIndex &, short nDiff );
62 587496 : ~SwIndex() { Remove(); }
63 :
64 : INLINE SwIndex& operator=( xub_StrLen const );
65 : SwIndex& operator=( const SwIndex & );
66 :
67 : INLINE xub_StrLen operator++();
68 : INLINE xub_StrLen operator--();
69 : INLINE xub_StrLen operator++(int);
70 : INLINE xub_StrLen operator--(int);
71 :
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& );
76 :
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;
81 :
82 80 : bool operator< ( xub_StrLen const nVal ) const { return m_nIndex < nVal; }
83 0 : bool operator<=( xub_StrLen const nVal ) const { return m_nIndex <= nVal; }
84 2188 : bool operator> ( xub_StrLen const nVal ) const { return m_nIndex > nVal; }
85 226324 : bool operator>=( xub_StrLen const nVal ) const { return m_nIndex >= nVal; }
86 1112 : bool operator==( xub_StrLen const nVal ) const { return m_nIndex == nVal; }
87 5367 : bool operator!=( xub_StrLen const nVal ) const { return m_nIndex != nVal; }
88 :
89 7223 : bool operator==( const SwIndex& rSwIndex ) const
90 : {
91 : return (m_nIndex == rSwIndex.m_nIndex)
92 7223 : && (m_pIndexReg == rSwIndex.m_pIndexReg);
93 : }
94 :
95 34789 : bool operator!=( const SwIndex& rSwIndex ) const
96 : {
97 : return (m_nIndex != rSwIndex.m_nIndex)
98 34789 : || (m_pIndexReg != rSwIndex.m_pIndexReg);
99 : }
100 :
101 729736 : xub_StrLen GetIndex() const { return m_nIndex; }
102 :
103 : // Assignments without creating a temporary object.
104 : SwIndex &Assign(SwIndexReg *,xub_StrLen);
105 :
106 : // Returns pointer to IndexArray (for RTTI at SwIndexReg).
107 544996 : const SwIndexReg* GetIdxReg() const { return m_pIndexReg; }
108 : };
109 :
110 : #undef INLINE
111 :
112 : class SwIndexReg
113 : {
114 : friend class SwIndex;
115 : friend bool sw_PosOk(const SwPosition & aPos);
116 :
117 : const SwIndex * m_pFirst;
118 : const SwIndex * m_pLast;
119 :
120 : protected:
121 : virtual void Update( SwIndex const & rPos, const xub_StrLen nChangeLen,
122 : const bool bNegative = false, const bool bDelete = false );
123 :
124 : void ChkArr();
125 :
126 684 : bool HasAnyIndex() const { return 0 != m_pFirst; }
127 :
128 : public:
129 : explicit SwIndexReg();
130 : virtual ~SwIndexReg();
131 :
132 : // rtti, abgeleitete moegens gleichtun oder nicht. Wenn sie es gleichtun
133 : // kann ueber das SwIndexReg typsicher gecastet werden.
134 : TYPEINFO();
135 :
136 : void MoveTo( SwIndexReg& rArr );
137 : };
138 :
139 :
140 : #ifndef DBG_UTIL
141 :
142 0 : inline xub_StrLen SwIndex::operator++()
143 : {
144 0 : return ChgValue( *this, m_nIndex+1 ).m_nIndex;
145 : }
146 : inline xub_StrLen SwIndex::operator--()
147 : {
148 : return ChgValue( *this, m_nIndex-1 ).m_nIndex;
149 : }
150 22 : inline xub_StrLen SwIndex::operator++(int)
151 : {
152 22 : xub_StrLen const nOldIndex = m_nIndex;
153 22 : ChgValue( *this, m_nIndex+1 );
154 22 : return nOldIndex;
155 : }
156 392 : inline xub_StrLen SwIndex::operator--(int)
157 : {
158 392 : xub_StrLen const nOldIndex = m_nIndex;
159 392 : ChgValue( *this, m_nIndex-1 );
160 392 : return nOldIndex;
161 : }
162 :
163 1236 : inline xub_StrLen SwIndex::operator+=( xub_StrLen const nVal )
164 : {
165 1236 : return ChgValue( *this, m_nIndex + nVal ).m_nIndex;
166 : }
167 6 : inline xub_StrLen SwIndex::operator-=( xub_StrLen const nVal )
168 : {
169 6 : return ChgValue( *this, m_nIndex - nVal ).m_nIndex;
170 : }
171 : inline xub_StrLen SwIndex::operator+=( const SwIndex& rIndex )
172 : {
173 : return ChgValue( *this, m_nIndex + rIndex.m_nIndex ).m_nIndex;
174 : }
175 0 : inline xub_StrLen SwIndex::operator-=( const SwIndex& rIndex )
176 : {
177 0 : return ChgValue( *this, m_nIndex - rIndex.m_nIndex ).m_nIndex;
178 : }
179 :
180 20110 : inline bool SwIndex::operator< ( const SwIndex& rIndex ) const
181 : {
182 20110 : return m_nIndex < rIndex.m_nIndex;
183 : }
184 100819 : inline bool SwIndex::operator<=( const SwIndex& rIndex ) const
185 : {
186 100819 : return m_nIndex <= rIndex.m_nIndex;
187 : }
188 90772 : inline bool SwIndex::operator> ( const SwIndex& rIndex ) const
189 : {
190 90772 : return m_nIndex > rIndex.m_nIndex;
191 : }
192 4212 : inline bool SwIndex::operator>=( const SwIndex& rIndex ) const
193 : {
194 4212 : return m_nIndex >= rIndex.m_nIndex;
195 : }
196 5693 : inline SwIndex& SwIndex::operator= ( xub_StrLen const nVal )
197 : {
198 5693 : if (m_nIndex != nVal)
199 : {
200 2454 : ChgValue( *this, nVal );
201 : }
202 5693 : return *this;
203 : }
204 :
205 : #endif // ifndef DBG_UTIL
206 :
207 : #endif
208 :
209 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|