GPU-Calc: remove Alloc_Host_Ptr for clmem of NAN vector
[LibreOffice.git] / svl / source / items / poolitem.cxx
blob3147c5c5e84df72e1456b491621523adb9e4d00b
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 #include <svl/poolitem.hxx>
22 #include <tools/stream.hxx>
24 // STATIC DATA -----------------------------------------------------------
26 DBG_NAME(SfxPoolItem)
27 DBG_NAME(SfxVoidItem)
28 // @@@ DBG_NAME(SfxInvalidItem);
29 DBG_NAME(SfxItemHandle)
31 // RTTI ------------------------------------------------------------------
33 TYPEINIT0(SfxPoolItem);
34 TYPEINIT1(SfxVoidItem, SfxPoolItem);
35 // @@@ TYPEINIT1(SfxInvalidItem, SfxPoolItem);
36 TYPEINIT1(SfxSetItem, SfxPoolItem);
37 // @@@ TYPEINIT1(SfxItemChangedHint, SfxHint);
39 // ------------------------------------------------------------------------
40 #if OSL_DEBUG_LEVEL > 1
41 static sal_uLong nItemCount = 0;
43 const char* pw1 = "Wow! 10.000 items!";
44 const char* pw2 = "Wow! 100.000 items!";
45 const char* pw3 = "Wow! 1.000.000 items!";
46 const char* pw4 = "Wow! 50.000.000 items!";
47 const char* pw5 = "Wow! 10.000.000 items!";
48 #endif
50 IMPL_PTRHINT(SfxPoolItemHint,SfxPoolItem)
52 // SfxPoolItem -----------------------------------------------------------
53 SfxPoolItem::SfxPoolItem(sal_uInt16 const nWhich)
54 : m_nRefCount(0)
55 , m_nWhich(nWhich)
56 , m_nKind(0)
58 DBG_CTOR(SfxPoolItem, 0);
59 DBG_ASSERT(nWhich <= SHRT_MAX, "invalid WhichId");
60 #if OSL_DEBUG_LEVEL > 1
61 ++nItemCount;
62 if ( pw1 && nItemCount>=10000 )
64 DBG_WARNING( pw1 );
65 pw1 = NULL;
67 if ( pw2 && nItemCount>=100000 )
69 DBG_WARNING( pw2 );
70 pw2 = NULL;
72 if ( pw3 && nItemCount>=1000000 )
74 DBG_WARNING( pw3 );
75 pw3 = NULL;
77 if ( pw4 && nItemCount>=5000000 )
79 DBG_WARNING( pw4 );
80 pw4 = NULL;
82 if ( pw5 && nItemCount>=10000000 )
84 DBG_WARNING( pw5 );
85 pw5 = NULL;
87 #endif
90 // -----------------------------------------------------------------------
91 SfxPoolItem::SfxPoolItem( const SfxPoolItem& rCpy )
92 : m_nRefCount(0) // don't copy that
93 , m_nWhich(rCpy.Which()) // call function because of ChkThis() (WTF does that mean?)
94 , m_nKind( 0 )
96 DBG_CTOR(SfxPoolItem, 0);
97 #if OSL_DEBUG_LEVEL > 1
98 ++nItemCount;
99 if ( pw1 && nItemCount>=10000 )
101 DBG_WARNING( pw1 );
102 pw1 = NULL;
104 if ( pw2 && nItemCount>=100000 )
106 DBG_WARNING( pw2 );
107 pw2 = NULL;
109 if ( pw3 && nItemCount>=1000000 )
111 DBG_WARNING( pw3 );
112 pw3 = NULL;
114 if ( pw4 && nItemCount>=5000000 )
116 DBG_WARNING( pw4 );
117 pw4 = NULL;
119 if ( pw5 && nItemCount>=10000000 )
121 DBG_WARNING( pw5 );
122 pw5 = NULL;
124 #endif
127 // ------------------------------------------------------------------------
128 SfxPoolItem::~SfxPoolItem()
130 DBG_DTOR(SfxPoolItem, 0);
131 DBG_ASSERT(m_nRefCount == 0 || m_nRefCount > SFX_ITEMS_MAXREF,
132 "destroying item in use");
133 #if OSL_DEBUG_LEVEL > 1
134 --nItemCount;
135 #endif
138 // ------------------------------------------------------------------------
139 int SfxPoolItem::Compare( const SfxPoolItem& ) const
141 return 0;
144 // ------------------------------------------------------------------------
145 int SfxPoolItem::Compare( const SfxPoolItem& rWith, const IntlWrapper& ) const
147 return Compare( rWith );
150 // ------------------------------------------------------------------------
151 int SfxPoolItem::operator==( const SfxPoolItem& rCmp ) const
153 DBG_CHKTHIS(SfxPoolItem, 0);
154 return rCmp.Type() == Type();
157 // -----------------------------------------------------------------------
158 SfxPoolItem* SfxPoolItem::Create(SvStream &, sal_uInt16) const
160 DBG_CHKTHIS(SfxPoolItem, 0);
161 return Clone(0);
164 // -----------------------------------------------------------------------
165 sal_uInt16 SfxPoolItem::GetVersion( sal_uInt16 ) const
167 DBG_CHKTHIS(SfxPoolItem, 0);
168 return 0;
171 // -----------------------------------------------------------------------
172 SvStream& SfxPoolItem::Store(SvStream &rStream, sal_uInt16 ) const
174 DBG_CHKTHIS(SfxPoolItem, 0);
175 return rStream;
178 // static
179 OUString SfxPoolItem::readByteString(SvStream& rStream)
181 return rStream.ReadUniOrByteString(rStream.GetStreamCharSet());
184 // static
185 void SfxPoolItem::writeByteString(SvStream & rStream, const OUString& rString)
187 rStream.WriteUniOrByteString(rString, rStream.GetStreamCharSet());
190 // static
191 OUString SfxPoolItem::readUnicodeString(SvStream & rStream, bool bUnicode)
193 return rStream.ReadUniOrByteString(bUnicode ? RTL_TEXTENCODING_UCS2 :
194 rStream.GetStreamCharSet());
197 // static
198 void SfxPoolItem::writeUnicodeString(SvStream & rStream, const OUString& rString)
200 rStream.WriteUniOrByteString(rString, RTL_TEXTENCODING_UCS2);
203 // ------------------------------------------------------------------------
204 SfxItemPresentation SfxPoolItem::GetPresentation
206 SfxItemPresentation /*ePresentation*/, // IN: wie formatiert werden soll
207 SfxMapUnit /*eCoreMetric*/, // IN: Ma\seinheit des SfxPoolItems
208 SfxMapUnit /*ePresentationMetric*/, // IN: Wunsch-Ma\einheit der Darstellung
209 OUString& /*rText*/, // OUT: textuelle Darstellung
210 const IntlWrapper *
211 ) const
213 /* [Beschreibung]
215 "Uber diese virtuelle Methode kann von den SfxPoolItem-Subklassen
216 eine textuelle Datstellung des Wertes erhalten werden. Sie sollte
217 von allen UI-relevanten SfxPoolItem-Subklassen "uberladen werden.
219 Da die Ma\seinheit des Wertes im SfxItemPool nur "uber
220 <SfxItemPool::GetMetric(sal_uInt16)const> erfragbar ist, und nicht etwa
221 in der SfxPoolItem-Instanz oder -Subklasse verf"ugbar ist, wird die
222 eigene Ma\seinheit als 'eCoreMetric' "ubergeben.
224 Die darzustellende Ma\seinheit wird als 'ePresentationMetric'
225 "ubergeben.
228 [R"uckgabewert]
230 SfxItemPresentation SFX_ITEM_PRESENTATION_NONE
231 es konnte keine Text-Darstellung erzeugt werden
233 SFX_ITEM_PRESENTATION_NAMELESS
234 es konnte eine Text-Darstellung (ggf. mit
235 Ma\seinheit) erzeugt werden, die jedoch keine
236 semantische Bedeutung enth"alt
238 SFX_ITEM_PRESENTATION_COMPLETE
239 es konnte eine komplette Text-Darstellung mit
240 semantischer Bedeutung (und ggf. Ma\seinheit)
241 erzeugt werden
244 [Beispiele]
246 pSvxFontItem->GetPresentation( SFX_PRESENTATION_NAMELESS, ... )
247 "12pt" mit return SFX_ITEM_PRESENTATION_NAMELESS
249 pSvxColorItem->GetPresentation( SFX_PRESENTATION_COMPLETE, ... )
250 "rot" mit return SFX_ITEM_PRESENTATION_NAMELESS
251 (das das SvxColorItem nicht wei\s, was f"ur eine Farbe es darstellt,
252 kann es keinen Namen angeben, was durch den Returnwert mitgeteilt wird.
254 pSvxBorderItem->GetPresentation( SFX_PRESENTATION_COMPLETE, ... )
255 "1cm oberer Rand, 2cm linker Rand, 0,2cm unterer Rand, ..."
259 return SFX_ITEM_PRESENTATION_NONE;
262 // SfxVoidItem ------------------------------------------------------------
263 SfxVoidItem::SfxVoidItem( sal_uInt16 which ):
264 SfxPoolItem(which)
266 DBG_CTOR(SfxVoidItem, 0);
269 // SfxVoidItem ------------------------------------------------------------
270 SfxVoidItem::SfxVoidItem( const SfxVoidItem& rCopy):
271 SfxPoolItem(rCopy)
273 DBG_CTOR(SfxVoidItem, 0);
276 // ------------------------------------------------------------------------
277 int SfxVoidItem::operator==( const SfxPoolItem&
278 #ifdef DBG_UTIL
279 rCmp
280 #endif
281 ) const
283 DBG_CHKTHIS(SfxVoidItem, 0);
284 DBG_ASSERT( SfxPoolItem::operator==( rCmp ), "unequal type" );
285 return sal_True;
288 // ------------------------------------------------------------------------
289 SfxItemPresentation SfxVoidItem::GetPresentation
291 SfxItemPresentation /*ePresentation*/,
292 SfxMapUnit /*eCoreMetric*/,
293 SfxMapUnit /*ePresentationMetric*/,
294 OUString& rText,
295 const IntlWrapper *
296 ) const
298 DBG_CHKTHIS(SfxVoidItem, 0);
299 rText = "Void";
300 return SFX_ITEM_PRESENTATION_NAMELESS;
303 // ------------------------------------------------------------------------
304 SfxPoolItem* SfxVoidItem::Clone(SfxItemPool *) const
306 DBG_CHKTHIS(SfxVoidItem, 0);
307 return new SfxVoidItem(*this);
310 // SfxInvalidItem ---------------------------------------------------------
312 // SfxItemHandle ----------------------------------------------------------
313 SfxItemHandle::SfxItemHandle(SfxPoolItem &rItem):
314 pRef(new sal_uInt16(1)),
315 pItem(rItem.Clone(0))
317 DBG_CTOR(SfxItemHandle, 0);
320 // ------------------------------------------------------------------------
321 SfxItemHandle::SfxItemHandle(const SfxItemHandle &rCopy):
322 pRef(rCopy.pRef),
323 pItem(rCopy.pItem)
325 DBG_CTOR(SfxItemHandle, 0);
326 ++(*pRef);
329 // ------------------------------------------------------------------------
330 const SfxItemHandle &SfxItemHandle::operator=(const SfxItemHandle &rCopy)
332 DBG_CHKTHIS(SfxItemHandle, 0);
333 if(&rCopy == this || pItem == rCopy.pItem)
334 return *this;
335 --(*pRef);
336 if(!(*pRef))
338 delete pItem;
339 pItem = 0;
341 pRef = rCopy.pRef;
342 ++(*pRef);
343 pItem = rCopy.pItem;
344 return *this;
347 // ------------------------------------------------------------------------
348 SfxItemHandle::~SfxItemHandle()
350 DBG_DTOR(SfxItemHandle, 0);
351 --(*pRef);
352 if(!(*pRef)) {
353 delete pRef; pRef = 0;
354 delete pItem; pItem = 0;
358 // ------------------------------------------------------------------------
359 bool SfxPoolItem::ScaleMetrics( long /*lMult*/, long /*lDiv*/ )
361 return false;
364 // ------------------------------------------------------------------------
365 bool SfxPoolItem::HasMetrics() const
367 return false;
370 // -----------------------------------------------------------------------
372 bool SfxPoolItem::QueryValue( com::sun::star::uno::Any&, sal_uInt8 ) const
374 OSL_FAIL("There is no implementation for QueryValue for this item!");
375 return false;
378 // -----------------------------------------------------------------------
380 bool SfxPoolItem::PutValue( const com::sun::star::uno::Any&, sal_uInt8 )
382 OSL_FAIL("There is no implementation for PutValue for this item!");
383 return false;
386 SfxVoidItem::~SfxVoidItem()
388 DBG_DTOR(SfxVoidItem, 0);
391 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */