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 28 #ifndef SC_COLLECT_HXX 29 #define SC_COLLECT_HXX 30 31 #include "address.hxx" 32 #include <tools/string.hxx> 33 34 #ifndef INCLUDED_LIMITS_H 35 #include <limits.h> 36 #define INCLUDED_LIMITS_H 37 #endif 38 #include "scdllapi.h" 39 40 #define MAXCOLLECTIONSIZE 16384 41 #define MAXDELTA 1024 42 #define SCPOS_INVALID USHRT_MAX 43 44 #define SC_STRTYPE_VALUE 0 45 #define SC_STRTYPE_STANDARD 1 46 47 class ScDocument; 48 49 class SC_DLLPUBLIC ScDataObject 50 { 51 public: 52 ScDataObject() {} 53 virtual ~ScDataObject(); 54 virtual ScDataObject* Clone() const = 0; 55 }; 56 57 class SC_DLLPUBLIC ScCollection : public ScDataObject 58 { 59 protected: 60 sal_uInt16 nCount; 61 sal_uInt16 nLimit; 62 sal_uInt16 nDelta; 63 ScDataObject** pItems; 64 public: 65 ScCollection(sal_uInt16 nLim = 4, sal_uInt16 nDel = 4); 66 ScCollection(const ScCollection& rCollection); 67 virtual ~ScCollection(); 68 69 virtual ScDataObject* Clone() const; 70 71 void AtFree(sal_uInt16 nIndex); 72 void Free(ScDataObject* pScDataObject); 73 void FreeAll(); 74 75 sal_Bool AtInsert(sal_uInt16 nIndex, ScDataObject* pScDataObject); 76 virtual sal_Bool Insert(ScDataObject* pScDataObject); 77 78 ScDataObject* At(sal_uInt16 nIndex) const; 79 virtual sal_uInt16 IndexOf(ScDataObject* pScDataObject) const; 80 sal_uInt16 GetCount() const; 81 82 ScDataObject* operator[]( const sal_uInt16 nIndex) const {return At(nIndex);} 83 ScCollection& operator=( const ScCollection& rCol ); 84 }; 85 86 87 class SC_DLLPUBLIC ScSortedCollection : public ScCollection 88 { 89 private: 90 sal_Bool bDuplicates; 91 protected: 92 // fuer ScStrCollection Load/Store 93 void SetDups( sal_Bool bVal ) { bDuplicates = bVal; } 94 sal_Bool IsDups() const { return bDuplicates; } 95 public: 96 ScSortedCollection(sal_uInt16 nLim = 4, sal_uInt16 nDel = 4, sal_Bool bDup = sal_False); 97 ScSortedCollection(const ScSortedCollection& rScSortedCollection) : 98 ScCollection(rScSortedCollection), 99 bDuplicates(rScSortedCollection.bDuplicates) {} 100 101 virtual sal_uInt16 IndexOf(ScDataObject* pScDataObject) const; 102 virtual short Compare(ScDataObject* pKey1, ScDataObject* pKey2) const = 0; 103 virtual sal_Bool IsEqual(ScDataObject* pKey1, ScDataObject* pKey2) const; 104 sal_Bool Search(ScDataObject* pScDataObject, sal_uInt16& rIndex) const; 105 virtual sal_Bool Insert(ScDataObject* pScDataObject); 106 virtual sal_Bool InsertPos(ScDataObject* pScDataObject, sal_uInt16& nIndex); 107 108 sal_Bool operator==(const ScSortedCollection& rCmp) const; 109 }; 110 111 112 113 //------------------------------------------------------------------------ 114 class StrData : public ScDataObject 115 { 116 friend class ScStrCollection; 117 String aStr; 118 public: 119 StrData(const String& rStr) : aStr(rStr) {} 120 StrData(const StrData& rData) : ScDataObject(), aStr(rData.aStr) {} 121 virtual ScDataObject* Clone() const; 122 const String& GetString() const { return aStr; } 123 // SetString nur, wenn StrData nicht in ScStrCollection ist! !!! 124 // z.B. fuer Searcher 125 void SetString( const String& rNew ) { aStr = rNew; } 126 }; 127 128 //------------------------------------------------------------------------ 129 130 class SvStream; 131 132 class SC_DLLPUBLIC ScStrCollection : public ScSortedCollection 133 { 134 public: 135 ScStrCollection(sal_uInt16 nLim = 4, sal_uInt16 nDel = 4, sal_Bool bDup = sal_False) : 136 ScSortedCollection ( nLim, nDel, bDup ) {} 137 ScStrCollection(const ScStrCollection& rScStrCollection) : 138 ScSortedCollection ( rScStrCollection ) {} 139 140 virtual ScDataObject* Clone() const; 141 StrData* operator[]( const sal_uInt16 nIndex) const {return (StrData*)At(nIndex);} 142 virtual short Compare(ScDataObject* pKey1, ScDataObject* pKey2) const; 143 }; 144 145 //------------------------------------------------------------------------ 146 // TypedScStrCollection: wie ScStrCollection, nur, dass Zahlen vor Strings 147 // sortiert werden 148 149 class TypedStrData : public ScDataObject 150 { 151 public: 152 TypedStrData( const String& rStr, double nVal = 0.0, 153 sal_uInt16 nType = SC_STRTYPE_STANDARD ) 154 : aStrValue(rStr), 155 nValue(nVal), 156 nStrType(nType) {} 157 158 //UNUSED2008-05 TypedStrData( ScDocument* pDoc, SCCOL nCol, SCROW nRow, SCTAB nTab, 159 //UNUSED2008-05 sal_Bool bAllStrings ); 160 161 TypedStrData( const TypedStrData& rCpy ) 162 : ScDataObject(), 163 aStrValue(rCpy.aStrValue), 164 nValue(rCpy.nValue), 165 nStrType(rCpy.nStrType) {} 166 167 virtual ScDataObject* Clone() const; 168 169 sal_Bool IsStrData() const { return nStrType != 0; } 170 const String& GetString() const { return aStrValue; } 171 double GetValue () const { return nValue; } 172 173 private: 174 friend class TypedScStrCollection; 175 176 String aStrValue; 177 double nValue; 178 sal_uInt16 nStrType; // 0 = Value 179 }; 180 181 class SC_DLLPUBLIC TypedScStrCollection : public ScSortedCollection 182 { 183 private: 184 sal_Bool bCaseSensitive; 185 186 public: 187 TypedScStrCollection( sal_uInt16 nLim = 4, sal_uInt16 nDel = 4, sal_Bool bDup = sal_False ); 188 189 TypedScStrCollection( const TypedScStrCollection& rCpy ) 190 : ScSortedCollection( rCpy ) { bCaseSensitive = rCpy.bCaseSensitive; } 191 ~TypedScStrCollection(); 192 193 virtual ScDataObject* Clone() const; 194 virtual short Compare( ScDataObject* pKey1, ScDataObject* pKey2 ) const; 195 196 TypedStrData* operator[]( const sal_uInt16 nIndex) const; 197 198 void SetCaseSensitive( sal_Bool bSet ); 199 200 sal_Bool FindText( const String& rStart, String& rResult, sal_uInt16& rPos, sal_Bool bBack ) const; 201 sal_Bool GetExactMatch( String& rString ) const; 202 }; 203 204 #endif 205