xref: /trunk/main/svl/inc/svl/itemset.hxx (revision 43f0f119)
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 #ifndef _SFXITEMSET_HXX
24 #define _SFXITEMSET_HXX
25 
26 #include "svl/svldllapi.h"
27 
28 #include <cstdarg> 	// std::va_list and friends
29 #include <svl/poolitem.hxx>
30 #include <tools/rtti.hxx>
31 #include <tools/solar.h>
32 
33 class SfxItemPool;
34 class SfxPoolItem;
35 class SvStream;
36 
37 typedef SfxPoolItem const** SfxItemArray;
38 
39 #define USHORT_ARG int
40 
41 #ifdef MI_HATS_REPARIERT
42 #ifndef DBG
43 #ifdef DBG_UTILx
44 #define DBG(s) s
45 #define _pChildCount(THIS)  (  *(sal_uInt16**)SfxPointerServer::GetServer()->GetPointer(THIS) )
46 #define _pChildCountCtor	( (*(sal_uInt16**)SfxPointerServer::GetServer()->CreatePointer(this)) = new sal_uInt16 )
47 #define _pChildCountDtor	( SfxPointerServer::GetServer()->ReleasePointer(this) )
48 #else
49 #define DBG(s)
50 #endif
51 #endif
52 #else
53 #ifdef DBG
54 #undef DBG
55 #endif
56 #define DBG(s)
57 #endif
58 
59 //========================================================================
60 
61 #define SFX_ITEMSET_GET( rSet, pItem, ItemType, nSlotId, bDeep ) \
62 	const ItemType *pItem = (const ItemType*) \
63 							(rSet).GetItem( nSlotId, bDeep, TYPE(ItemType) )
64 
65 //========================================================================
66 
67 class SVL_DLLPUBLIC SfxItemSet
68 {
69 	friend class SfxItemIter;
70 
71 	SfxItemPool*				_pPool; 		// der verwendete Pool
72 	const SfxItemSet*           _pParent;       // Ableitung
73 	SfxItemArray                _aItems;        // Item-Feld
74 	sal_uInt16*                     _pWhichRanges;  // Array von Which-Bereichen
75 	sal_uInt16                      _nCount;        // Anzahl Items
76 
77 	//optimize a comparing operation from 'memcmp' to 'hash compare' to improve xls loading performance, i120575
78 	sal_Int32 _aHashKey; //hash result of array of points: _aItems.
79 
80 	void UpdateHashKey();
81 	//Need invlidate the hashkey at every possible place where the array _aItems may be changed.
82 	//thread safe : there is always solarmutex outter, so no need to add mutex here.
InvalidateHashKey()83 	void InvalidateHashKey() { _aHashKey = 0;} //treat '0' as an invalidate key.
IsValidateHashKey() const84 	sal_Bool IsValidateHashKey() const { return (0!=_aHashKey);}
GetHashKey() const85 	sal_Int32 GetHashKey() const { return _aHashKey; }
86 	//end:i120575
87 	//---------------------------------------------------------------------
88 #ifndef _SFXITEMS_HXX
89 
90 friend class SfxItemPoolCache;
91 friend class SfxAllItemSet;
92 friend const char *DbgCheckItemSet( const void* );
93 
94 private:
95 	SVL_DLLPRIVATE void						InitRanges_Impl(const sal_uInt16 *nWhichPairTable);
96 	SVL_DLLPRIVATE void						InitRanges_Impl(va_list pWhich, sal_uInt16 n1, sal_uInt16 n2, sal_uInt16 n3);
97 	SVL_DLLPRIVATE void						InitRanges_Impl(sal_uInt16 nWh1, sal_uInt16 nWh2);
98 
99 public:
100 	//optimize a comparing operation from 'memcmp' to 'hash compare' to improve xls loading performance, i120575
101 	//Make this method public is dangerous, may disrupt the item array. so invalidate the hash key here.
102 	//currently this method is never called, pls also do not do it in future.
GetItems_Impl() const103 	SfxItemArray	GetItems_Impl() const
104 	{
105 		const_cast<SfxItemSet &>(*this).InvalidateHashKey();
106 		return _aItems;
107 	}//end:i120575
108 
109 #endif
110 	//---------------------------------------------------------------------
111 
112 private:
113 	const SfxItemSet&			operator=(const SfxItemSet &);	 // n.i.!!
114 
115 protected:
116 	// Notification-Callback
117 	virtual void				Changed( const SfxPoolItem& rOld, const SfxPoolItem& rNew );
118 
119 	// direkte Put-Methode
120 	int 						PutDirect(const SfxPoolItem &rItem);
121 
122 public:
123 								SfxItemSet( const SfxItemSet& );
124 
125 								SfxItemSet( SfxItemPool&, sal_Bool bTotalPoolRanges = sal_False );
126 								SfxItemSet( SfxItemPool&, sal_uInt16 nWhich1, sal_uInt16 nWhich2 );
127 								SfxItemSet( SfxItemPool&, USHORT_ARG nWh1, USHORT_ARG nWh2, USHORT_ARG nNull, ... );
128 								SfxItemSet( SfxItemPool&, const sal_uInt16* nWhichPairTable );
129 	virtual                     ~SfxItemSet();
130 
131 	virtual SfxItemSet *		Clone(sal_Bool bItems = sal_True, SfxItemPool *pToPool = 0) const;
132 
133 	// Items erfragen
Count() const134 	sal_uInt16						Count() const { return _nCount; }
135 	sal_uInt16						TotalCount() const;
136 
137 	virtual	const SfxPoolItem&	Get( sal_uInt16 nWhich, sal_Bool bSrchInParent = sal_True ) const;
138 	const SfxPoolItem*  		GetItem( sal_uInt16 nWhich, sal_Bool bSrchInParent = sal_True,
139 										 TypeId aItemType = 0 ) const;
140 
141 	// Which-Wert des Items an der Position nPos erfragen
142 	sal_uInt16						GetWhichByPos(sal_uInt16 nPos) const;
143 
144 	// Item-Status erfragen
145 	SfxItemState				GetItemState(	sal_uInt16 nWhich,
146 												sal_Bool bSrchInParent = sal_True,
147 												const SfxPoolItem **ppItem = 0 ) const;
148 
149 	virtual void				DisableItem(sal_uInt16 nWhich);
150 	virtual void				InvalidateItem( sal_uInt16 nWhich );
151 	virtual sal_uInt16              ClearItem( sal_uInt16 nWhich = 0);
152 	virtual void				ClearInvalidItems( sal_Bool bHardDefault = sal_False );
153 			void 				InvalidateAllItems(); HACK(via nWhich = 0)
154 
155 	inline void 				SetParent( const SfxItemSet* pNew );
156 
157 	// Items hinzufuegen, loeschen etc.
158 	virtual const SfxPoolItem*	Put( const SfxPoolItem&, sal_uInt16 nWhich );
Put(const SfxPoolItem & rItem)159 	const SfxPoolItem*			Put( const SfxPoolItem& rItem )
160 								{ return Put(rItem, rItem.Which()); }
161 	virtual int 				Put( const SfxItemSet&,
162 									 sal_Bool bInvalidAsDefault = sal_True );
163 	void						PutExtended( const SfxItemSet&,
164 											 SfxItemState eDontCareAs = SFX_ITEM_UNKNOWN,
165 											 SfxItemState eDefaultAs = SFX_ITEM_UNKNOWN );
166 
167 	virtual int 				Set( const SfxItemSet&, sal_Bool bDeep = sal_True );
168 
169 	virtual void				Intersect( const SfxItemSet& rSet );
170 	virtual void				MergeValues( const SfxItemSet& rSet, sal_Bool bOverwriteDefaults = sal_False );
171 	virtual void				Differentiate( const SfxItemSet& rSet );
172 	virtual void				MergeValue( const SfxPoolItem& rItem, sal_Bool bOverwriteDefaults = sal_False  );
173 
GetPool() const174 	SfxItemPool*				GetPool() const { return _pPool; }
GetRanges() const175 	const sal_uInt16*				GetRanges() const { return _pWhichRanges; }
176 	void						SetRanges( const sal_uInt16 *pRanges );
177 	void						MergeRange( sal_uInt16 nFrom, sal_uInt16 nTo );
GetParent() const178 	const SfxItemSet*			GetParent() const { return _pParent; }
179 
180 	virtual SvStream &			Load( SvStream &, FASTBOOL bDirect = sal_False,
181 									  const SfxItemPool *pRefPool = 0 );
182 	virtual SvStream &			Store( SvStream &, FASTBOOL bDirect = sal_False ) const;
183 
184 	virtual int                 operator==(const SfxItemSet &) const;
185 
186 	//optimize a comparing operation from 'memcmp' to 'hash compare' to improve xls loading performance, i120575
187 	//in some situation (e.g.. ScPatternAttr::operator== ),
188 	//two sfxitemset can be compared 'quickly' by the Hashkey only.
189 	//may also update the hashkey in this method.
190 	sal_Bool QuickCompare( SfxItemSet & rCmp);
191 	//end:i120575
192 };
193 
194 // --------------- Inline Implementierungen ------------------------
195 
SetParent(const SfxItemSet * pNew)196 inline void SfxItemSet::SetParent( const SfxItemSet* pNew )
197 {
198 	DBG( if (_pParent) --*_pChildCount(_pParent) );
199 	_pParent = pNew;
200 	DBG( if (_pParent) ++*_pChildCount(_pParent) );
201 }
202 
203 //========================================================================
204 
205 class SVL_DLLPUBLIC SfxAllItemSet: public SfxItemSet
206 
207 /*  versteht alle Ranges; werden durch das Putten der Items
208 	automatisch angepasst
209 */
210 
211 {
212 	SfxVoidItem 				aDefault;
213 	sal_uInt16 						nFree;
214 
215 public:
216 								SfxAllItemSet( SfxItemPool &rPool );
217 								SfxAllItemSet( const SfxItemSet & );
218 								SfxAllItemSet( const SfxAllItemSet & );
219 
220 	virtual SfxItemSet *		Clone( sal_Bool bItems = sal_True, SfxItemPool *pToPool = 0 ) const;
221 	virtual const SfxPoolItem*	Put( const SfxPoolItem&, sal_uInt16 nWhich );
Put(const SfxPoolItem & rItem)222 	const SfxPoolItem*	        Put( const SfxPoolItem& rItem )
223 	{ return Put(rItem, rItem.Which()); }
224 	virtual int 				Put( const SfxItemSet&,
225 									 sal_Bool bInvalidAsDefault = sal_True );
226 };
227 
228 #endif // #ifndef _SFXITEMSET_HXX
229 
230