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