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