LCOV - code coverage report
Current view: top level - libreoffice/svl/source/items - poolitem.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 32 84 38.1 %
Date: 2012-12-27 Functions: 29 53 54.7 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       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/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      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 .
      18             :  */
      19             : 
      20             : 
      21             : #include <svl/poolitem.hxx>
      22             : #include <tools/stream.hxx>
      23             : 
      24             : // STATIC DATA -----------------------------------------------------------
      25             : 
      26             : DBG_NAME(SfxPoolItem)
      27             : DBG_NAME(SfxVoidItem)
      28             : // @@@ DBG_NAME(SfxInvalidItem);
      29             : DBG_NAME(SfxItemHandle)
      30             : 
      31             : // RTTI ------------------------------------------------------------------
      32             : 
      33      804227 : TYPEINIT0(SfxPoolItem);
      34     2144380 : TYPEINIT1(SfxVoidItem, SfxPoolItem);
      35             : // @@@ TYPEINIT1(SfxInvalidItem, SfxPoolItem);
      36      363511 : TYPEINIT1(SfxSetItem, SfxPoolItem);
      37             : // @@@ TYPEINIT1(SfxItemChangedHint, SfxHint);
      38             : 
      39             : // ------------------------------------------------------------------------
      40             : #if OSL_DEBUG_LEVEL > 1
      41             : static sal_uLong nItemCount = 0;
      42             : 
      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
      49             : 
      50       59060 : IMPL_PTRHINT(SfxPoolItemHint,SfxPoolItem)
      51             : 
      52             : // SfxPoolItem -----------------------------------------------------------
      53      718748 : SfxPoolItem::SfxPoolItem( sal_uInt16 nW )
      54             :     : nRefCount( 0 ),
      55             :       nWhich( nW )
      56      718748 :       , nKind( 0 )
      57             : {
      58             :     DBG_CTOR(SfxPoolItem, 0);
      59             :     DBG_ASSERT(nW <= SHRT_MAX, "Which Bereich ueberschritten");
      60             : #if OSL_DEBUG_LEVEL > 1
      61             :     ++nItemCount;
      62             :     if ( pw1 && nItemCount>=10000 )
      63             :     {
      64             :         DBG_WARNING( pw1 );
      65             :         pw1 = NULL;
      66             :     }
      67             :     if ( pw2 && nItemCount>=100000 )
      68             :     {
      69             :         DBG_WARNING( pw2 );
      70             :         pw2 = NULL;
      71             :     }
      72             :     if ( pw3 && nItemCount>=1000000 )
      73             :     {
      74             :         DBG_WARNING( pw3 );
      75             :         pw3 = NULL;
      76             :     }
      77             :     if ( pw4 && nItemCount>=5000000 )
      78             :     {
      79             :         DBG_WARNING( pw4 );
      80             :         pw4 = NULL;
      81             :     }
      82             :     if ( pw5 && nItemCount>=10000000 )
      83             :     {
      84             :         DBG_WARNING( pw5 );
      85             :         pw5 = NULL;
      86             :     }
      87             : #endif
      88      718748 : }
      89             : 
      90             : // -----------------------------------------------------------------------
      91      296558 : SfxPoolItem::SfxPoolItem( const SfxPoolItem& rCpy )
      92             :     : nRefCount( 0 ),               // wird ja ein neues Object!
      93      296558 :       nWhich( rCpy.Which() )    // Funktion rufen wg. ChkThis()
      94      593116 :       , nKind( 0 )
      95             : {
      96             :     DBG_CTOR(SfxPoolItem, 0);
      97             : #if OSL_DEBUG_LEVEL > 1
      98             :     ++nItemCount;
      99             :     if ( pw1 && nItemCount>=10000 )
     100             :     {
     101             :         DBG_WARNING( pw1 );
     102             :         pw1 = NULL;
     103             :     }
     104             :     if ( pw2 && nItemCount>=100000 )
     105             :     {
     106             :         DBG_WARNING( pw2 );
     107             :         pw2 = NULL;
     108             :     }
     109             :     if ( pw3 && nItemCount>=1000000 )
     110             :     {
     111             :         DBG_WARNING( pw3 );
     112             :         pw3 = NULL;
     113             :     }
     114             :     if ( pw4 && nItemCount>=5000000 )
     115             :     {
     116             :         DBG_WARNING( pw4 );
     117             :         pw4 = NULL;
     118             :     }
     119             :     if ( pw5 && nItemCount>=10000000 )
     120             :     {
     121             :         DBG_WARNING( pw5 );
     122             :         pw5 = NULL;
     123             :     }
     124             : #endif
     125      296558 : }
     126             : 
     127             : // ------------------------------------------------------------------------
     128      927231 : SfxPoolItem::~SfxPoolItem()
     129             : {
     130             :     DBG_DTOR(SfxPoolItem, 0);
     131             :     DBG_ASSERT(nRefCount == 0 || nRefCount > SFX_ITEMS_MAXREF, "destroying item in use" );
     132             : #if OSL_DEBUG_LEVEL > 1
     133             :     --nItemCount;
     134             : #endif
     135      927231 : }
     136             : 
     137             : // ------------------------------------------------------------------------
     138           0 : int SfxPoolItem::Compare( const SfxPoolItem& ) const
     139             : {
     140           0 :     return 0;
     141             : }
     142             : 
     143             : // ------------------------------------------------------------------------
     144           0 : int SfxPoolItem::Compare( const SfxPoolItem& rWith, const IntlWrapper& ) const
     145             : {
     146           0 :     return Compare( rWith );
     147             : }
     148             : 
     149             : // ------------------------------------------------------------------------
     150       17500 : int SfxPoolItem::operator==( const SfxPoolItem& rCmp ) const
     151             : {
     152             :     DBG_CHKTHIS(SfxPoolItem, 0);
     153       17500 :     return rCmp.Type() == Type();
     154             : }
     155             : 
     156             : // -----------------------------------------------------------------------
     157           0 : SfxPoolItem* SfxPoolItem::Create(SvStream &, sal_uInt16) const
     158             : {
     159             :     DBG_CHKTHIS(SfxPoolItem, 0);
     160           0 :     return Clone(0);
     161             : }
     162             : 
     163             : // -----------------------------------------------------------------------
     164       63384 : sal_uInt16 SfxPoolItem::GetVersion( sal_uInt16 ) const
     165             : {
     166             :     DBG_CHKTHIS(SfxPoolItem, 0);
     167       63384 :     return 0;
     168             : }
     169             : 
     170             : // -----------------------------------------------------------------------
     171           0 : SvStream& SfxPoolItem::Store(SvStream &rStream, sal_uInt16 ) const
     172             : {
     173             :     DBG_CHKTHIS(SfxPoolItem, 0);
     174           0 :     return rStream;
     175             : }
     176             : 
     177             : //============================================================================
     178             : // static
     179           0 : rtl::OUString SfxPoolItem::readByteString(SvStream& rStream)
     180             : {
     181           0 :     return rStream.ReadUniOrByteString(rStream.GetStreamCharSet());
     182             : }
     183             : 
     184             : //============================================================================
     185             : // static
     186         888 : void SfxPoolItem::writeByteString(SvStream & rStream, const rtl::OUString& rString)
     187             : {
     188         888 :     rStream.WriteUniOrByteString(rString, rStream.GetStreamCharSet());
     189         888 : }
     190             : 
     191             : //============================================================================
     192             : // static
     193           0 : rtl::OUString SfxPoolItem::readUnicodeString(SvStream & rStream, bool bUnicode)
     194             : {
     195             :     return rStream.ReadUniOrByteString(bUnicode ? RTL_TEXTENCODING_UCS2 :
     196           0 :                                       rStream.GetStreamCharSet());
     197             : }
     198             : 
     199             : //============================================================================
     200             : // static
     201           0 : void SfxPoolItem::writeUnicodeString(SvStream & rStream, const rtl::OUString& rString)
     202             : {
     203           0 :     rStream.WriteUniOrByteString(rString, RTL_TEXTENCODING_UCS2);
     204           0 : }
     205             : 
     206             : // ------------------------------------------------------------------------
     207           0 : SfxItemPresentation SfxPoolItem::GetPresentation
     208             : (
     209             :     SfxItemPresentation /*ePresentation*/,       // IN:  wie formatiert werden soll
     210             :     SfxMapUnit          /*eCoreMetric*/,         // IN:  Ma\seinheit des SfxPoolItems
     211             :     SfxMapUnit          /*ePresentationMetric*/, // IN:  Wunsch-Ma\einheit der Darstellung
     212             :     XubString&          /*rText*/,               // OUT: textuelle Darstellung
     213             :     const IntlWrapper *
     214             : )   const
     215             : 
     216             : /*  [Beschreibung]
     217             : 
     218             :     "Uber diese virtuelle Methode kann von den SfxPoolItem-Subklassen
     219             :     eine textuelle Datstellung des Wertes erhalten werden. Sie sollte
     220             :     von allen UI-relevanten SfxPoolItem-Subklassen "uberladen werden.
     221             : 
     222             :     Da die Ma\seinheit des Wertes im SfxItemPool nur "uber
     223             :     <SfxItemPool::GetMetric(sal_uInt16)const> erfragbar ist, und nicht etwa
     224             :     in der SfxPoolItem-Instanz oder -Subklasse  verf"ugbar ist, wird die
     225             :     eigene Ma\seinheit als 'eCoreMetric' "ubergeben.
     226             : 
     227             :     Die darzustellende Ma\seinheit wird als 'ePresentationMetric'
     228             :     "ubergeben.
     229             : 
     230             : 
     231             :     [R"uckgabewert]
     232             : 
     233             :     SfxItemPresentation     SFX_ITEM_PRESENTATION_NONE
     234             :                             es konnte keine Text-Darstellung erzeugt werden
     235             : 
     236             :                             SFX_ITEM_PRESENTATION_NAMELESS
     237             :                             es konnte eine Text-Darstellung (ggf. mit
     238             :                             Ma\seinheit) erzeugt werden, die jedoch keine
     239             :                             semantische Bedeutung enth"alt
     240             : 
     241             :                             SFX_ITEM_PRESENTATION_COMPLETE
     242             :                             es konnte eine komplette Text-Darstellung mit
     243             :                             semantischer Bedeutung (und ggf. Ma\seinheit)
     244             :                             erzeugt werden
     245             : 
     246             : 
     247             :     [Beispiele]
     248             : 
     249             :     pSvxFontItem->GetPresentation( SFX_PRESENTATION_NAMELESS, ... )
     250             :         "12pt" mit return SFX_ITEM_PRESENTATION_NAMELESS
     251             : 
     252             :     pSvxColorItem->GetPresentation( SFX_PRESENTATION_COMPLETE, ... )
     253             :         "rot" mit return SFX_ITEM_PRESENTATION_NAMELESS
     254             :         (das das SvxColorItem nicht wei\s, was f"ur eine Farbe es darstellt,
     255             :         kann es keinen Namen angeben, was durch den Returnwert mitgeteilt wird.
     256             : 
     257             :     pSvxBorderItem->GetPresentation( SFX_PRESENTATION_COMPLETE, ... )
     258             :         "1cm oberer Rand, 2cm linker Rand, 0,2cm unterer Rand, ..."
     259             : */
     260             : 
     261             : {
     262           0 :     return SFX_ITEM_PRESENTATION_NONE;
     263             : }
     264             : 
     265             : // SfxVoidItem ------------------------------------------------------------
     266       10521 : SfxVoidItem::SfxVoidItem( sal_uInt16 which ):
     267       10521 :     SfxPoolItem(which)
     268             : {
     269             :     DBG_CTOR(SfxVoidItem, 0);
     270       10521 : }
     271             : 
     272             : // SfxVoidItem ------------------------------------------------------------
     273         634 : SfxVoidItem::SfxVoidItem( const SfxVoidItem& rCopy):
     274         634 :     SfxPoolItem(rCopy)
     275             : {
     276             :     DBG_CTOR(SfxVoidItem, 0);
     277         634 : }
     278             : 
     279             : // ------------------------------------------------------------------------
     280         488 : int SfxVoidItem::operator==( const SfxPoolItem&
     281             : #ifdef DBG_UTIL
     282             : rCmp
     283             : #endif
     284             : ) const
     285             : {
     286             :     DBG_CHKTHIS(SfxVoidItem, 0);
     287             :     DBG_ASSERT( SfxPoolItem::operator==( rCmp ), "unequal type" );
     288         488 :     return sal_True;
     289             : }
     290             : 
     291             : // ------------------------------------------------------------------------
     292           0 : SfxItemPresentation SfxVoidItem::GetPresentation
     293             : (
     294             :     SfxItemPresentation     /*ePresentation*/,
     295             :     SfxMapUnit              /*eCoreMetric*/,
     296             :     SfxMapUnit              /*ePresentationMetric*/,
     297             :     XubString&              rText,
     298             :     const IntlWrapper *
     299             : )   const
     300             : {
     301             :     DBG_CHKTHIS(SfxVoidItem, 0);
     302           0 :     rText.AssignAscii(RTL_CONSTASCII_STRINGPARAM("Void"));
     303           0 :     return SFX_ITEM_PRESENTATION_NAMELESS;
     304             : }
     305             : 
     306             : // ------------------------------------------------------------------------
     307         634 : SfxPoolItem* SfxVoidItem::Clone(SfxItemPool *) const
     308             : {
     309             :     DBG_CHKTHIS(SfxVoidItem, 0);
     310         634 :     return new SfxVoidItem(*this);
     311             : }
     312             : 
     313             : // SfxInvalidItem ---------------------------------------------------------
     314             : 
     315             : // SfxItemHandle ----------------------------------------------------------
     316           0 : SfxItemHandle::SfxItemHandle(SfxPoolItem &rItem):
     317             :     pRef(new sal_uInt16(1)),
     318           0 :     pItem(rItem.Clone(0))
     319             : {
     320             :     DBG_CTOR(SfxItemHandle, 0);
     321           0 : }
     322             : 
     323             : // ------------------------------------------------------------------------
     324           0 : SfxItemHandle::SfxItemHandle(const SfxItemHandle &rCopy):
     325             :     pRef(rCopy.pRef),
     326           0 :     pItem(rCopy.pItem)
     327             : {
     328             :     DBG_CTOR(SfxItemHandle, 0);
     329           0 :     ++(*pRef);
     330           0 : }
     331             : 
     332             : // ------------------------------------------------------------------------
     333           0 : const SfxItemHandle &SfxItemHandle::operator=(const SfxItemHandle &rCopy)
     334             : {
     335             :     DBG_CHKTHIS(SfxItemHandle, 0);
     336           0 :     if(&rCopy == this || pItem == rCopy.pItem)
     337           0 :         return *this;
     338           0 :     --(*pRef);
     339           0 :     if(!(*pRef))
     340             :     {
     341           0 :         delete pItem;
     342           0 :         pItem = 0;
     343             :     }
     344           0 :     pRef = rCopy.pRef;
     345           0 :     ++(*pRef);
     346           0 :     pItem = rCopy.pItem;
     347           0 :     return *this;
     348             : }
     349             : 
     350             : // ------------------------------------------------------------------------
     351           0 : SfxItemHandle::~SfxItemHandle()
     352             : {
     353             :     DBG_DTOR(SfxItemHandle, 0);
     354           0 :     --(*pRef);
     355           0 :     if(!(*pRef)) {
     356           0 :         delete pRef; pRef = 0;
     357           0 :         delete pItem; pItem = 0;
     358             :     }
     359           0 : }
     360             : 
     361             : // ------------------------------------------------------------------------
     362           0 : bool SfxPoolItem::ScaleMetrics( long /*lMult*/, long /*lDiv*/ )
     363             : {
     364           0 :     return false;
     365             : }
     366             : 
     367             : // ------------------------------------------------------------------------
     368           0 : bool SfxPoolItem::HasMetrics() const
     369             : {
     370           0 :     return false;
     371             : }
     372             : 
     373             : // -----------------------------------------------------------------------
     374             : 
     375           0 : bool SfxPoolItem::QueryValue( com::sun::star::uno::Any&, sal_uInt8 ) const
     376             : {
     377             :     OSL_FAIL("There is no implementation for QueryValue for this item!");
     378           0 :     return false;
     379             : }
     380             : 
     381             : // -----------------------------------------------------------------------
     382             : 
     383           0 : bool SfxPoolItem::PutValue( const com::sun::star::uno::Any&, sal_uInt8 )
     384             : {
     385             :     OSL_FAIL("There is no implementation for PutValue for this item!");
     386           0 :     return false;
     387             : }
     388             : 
     389       11400 : SfxVoidItem::~SfxVoidItem()
     390             : {
     391             :     DBG_DTOR(SfxVoidItem, 0);
     392       11400 : }
     393             : 
     394             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10