1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 #ifndef _INDEX_HXX 28 #define _INDEX_HXX 29 30 #include <limits.h> 31 #include <tools/solar.h> 32 #include <tools/rtti.hxx> // for RTTI of SwIndexReg 33 #include <tools/string.hxx> // for xub_StrLen 34 #include <swdllapi.h> 35 36 #define INVALID_INDEX STRING_NOTFOUND 37 38 // Maximale Anzahl von Indizies im IndexArray (zum Abtesten auf Ueberlaeufe) 39 class SwIndex; 40 class SwIndexReg; 41 struct SwPosition; 42 43 #ifndef DBG_UTIL 44 #define INLINE inline 45 #else 46 #define INLINE 47 #endif 48 49 class SW_DLLPUBLIC SwIndex 50 { 51 friend class SwIndexReg; 52 53 #ifdef DBG_UTIL 54 static int nSerial; 55 int MySerial; 56 #endif 57 58 xub_StrLen nIndex; 59 SwIndexReg* pArray; 60 SwIndex *pNext, *pPrev; 61 62 SwIndex& ChgValue( const SwIndex& rIdx, xub_StrLen nNewValue ); 63 void Remove(); // Ausketten 64 65 public: 66 explicit SwIndex(SwIndexReg *const pReg, xub_StrLen const nIdx = 0); 67 SwIndex( const SwIndex & ); 68 SwIndex( const SwIndex &, short nDiff ); 69 ~SwIndex() { Remove(); } 70 71 INLINE xub_StrLen operator++(); 72 INLINE xub_StrLen operator--(); 73 #ifndef CFRONT 74 INLINE xub_StrLen operator++(int); 75 INLINE xub_StrLen operator--(int); 76 #endif 77 78 INLINE xub_StrLen operator+=( xub_StrLen ); 79 INLINE xub_StrLen operator-=( xub_StrLen ); 80 INLINE xub_StrLen operator+=( const SwIndex& ); 81 INLINE xub_StrLen operator-=( const SwIndex& ); 82 83 INLINE sal_Bool operator<( const SwIndex& ) const; 84 INLINE sal_Bool operator<=( const SwIndex& ) const; 85 INLINE sal_Bool operator>( const SwIndex& ) const; 86 INLINE sal_Bool operator>=( const SwIndex& ) const; 87 sal_Bool operator==( const SwIndex& rSwIndex ) const 88 { return (nIndex == rSwIndex.nIndex) && (pArray == rSwIndex.pArray); } 89 90 sal_Bool operator!=( const SwIndex& rSwIndex ) const 91 { return (nIndex != rSwIndex.nIndex) || (pArray != rSwIndex.pArray); } 92 93 sal_Bool operator<( xub_StrLen nWert ) const { return nIndex < nWert; } 94 sal_Bool operator<=( xub_StrLen nWert ) const { return nIndex <= nWert; } 95 sal_Bool operator>( xub_StrLen nWert ) const { return nIndex > nWert; } 96 sal_Bool operator>=( xub_StrLen nWert ) const { return nIndex >= nWert; } 97 sal_Bool operator==( xub_StrLen nWert ) const { return nIndex == nWert; } 98 sal_Bool operator!=( xub_StrLen nWert ) const { return nIndex != nWert; } 99 100 INLINE SwIndex& operator=( xub_StrLen ); 101 SwIndex& operator=( const SwIndex & ); 102 103 // gebe den Wert vom Index als xub_StrLen zurueck 104 xub_StrLen GetIndex() const { return nIndex; } 105 106 // ermoeglicht Zuweisungen ohne Erzeugen eines temporaeren 107 // Objektes 108 SwIndex &Assign(SwIndexReg *,xub_StrLen); 109 110 // Herausgabe des Pointers auf das IndexArray, 111 // (fuers RTTI am SwIndexReg) 112 const SwIndexReg* GetIdxReg() const { return pArray; } 113 }; 114 115 #undef INLINE 116 117 class SwIndexReg 118 { 119 friend class SwIndex; 120 friend bool lcl_PosOk(const SwPosition & aPos); 121 122 const SwIndex *pFirst, *pLast, *pMiddle; 123 124 // ein globales Array, in das Indizies verschoben werden, die mal 125 // temporaer "ausgelagert" werden muessen; oder die zum Zeitpunkt des 126 // anlegens kein gueltiges Array kennen (SwPaM/SwPosition!) 127 friend void _InitCore(); 128 friend void _FinitCore(); 129 static SwIndexReg* pEmptyIndexArray; 130 131 protected: 132 virtual void Update( SwIndex const & rPos, const xub_StrLen nChangeLen, 133 const bool bNegative = false, const bool bDelete = false ); 134 135 void ChkArr(); 136 137 sal_Bool HasAnyIndex() const { return 0 != pFirst; } 138 139 public: 140 SwIndexReg(); 141 virtual ~SwIndexReg(); 142 143 // rtti, abgeleitete moegens gleichtun oder nicht. Wenn sie es gleichtun 144 // kann ueber das SwIndexReg typsicher gecastet werden. 145 TYPEINFO(); 146 147 void MoveTo( SwIndexReg& rArr ); 148 }; 149 150 #ifndef DBG_UTIL 151 152 inline xub_StrLen SwIndex::operator++() 153 { 154 return ChgValue( *this, nIndex+1 ).nIndex; 155 } 156 inline xub_StrLen SwIndex::operator--() 157 { 158 return ChgValue( *this, nIndex-1 ).nIndex; 159 } 160 #ifndef CFRONT 161 inline xub_StrLen SwIndex::operator++(int) 162 { 163 xub_StrLen nOldIndex = nIndex; 164 ChgValue( *this, nIndex+1 ); 165 return nOldIndex; 166 } 167 inline xub_StrLen SwIndex::operator--(int) 168 { 169 xub_StrLen nOldIndex = nIndex; 170 ChgValue( *this, nIndex-1 ); 171 return nOldIndex; 172 } 173 #endif 174 175 inline xub_StrLen SwIndex::operator+=( xub_StrLen nWert ) 176 { 177 return ChgValue( *this, nIndex + nWert ).nIndex; 178 } 179 inline xub_StrLen SwIndex::operator-=( xub_StrLen nWert ) 180 { 181 return ChgValue( *this, nIndex - nWert ).nIndex; 182 } 183 inline xub_StrLen SwIndex::operator+=( const SwIndex& rIndex ) 184 { 185 return ChgValue( *this, nIndex + rIndex.nIndex ).nIndex; 186 } 187 inline xub_StrLen SwIndex::operator-=( const SwIndex& rIndex ) 188 { 189 return ChgValue( *this, nIndex - rIndex.nIndex ).nIndex; 190 } 191 192 inline sal_Bool SwIndex::operator<( const SwIndex& rIndex ) const 193 { 194 return nIndex < rIndex.nIndex; 195 } 196 inline sal_Bool SwIndex::operator<=( const SwIndex& rIndex ) const 197 { 198 return nIndex <= rIndex.nIndex; 199 } 200 inline sal_Bool SwIndex::operator>( const SwIndex& rIndex ) const 201 { 202 return nIndex > rIndex.nIndex; 203 } 204 inline sal_Bool SwIndex::operator>=( const SwIndex& rIndex ) const 205 { 206 return nIndex >= rIndex.nIndex; 207 } 208 inline SwIndex& SwIndex::operator=( xub_StrLen nWert ) 209 { 210 if( nIndex != nWert ) 211 ChgValue( *this, nWert ); 212 return *this; 213 } 214 215 #endif // PRODUCT 216 217 #endif 218