1*38d50f7bSAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*38d50f7bSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*38d50f7bSAndrew Rist * or more contributor license agreements. See the NOTICE file 5*38d50f7bSAndrew Rist * distributed with this work for additional information 6*38d50f7bSAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*38d50f7bSAndrew Rist * to you under the Apache License, Version 2.0 (the 8*38d50f7bSAndrew Rist * "License"); you may not use this file except in compliance 9*38d50f7bSAndrew Rist * with the License. You may obtain a copy of the License at 10*38d50f7bSAndrew Rist * 11*38d50f7bSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12*38d50f7bSAndrew Rist * 13*38d50f7bSAndrew Rist * Unless required by applicable law or agreed to in writing, 14*38d50f7bSAndrew Rist * software distributed under the License is distributed on an 15*38d50f7bSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*38d50f7bSAndrew Rist * KIND, either express or implied. See the License for the 17*38d50f7bSAndrew Rist * specific language governing permissions and limitations 18*38d50f7bSAndrew Rist * under the License. 19*38d50f7bSAndrew Rist * 20*38d50f7bSAndrew Rist *************************************************************/ 21*38d50f7bSAndrew Rist 22*38d50f7bSAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir #ifndef SC_COLLECT_HXX 25cdf0e10cSrcweir #define SC_COLLECT_HXX 26cdf0e10cSrcweir 27cdf0e10cSrcweir #include "address.hxx" 28cdf0e10cSrcweir #include <tools/string.hxx> 29cdf0e10cSrcweir 30cdf0e10cSrcweir #ifndef INCLUDED_LIMITS_H 31cdf0e10cSrcweir #include <limits.h> 32cdf0e10cSrcweir #define INCLUDED_LIMITS_H 33cdf0e10cSrcweir #endif 34cdf0e10cSrcweir #include "scdllapi.h" 35cdf0e10cSrcweir 36cdf0e10cSrcweir #define MAXCOLLECTIONSIZE 16384 37cdf0e10cSrcweir #define MAXDELTA 1024 38cdf0e10cSrcweir #define SCPOS_INVALID USHRT_MAX 39cdf0e10cSrcweir 40cdf0e10cSrcweir #define SC_STRTYPE_VALUE 0 41cdf0e10cSrcweir #define SC_STRTYPE_STANDARD 1 42cdf0e10cSrcweir 43cdf0e10cSrcweir class ScDocument; 44cdf0e10cSrcweir 45cdf0e10cSrcweir class SC_DLLPUBLIC ScDataObject 46cdf0e10cSrcweir { 47cdf0e10cSrcweir public: ScDataObject()48cdf0e10cSrcweir ScDataObject() {} 49cdf0e10cSrcweir virtual ~ScDataObject(); 50cdf0e10cSrcweir virtual ScDataObject* Clone() const = 0; 51cdf0e10cSrcweir }; 52cdf0e10cSrcweir 53cdf0e10cSrcweir class SC_DLLPUBLIC ScCollection : public ScDataObject 54cdf0e10cSrcweir { 55cdf0e10cSrcweir protected: 56cdf0e10cSrcweir sal_uInt16 nCount; 57cdf0e10cSrcweir sal_uInt16 nLimit; 58cdf0e10cSrcweir sal_uInt16 nDelta; 59cdf0e10cSrcweir ScDataObject** pItems; 60cdf0e10cSrcweir public: 61cdf0e10cSrcweir ScCollection(sal_uInt16 nLim = 4, sal_uInt16 nDel = 4); 62cdf0e10cSrcweir ScCollection(const ScCollection& rCollection); 63cdf0e10cSrcweir virtual ~ScCollection(); 64cdf0e10cSrcweir 65cdf0e10cSrcweir virtual ScDataObject* Clone() const; 66cdf0e10cSrcweir 67cdf0e10cSrcweir void AtFree(sal_uInt16 nIndex); 68cdf0e10cSrcweir void Free(ScDataObject* pScDataObject); 69cdf0e10cSrcweir void FreeAll(); 70cdf0e10cSrcweir 71cdf0e10cSrcweir sal_Bool AtInsert(sal_uInt16 nIndex, ScDataObject* pScDataObject); 72cdf0e10cSrcweir virtual sal_Bool Insert(ScDataObject* pScDataObject); 73cdf0e10cSrcweir 74cdf0e10cSrcweir ScDataObject* At(sal_uInt16 nIndex) const; 75cdf0e10cSrcweir virtual sal_uInt16 IndexOf(ScDataObject* pScDataObject) const; 76cdf0e10cSrcweir sal_uInt16 GetCount() const; 77cdf0e10cSrcweir operator [](const sal_uInt16 nIndex) const78cdf0e10cSrcweir ScDataObject* operator[]( const sal_uInt16 nIndex) const {return At(nIndex);} 79cdf0e10cSrcweir ScCollection& operator=( const ScCollection& rCol ); 80cdf0e10cSrcweir }; 81cdf0e10cSrcweir 82cdf0e10cSrcweir 83cdf0e10cSrcweir class SC_DLLPUBLIC ScSortedCollection : public ScCollection 84cdf0e10cSrcweir { 85cdf0e10cSrcweir private: 86cdf0e10cSrcweir sal_Bool bDuplicates; 87cdf0e10cSrcweir protected: 88cdf0e10cSrcweir // fuer ScStrCollection Load/Store SetDups(sal_Bool bVal)89cdf0e10cSrcweir void SetDups( sal_Bool bVal ) { bDuplicates = bVal; } IsDups() const90cdf0e10cSrcweir sal_Bool IsDups() const { return bDuplicates; } 91cdf0e10cSrcweir public: 92cdf0e10cSrcweir ScSortedCollection(sal_uInt16 nLim = 4, sal_uInt16 nDel = 4, sal_Bool bDup = sal_False); ScSortedCollection(const ScSortedCollection & rScSortedCollection)93cdf0e10cSrcweir ScSortedCollection(const ScSortedCollection& rScSortedCollection) : 94cdf0e10cSrcweir ScCollection(rScSortedCollection), 95cdf0e10cSrcweir bDuplicates(rScSortedCollection.bDuplicates) {} 96cdf0e10cSrcweir 97cdf0e10cSrcweir virtual sal_uInt16 IndexOf(ScDataObject* pScDataObject) const; 98cdf0e10cSrcweir virtual short Compare(ScDataObject* pKey1, ScDataObject* pKey2) const = 0; 99cdf0e10cSrcweir virtual sal_Bool IsEqual(ScDataObject* pKey1, ScDataObject* pKey2) const; 100cdf0e10cSrcweir sal_Bool Search(ScDataObject* pScDataObject, sal_uInt16& rIndex) const; 101cdf0e10cSrcweir virtual sal_Bool Insert(ScDataObject* pScDataObject); 102cdf0e10cSrcweir virtual sal_Bool InsertPos(ScDataObject* pScDataObject, sal_uInt16& nIndex); 103cdf0e10cSrcweir 104cdf0e10cSrcweir sal_Bool operator==(const ScSortedCollection& rCmp) const; 105cdf0e10cSrcweir }; 106cdf0e10cSrcweir 107cdf0e10cSrcweir 108cdf0e10cSrcweir 109cdf0e10cSrcweir //------------------------------------------------------------------------ 110cdf0e10cSrcweir class StrData : public ScDataObject 111cdf0e10cSrcweir { 112cdf0e10cSrcweir friend class ScStrCollection; 113cdf0e10cSrcweir String aStr; 114cdf0e10cSrcweir public: StrData(const String & rStr)115cdf0e10cSrcweir StrData(const String& rStr) : aStr(rStr) {} StrData(const StrData & rData)116cdf0e10cSrcweir StrData(const StrData& rData) : ScDataObject(), aStr(rData.aStr) {} 117cdf0e10cSrcweir virtual ScDataObject* Clone() const; GetString() const118cdf0e10cSrcweir const String& GetString() const { return aStr; } 119cdf0e10cSrcweir // SetString nur, wenn StrData nicht in ScStrCollection ist! !!! 120cdf0e10cSrcweir // z.B. fuer Searcher SetString(const String & rNew)121cdf0e10cSrcweir void SetString( const String& rNew ) { aStr = rNew; } 122cdf0e10cSrcweir }; 123cdf0e10cSrcweir 124cdf0e10cSrcweir //------------------------------------------------------------------------ 125cdf0e10cSrcweir 126cdf0e10cSrcweir class SvStream; 127cdf0e10cSrcweir 128cdf0e10cSrcweir class SC_DLLPUBLIC ScStrCollection : public ScSortedCollection 129cdf0e10cSrcweir { 130cdf0e10cSrcweir public: ScStrCollection(sal_uInt16 nLim=4,sal_uInt16 nDel=4,sal_Bool bDup=sal_False)131cdf0e10cSrcweir ScStrCollection(sal_uInt16 nLim = 4, sal_uInt16 nDel = 4, sal_Bool bDup = sal_False) : 132cdf0e10cSrcweir ScSortedCollection ( nLim, nDel, bDup ) {} ScStrCollection(const ScStrCollection & rScStrCollection)133cdf0e10cSrcweir ScStrCollection(const ScStrCollection& rScStrCollection) : 134cdf0e10cSrcweir ScSortedCollection ( rScStrCollection ) {} 135cdf0e10cSrcweir 136cdf0e10cSrcweir virtual ScDataObject* Clone() const; operator [](const sal_uInt16 nIndex) const137cdf0e10cSrcweir StrData* operator[]( const sal_uInt16 nIndex) const {return (StrData*)At(nIndex);} 138cdf0e10cSrcweir virtual short Compare(ScDataObject* pKey1, ScDataObject* pKey2) const; 139cdf0e10cSrcweir }; 140cdf0e10cSrcweir 141cdf0e10cSrcweir //------------------------------------------------------------------------ 142cdf0e10cSrcweir // TypedScStrCollection: wie ScStrCollection, nur, dass Zahlen vor Strings 143cdf0e10cSrcweir // sortiert werden 144cdf0e10cSrcweir 145cdf0e10cSrcweir class TypedStrData : public ScDataObject 146cdf0e10cSrcweir { 147cdf0e10cSrcweir public: TypedStrData(const String & rStr,double nVal=0.0,sal_uInt16 nType=SC_STRTYPE_STANDARD)148cdf0e10cSrcweir TypedStrData( const String& rStr, double nVal = 0.0, 149cdf0e10cSrcweir sal_uInt16 nType = SC_STRTYPE_STANDARD ) 150cdf0e10cSrcweir : aStrValue(rStr), 151cdf0e10cSrcweir nValue(nVal), 152cdf0e10cSrcweir nStrType(nType) {} 153cdf0e10cSrcweir 154cdf0e10cSrcweir //UNUSED2008-05 TypedStrData( ScDocument* pDoc, SCCOL nCol, SCROW nRow, SCTAB nTab, 155cdf0e10cSrcweir //UNUSED2008-05 sal_Bool bAllStrings ); 156cdf0e10cSrcweir TypedStrData(const TypedStrData & rCpy)157cdf0e10cSrcweir TypedStrData( const TypedStrData& rCpy ) 158cdf0e10cSrcweir : ScDataObject(), 159cdf0e10cSrcweir aStrValue(rCpy.aStrValue), 160cdf0e10cSrcweir nValue(rCpy.nValue), 161cdf0e10cSrcweir nStrType(rCpy.nStrType) {} 162cdf0e10cSrcweir 163cdf0e10cSrcweir virtual ScDataObject* Clone() const; 164cdf0e10cSrcweir IsStrData() const165cdf0e10cSrcweir sal_Bool IsStrData() const { return nStrType != 0; } GetString() const166cdf0e10cSrcweir const String& GetString() const { return aStrValue; } GetValue() const167cdf0e10cSrcweir double GetValue () const { return nValue; } 168cdf0e10cSrcweir 169cdf0e10cSrcweir private: 170cdf0e10cSrcweir friend class TypedScStrCollection; 171cdf0e10cSrcweir 172cdf0e10cSrcweir String aStrValue; 173cdf0e10cSrcweir double nValue; 174cdf0e10cSrcweir sal_uInt16 nStrType; // 0 = Value 175cdf0e10cSrcweir }; 176cdf0e10cSrcweir 177cdf0e10cSrcweir class SC_DLLPUBLIC TypedScStrCollection : public ScSortedCollection 178cdf0e10cSrcweir { 179cdf0e10cSrcweir private: 180cdf0e10cSrcweir sal_Bool bCaseSensitive; 181cdf0e10cSrcweir 182cdf0e10cSrcweir public: 183cdf0e10cSrcweir TypedScStrCollection( sal_uInt16 nLim = 4, sal_uInt16 nDel = 4, sal_Bool bDup = sal_False ); 184cdf0e10cSrcweir TypedScStrCollection(const TypedScStrCollection & rCpy)185cdf0e10cSrcweir TypedScStrCollection( const TypedScStrCollection& rCpy ) 186cdf0e10cSrcweir : ScSortedCollection( rCpy ) { bCaseSensitive = rCpy.bCaseSensitive; } 187cdf0e10cSrcweir ~TypedScStrCollection(); 188cdf0e10cSrcweir 189cdf0e10cSrcweir virtual ScDataObject* Clone() const; 190cdf0e10cSrcweir virtual short Compare( ScDataObject* pKey1, ScDataObject* pKey2 ) const; 191cdf0e10cSrcweir 192cdf0e10cSrcweir TypedStrData* operator[]( const sal_uInt16 nIndex) const; 193cdf0e10cSrcweir 194cdf0e10cSrcweir void SetCaseSensitive( sal_Bool bSet ); 195cdf0e10cSrcweir 196cdf0e10cSrcweir sal_Bool FindText( const String& rStart, String& rResult, sal_uInt16& rPos, sal_Bool bBack ) const; 197cdf0e10cSrcweir sal_Bool GetExactMatch( String& rString ) const; 198cdf0e10cSrcweir }; 199cdf0e10cSrcweir 200cdf0e10cSrcweir #endif 201