1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
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
39 #define INCLUDED_LIMITS_H
43 #define MAXCOLLECTIONSIZE 16384
45 #define SCPOS_INVALID USHRT_MAX
47 #define SC_STRTYPE_VALUE 0
48 #define SC_STRTYPE_STANDARD 1
52 class SC_DLLPUBLIC ScDataObject
56 virtual ~ScDataObject();
57 virtual ScDataObject
* Clone() const = 0;
60 class SC_DLLPUBLIC ScCollection
: public ScDataObject
66 ScDataObject
** pItems
;
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
);
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
95 // fuer ScStrCollection Load/Store
96 void SetDups( BOOL bVal
) { bDuplicates
= bVal
; }
97 BOOL
IsDups() const { return bDuplicates
; }
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
;
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 //------------------------------------------------------------------------
135 class SC_DLLPUBLIC ScStrCollection
: public ScSortedCollection
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
152 class TypedStrData
: public ScDataObject
155 TypedStrData( const String
& rStr
, double nVal
= 0.0,
156 USHORT nType
= SC_STRTYPE_STANDARD
)
161 //UNUSED2008-05 TypedStrData( ScDocument* pDoc, SCCOL nCol, SCROW nRow, SCTAB nTab,
162 //UNUSED2008-05 BOOL bAllStrings );
164 TypedStrData( const TypedStrData
& rCpy
)
166 aStrValue(rCpy
.aStrValue
),
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
; }
177 friend class TypedScStrCollection
;
181 USHORT nStrType
; // 0 = Value
184 class SC_DLLPUBLIC TypedScStrCollection
: public ScSortedCollection
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;