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 { return nCount
; }
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;
147 void Load( SvStream
& );
148 void Store( SvStream
& ) const;
151 //------------------------------------------------------------------------
152 // TypedScStrCollection: wie ScStrCollection, nur, dass Zahlen vor Strings
155 class TypedStrData
: public ScDataObject
158 TypedStrData( const String
& rStr
, double nVal
= 0.0,
159 USHORT nType
= SC_STRTYPE_STANDARD
)
164 //UNUSED2008-05 TypedStrData( ScDocument* pDoc, SCCOL nCol, SCROW nRow, SCTAB nTab,
165 //UNUSED2008-05 BOOL bAllStrings );
167 TypedStrData( const TypedStrData
& rCpy
)
169 aStrValue(rCpy
.aStrValue
),
171 nStrType(rCpy
.nStrType
) {}
173 virtual ScDataObject
* Clone() const;
175 BOOL
IsStrData() const { return nStrType
!= 0; }
176 const String
& GetString() const { return aStrValue
; }
177 double GetValue () const { return nValue
; }
180 friend class TypedScStrCollection
;
181 #if OLD_PIVOT_IMPLEMENTATION
182 friend class PivotScStrCollection
;
187 USHORT nStrType
; // 0 = Value
190 class SC_DLLPUBLIC TypedScStrCollection
: public ScSortedCollection
196 TypedScStrCollection( USHORT nLim
= 4, USHORT nDel
= 4, BOOL bDup
= FALSE
)
197 : ScSortedCollection( nLim
, nDel
, bDup
) { bCaseSensitive
= FALSE
; }
199 TypedScStrCollection( const TypedScStrCollection
& rCpy
)
200 : ScSortedCollection( rCpy
) { bCaseSensitive
= rCpy
.bCaseSensitive
; }
202 virtual ScDataObject
* Clone() const;
203 virtual short Compare( ScDataObject
* pKey1
, ScDataObject
* pKey2
) const;
205 TypedStrData
* operator[]( const USHORT nIndex
) const
206 { return (TypedStrData
*)At(nIndex
); }
208 void SetCaseSensitive( BOOL bSet
) { bCaseSensitive
= bSet
; }
210 BOOL
FindText( const String
& rStart
, String
& rResult
, USHORT
& rPos
, BOOL bBack
) const;
211 BOOL
GetExactMatch( String
& rString
) const;