1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir 28*cdf0e10cSrcweir #ifndef SC_COLLECT_HXX 29*cdf0e10cSrcweir #define SC_COLLECT_HXX 30*cdf0e10cSrcweir 31*cdf0e10cSrcweir #include "address.hxx" 32*cdf0e10cSrcweir #include <tools/string.hxx> 33*cdf0e10cSrcweir 34*cdf0e10cSrcweir #ifndef INCLUDED_LIMITS_H 35*cdf0e10cSrcweir #include <limits.h> 36*cdf0e10cSrcweir #define INCLUDED_LIMITS_H 37*cdf0e10cSrcweir #endif 38*cdf0e10cSrcweir #include "scdllapi.h" 39*cdf0e10cSrcweir 40*cdf0e10cSrcweir #define MAXCOLLECTIONSIZE 16384 41*cdf0e10cSrcweir #define MAXDELTA 1024 42*cdf0e10cSrcweir #define SCPOS_INVALID USHRT_MAX 43*cdf0e10cSrcweir 44*cdf0e10cSrcweir #define SC_STRTYPE_VALUE 0 45*cdf0e10cSrcweir #define SC_STRTYPE_STANDARD 1 46*cdf0e10cSrcweir 47*cdf0e10cSrcweir class ScDocument; 48*cdf0e10cSrcweir 49*cdf0e10cSrcweir class SC_DLLPUBLIC ScDataObject 50*cdf0e10cSrcweir { 51*cdf0e10cSrcweir public: 52*cdf0e10cSrcweir ScDataObject() {} 53*cdf0e10cSrcweir virtual ~ScDataObject(); 54*cdf0e10cSrcweir virtual ScDataObject* Clone() const = 0; 55*cdf0e10cSrcweir }; 56*cdf0e10cSrcweir 57*cdf0e10cSrcweir class SC_DLLPUBLIC ScCollection : public ScDataObject 58*cdf0e10cSrcweir { 59*cdf0e10cSrcweir protected: 60*cdf0e10cSrcweir sal_uInt16 nCount; 61*cdf0e10cSrcweir sal_uInt16 nLimit; 62*cdf0e10cSrcweir sal_uInt16 nDelta; 63*cdf0e10cSrcweir ScDataObject** pItems; 64*cdf0e10cSrcweir public: 65*cdf0e10cSrcweir ScCollection(sal_uInt16 nLim = 4, sal_uInt16 nDel = 4); 66*cdf0e10cSrcweir ScCollection(const ScCollection& rCollection); 67*cdf0e10cSrcweir virtual ~ScCollection(); 68*cdf0e10cSrcweir 69*cdf0e10cSrcweir virtual ScDataObject* Clone() const; 70*cdf0e10cSrcweir 71*cdf0e10cSrcweir void AtFree(sal_uInt16 nIndex); 72*cdf0e10cSrcweir void Free(ScDataObject* pScDataObject); 73*cdf0e10cSrcweir void FreeAll(); 74*cdf0e10cSrcweir 75*cdf0e10cSrcweir sal_Bool AtInsert(sal_uInt16 nIndex, ScDataObject* pScDataObject); 76*cdf0e10cSrcweir virtual sal_Bool Insert(ScDataObject* pScDataObject); 77*cdf0e10cSrcweir 78*cdf0e10cSrcweir ScDataObject* At(sal_uInt16 nIndex) const; 79*cdf0e10cSrcweir virtual sal_uInt16 IndexOf(ScDataObject* pScDataObject) const; 80*cdf0e10cSrcweir sal_uInt16 GetCount() const; 81*cdf0e10cSrcweir 82*cdf0e10cSrcweir ScDataObject* operator[]( const sal_uInt16 nIndex) const {return At(nIndex);} 83*cdf0e10cSrcweir ScCollection& operator=( const ScCollection& rCol ); 84*cdf0e10cSrcweir }; 85*cdf0e10cSrcweir 86*cdf0e10cSrcweir 87*cdf0e10cSrcweir class SC_DLLPUBLIC ScSortedCollection : public ScCollection 88*cdf0e10cSrcweir { 89*cdf0e10cSrcweir private: 90*cdf0e10cSrcweir sal_Bool bDuplicates; 91*cdf0e10cSrcweir protected: 92*cdf0e10cSrcweir // fuer ScStrCollection Load/Store 93*cdf0e10cSrcweir void SetDups( sal_Bool bVal ) { bDuplicates = bVal; } 94*cdf0e10cSrcweir sal_Bool IsDups() const { return bDuplicates; } 95*cdf0e10cSrcweir public: 96*cdf0e10cSrcweir ScSortedCollection(sal_uInt16 nLim = 4, sal_uInt16 nDel = 4, sal_Bool bDup = sal_False); 97*cdf0e10cSrcweir ScSortedCollection(const ScSortedCollection& rScSortedCollection) : 98*cdf0e10cSrcweir ScCollection(rScSortedCollection), 99*cdf0e10cSrcweir bDuplicates(rScSortedCollection.bDuplicates) {} 100*cdf0e10cSrcweir 101*cdf0e10cSrcweir virtual sal_uInt16 IndexOf(ScDataObject* pScDataObject) const; 102*cdf0e10cSrcweir virtual short Compare(ScDataObject* pKey1, ScDataObject* pKey2) const = 0; 103*cdf0e10cSrcweir virtual sal_Bool IsEqual(ScDataObject* pKey1, ScDataObject* pKey2) const; 104*cdf0e10cSrcweir sal_Bool Search(ScDataObject* pScDataObject, sal_uInt16& rIndex) const; 105*cdf0e10cSrcweir virtual sal_Bool Insert(ScDataObject* pScDataObject); 106*cdf0e10cSrcweir virtual sal_Bool InsertPos(ScDataObject* pScDataObject, sal_uInt16& nIndex); 107*cdf0e10cSrcweir 108*cdf0e10cSrcweir sal_Bool operator==(const ScSortedCollection& rCmp) const; 109*cdf0e10cSrcweir }; 110*cdf0e10cSrcweir 111*cdf0e10cSrcweir 112*cdf0e10cSrcweir 113*cdf0e10cSrcweir //------------------------------------------------------------------------ 114*cdf0e10cSrcweir class StrData : public ScDataObject 115*cdf0e10cSrcweir { 116*cdf0e10cSrcweir friend class ScStrCollection; 117*cdf0e10cSrcweir String aStr; 118*cdf0e10cSrcweir public: 119*cdf0e10cSrcweir StrData(const String& rStr) : aStr(rStr) {} 120*cdf0e10cSrcweir StrData(const StrData& rData) : ScDataObject(), aStr(rData.aStr) {} 121*cdf0e10cSrcweir virtual ScDataObject* Clone() const; 122*cdf0e10cSrcweir const String& GetString() const { return aStr; } 123*cdf0e10cSrcweir // SetString nur, wenn StrData nicht in ScStrCollection ist! !!! 124*cdf0e10cSrcweir // z.B. fuer Searcher 125*cdf0e10cSrcweir void SetString( const String& rNew ) { aStr = rNew; } 126*cdf0e10cSrcweir }; 127*cdf0e10cSrcweir 128*cdf0e10cSrcweir //------------------------------------------------------------------------ 129*cdf0e10cSrcweir 130*cdf0e10cSrcweir class SvStream; 131*cdf0e10cSrcweir 132*cdf0e10cSrcweir class SC_DLLPUBLIC ScStrCollection : public ScSortedCollection 133*cdf0e10cSrcweir { 134*cdf0e10cSrcweir public: 135*cdf0e10cSrcweir ScStrCollection(sal_uInt16 nLim = 4, sal_uInt16 nDel = 4, sal_Bool bDup = sal_False) : 136*cdf0e10cSrcweir ScSortedCollection ( nLim, nDel, bDup ) {} 137*cdf0e10cSrcweir ScStrCollection(const ScStrCollection& rScStrCollection) : 138*cdf0e10cSrcweir ScSortedCollection ( rScStrCollection ) {} 139*cdf0e10cSrcweir 140*cdf0e10cSrcweir virtual ScDataObject* Clone() const; 141*cdf0e10cSrcweir StrData* operator[]( const sal_uInt16 nIndex) const {return (StrData*)At(nIndex);} 142*cdf0e10cSrcweir virtual short Compare(ScDataObject* pKey1, ScDataObject* pKey2) const; 143*cdf0e10cSrcweir }; 144*cdf0e10cSrcweir 145*cdf0e10cSrcweir //------------------------------------------------------------------------ 146*cdf0e10cSrcweir // TypedScStrCollection: wie ScStrCollection, nur, dass Zahlen vor Strings 147*cdf0e10cSrcweir // sortiert werden 148*cdf0e10cSrcweir 149*cdf0e10cSrcweir class TypedStrData : public ScDataObject 150*cdf0e10cSrcweir { 151*cdf0e10cSrcweir public: 152*cdf0e10cSrcweir TypedStrData( const String& rStr, double nVal = 0.0, 153*cdf0e10cSrcweir sal_uInt16 nType = SC_STRTYPE_STANDARD ) 154*cdf0e10cSrcweir : aStrValue(rStr), 155*cdf0e10cSrcweir nValue(nVal), 156*cdf0e10cSrcweir nStrType(nType) {} 157*cdf0e10cSrcweir 158*cdf0e10cSrcweir //UNUSED2008-05 TypedStrData( ScDocument* pDoc, SCCOL nCol, SCROW nRow, SCTAB nTab, 159*cdf0e10cSrcweir //UNUSED2008-05 sal_Bool bAllStrings ); 160*cdf0e10cSrcweir 161*cdf0e10cSrcweir TypedStrData( const TypedStrData& rCpy ) 162*cdf0e10cSrcweir : ScDataObject(), 163*cdf0e10cSrcweir aStrValue(rCpy.aStrValue), 164*cdf0e10cSrcweir nValue(rCpy.nValue), 165*cdf0e10cSrcweir nStrType(rCpy.nStrType) {} 166*cdf0e10cSrcweir 167*cdf0e10cSrcweir virtual ScDataObject* Clone() const; 168*cdf0e10cSrcweir 169*cdf0e10cSrcweir sal_Bool IsStrData() const { return nStrType != 0; } 170*cdf0e10cSrcweir const String& GetString() const { return aStrValue; } 171*cdf0e10cSrcweir double GetValue () const { return nValue; } 172*cdf0e10cSrcweir 173*cdf0e10cSrcweir private: 174*cdf0e10cSrcweir friend class TypedScStrCollection; 175*cdf0e10cSrcweir 176*cdf0e10cSrcweir String aStrValue; 177*cdf0e10cSrcweir double nValue; 178*cdf0e10cSrcweir sal_uInt16 nStrType; // 0 = Value 179*cdf0e10cSrcweir }; 180*cdf0e10cSrcweir 181*cdf0e10cSrcweir class SC_DLLPUBLIC TypedScStrCollection : public ScSortedCollection 182*cdf0e10cSrcweir { 183*cdf0e10cSrcweir private: 184*cdf0e10cSrcweir sal_Bool bCaseSensitive; 185*cdf0e10cSrcweir 186*cdf0e10cSrcweir public: 187*cdf0e10cSrcweir TypedScStrCollection( sal_uInt16 nLim = 4, sal_uInt16 nDel = 4, sal_Bool bDup = sal_False ); 188*cdf0e10cSrcweir 189*cdf0e10cSrcweir TypedScStrCollection( const TypedScStrCollection& rCpy ) 190*cdf0e10cSrcweir : ScSortedCollection( rCpy ) { bCaseSensitive = rCpy.bCaseSensitive; } 191*cdf0e10cSrcweir ~TypedScStrCollection(); 192*cdf0e10cSrcweir 193*cdf0e10cSrcweir virtual ScDataObject* Clone() const; 194*cdf0e10cSrcweir virtual short Compare( ScDataObject* pKey1, ScDataObject* pKey2 ) const; 195*cdf0e10cSrcweir 196*cdf0e10cSrcweir TypedStrData* operator[]( const sal_uInt16 nIndex) const; 197*cdf0e10cSrcweir 198*cdf0e10cSrcweir void SetCaseSensitive( sal_Bool bSet ); 199*cdf0e10cSrcweir 200*cdf0e10cSrcweir sal_Bool FindText( const String& rStart, String& rResult, sal_uInt16& rPos, sal_Bool bBack ) const; 201*cdf0e10cSrcweir sal_Bool GetExactMatch( String& rString ) const; 202*cdf0e10cSrcweir }; 203*cdf0e10cSrcweir 204*cdf0e10cSrcweir #endif 205