LCOV - code coverage report
Current view: top level - include/svl - itempool.hxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 15 18 83.3 %
Date: 2014-04-11 Functions: 8 9 88.9 %
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             : #ifndef INCLUDED_SVL_ITEMPOOL_HXX
      21             : #define INCLUDED_SVL_ITEMPOOL_HXX
      22             : 
      23             : #include <limits.h>
      24             : #include <rtl/string.hxx>
      25             : #include <svl/poolitem.hxx>
      26             : #include <svl/svldllapi.h>
      27             : #include <tools/solar.h>
      28             : #include <vector>
      29             : 
      30             : class SvStream;
      31             : class SfxBroadcaster;
      32             : struct SfxItemPool_Impl;
      33             : 
      34             : #define SFX_WHICH_MAX 4999
      35             : 
      36             : #define SFX_ITEM_POOLABLE           0x0001
      37             : #define SFX_ITEM_NOT_POOLABLE       0x0002
      38             : 
      39             : struct SfxItemInfo
      40             : {
      41             :     sal_uInt16      _nSID;
      42             :     sal_uInt16      _nFlags;
      43             : };
      44             : 
      45             : class SfxStyleSheetIterator;
      46             : struct SfxPoolItemArray_Impl;
      47             : class SfxItemPool;
      48             : 
      49      156712 : class SVL_DLLPUBLIC SfxItemPoolUser
      50             : {
      51             : public:
      52             :     virtual void ObjectInDestruction(const SfxItemPool& rSfxItemPool) = 0;
      53             : 
      54             : protected:
      55      154351 :     ~SfxItemPoolUser() {}
      56             : };
      57             : 
      58             : /*  [Beschreibung]
      59             : 
      60             :     Die von dieser Klasse abgeleiteten Klassen dienen der Bereitstellung von
      61             :     Defaults von SfxPoolItems und halten konkrete (konstante) Instanzen, die
      62             :     dann von mehreren Stellen (i.d.R. eines Dokuments) referenziert werden
      63             :     k"onnen.
      64             : 
      65             :     Dadurch ist jeder Wert nur einmalig gespeichert, was zu wenig Konstruktor
      66             :     und Destruktor-Aufrufen f"ahrt, Vergleiche zwischen Items eines Dokuments
      67             :     beschleunigt und ein einfaches Laden und Speichern von Attributen
      68             :     bereitstellt.
      69             : */
      70             : class SVL_DLLPUBLIC SfxItemPool
      71             : {
      72             :     friend struct SfxItemPool_Impl;
      73             : 
      74             :     const SfxItemInfo*              pItemInfos;
      75             :     SfxItemPool_Impl*               pImp;
      76             : 
      77             : public:
      78             :     void AddSfxItemPoolUser(SfxItemPoolUser& rNewUser);
      79             :     void RemoveSfxItemPoolUser(SfxItemPoolUser& rOldUser);
      80             : 
      81             : #ifndef _SFXITEMS_HXX
      82             : private:
      83             :     sal_uInt16                      GetIndex_Impl(sal_uInt16 nWhich) const;
      84             :     sal_uInt16                      GetSize_Impl() const;
      85             : 
      86             :     SVL_DLLPRIVATE SvStream&        Load1_Impl( SvStream &rStream );
      87             :     SVL_DLLPRIVATE bool             IsItemFlag_Impl( sal_uInt16 nWhich, sal_uInt16 nFlag ) const;
      88             : 
      89             : public:
      90             :     // fuer dflt. SfxItemSet::CTOR, setze dflt. WhichRanges
      91             :     void                            FillItemIdRanges_Impl( sal_uInt16*& pWhichRanges ) const;
      92             :     const sal_uInt16*               GetFrozenIdRanges() const;
      93             : #endif
      94             : 
      95             : protected:
      96             :     static inline void              SetRefCount( SfxPoolItem& rItem, sal_uLong n );
      97             :     static inline sal_uLong         AddRef( const SfxPoolItem& rItem, sal_uLong n = 1 );
      98             :     static inline sal_uLong         ReleaseRef( const SfxPoolItem& rItem, sal_uLong n = 1);
      99             :     static inline void              SetKind( SfxPoolItem& rItem, sal_uInt16 nRef );
     100             : 
     101             : public:
     102             :                                     SfxItemPool( const SfxItemPool &rPool,
     103             :                                                  bool bCloneStaticDefaults = false );
     104             :                                     SfxItemPool( const OUString &rName,
     105             :                                                  sal_uInt16 nStart, sal_uInt16 nEnd,
     106             :                                                  const SfxItemInfo *pItemInfos,
     107             :                                                  SfxPoolItem **pDefaults = 0,
     108             :                                                  bool bLoadRefCounts = true );
     109             : 
     110             : protected:
     111             :     virtual                         ~SfxItemPool();
     112             : 
     113             : public:
     114             :     static void Free(SfxItemPool* pPool);
     115             : 
     116             :     SfxBroadcaster&                 BC();
     117             : 
     118             :     void                            SetPoolDefaultItem( const SfxPoolItem& );
     119             :     const SfxPoolItem*              GetPoolDefaultItem( sal_uInt16 nWhich ) const;
     120             :     void                            ResetPoolDefaultItem( sal_uInt16 nWhich );
     121             : 
     122             :     void                            SetDefaults( SfxPoolItem **pDefaults );
     123             :     void                            ReleaseDefaults( bool bDelete = false );
     124             :     static void                     ReleaseDefaults( SfxPoolItem **pDefaults, sal_uInt16 nCount, bool bDelete = false );
     125             : 
     126             :     virtual SfxMapUnit              GetMetric( sal_uInt16 nWhich ) const;
     127             :     void                            SetDefaultMetric( SfxMapUnit eNewMetric );
     128             : 
     129             :     /** Request string representation of pool items
     130             : 
     131             :         This virtual function produces a string representation, of
     132             :         from the respective SfxItemPool subclass' known SfxPoolItems.
     133             : 
     134             :         Subclasses, please overwrite this method, and handle
     135             :         SfxPoolItems that don't return useful/complete information on
     136             :         SfxPoolItem::GetPresentation()
     137             : 
     138             :         This baseclass yields the unmodified string representation of
     139             :         rItem.
     140             : 
     141             :         @param[in] rItem
     142             :         SfxPoolItem to query the string representation of
     143             : 
     144             :         @param[in] ePresent
     145             :         requested kind of representation - see SfxItemPresentation
     146             : 
     147             :         @param[in] eMetric
     148             :         requested unit of measure of the representation
     149             : 
     150             :         @param[out] rText
     151             :         string representation of 'rItem'
     152             :     */
     153             :     virtual SfxItemPresentation     GetPresentation( const SfxPoolItem& rItem,
     154             :                                         SfxItemPresentation ePresentation,
     155             :                                         SfxMapUnit          ePresentationMetric,
     156             :                                         OUString&           rText,
     157             :                                         const IntlWrapper * pIntlWrapper
     158             :                                          = 0 ) const;
     159             :     virtual SfxItemPool*            Clone() const;
     160             :     const OUString&            GetName() const;
     161             : 
     162             :     virtual const SfxPoolItem&      Put( const SfxPoolItem&, sal_uInt16 nWhich = 0 );
     163             :     virtual void                    Remove( const SfxPoolItem& );
     164             :     virtual const SfxPoolItem&      GetDefaultItem( sal_uInt16 nWhich ) const;
     165             : 
     166             :     const SfxPoolItem*              LoadItem( SvStream &rStream,
     167             :                                               bool bDirect = false,
     168             :                                               const SfxItemPool *pRefPool = 0 );
     169             :     bool                            StoreItem( SvStream &rStream,
     170             :                                                const SfxPoolItem &rItem,
     171             :                                                bool bDirect = false ) const;
     172             : 
     173             :     sal_uInt32                      GetSurrogate(const SfxPoolItem *) const;
     174             :     const SfxPoolItem *             GetItem2(sal_uInt16 nWhich, sal_uInt32 nSurrogate) const;
     175             :     sal_uInt32                      GetItemCount2(sal_uInt16 nWhich) const;
     176             :     const SfxPoolItem*              LoadSurrogate(SvStream& rStream,
     177             :                                             sal_uInt16 &rWhich, sal_uInt16 nSlotId,
     178             :                                             const SfxItemPool* pRefPool = 0 );
     179             :     bool                            StoreSurrogate(SvStream& rStream,
     180             :                                             const SfxPoolItem *pItem ) const;
     181             : 
     182             :     virtual SvStream &              Load(SvStream &);
     183             :     virtual SvStream &              Store(SvStream &) const;
     184             :     bool                            HasPersistentRefCounts() const;
     185             :     void                            LoadCompleted();
     186             : 
     187             :     sal_uInt16                      GetFirstWhich() const;
     188             :     sal_uInt16                      GetLastWhich() const;
     189             :     bool                            IsInRange( sal_uInt16 nWhich ) const;
     190             :     bool                            IsInVersionsRange( sal_uInt16 nWhich ) const;
     191             :     bool                            IsInStoringRange( sal_uInt16 nWhich ) const;
     192             :     void                            SetStoringRange( sal_uInt16 nFrom, sal_uInt16 nTo );
     193             :     void                            SetSecondaryPool( SfxItemPool *pPool );
     194             :     SfxItemPool*                    GetSecondaryPool() const;
     195             : #ifdef DBG_UTIL
     196             :     SfxItemPool*                    GetMasterPool() const;
     197             : #endif
     198             :     void                            FreezeIdRanges();
     199             : 
     200             :     void                            Delete();
     201             : 
     202             :     bool                            IsItemFlag( sal_uInt16 nWhich, sal_uInt16 nFlag ) const;
     203     8380983 :     bool                            IsItemFlag( const SfxPoolItem &rItem, sal_uInt16 nFlag ) const
     204     8380983 :                                     { return IsItemFlag( rItem.Which(), nFlag ); }
     205             :     void                            SetItemInfos( const SfxItemInfo *pInfos );
     206             :     sal_uInt16                      GetWhich( sal_uInt16 nSlot, bool bDeep = true ) const;
     207             :     sal_uInt16                      GetSlotId( sal_uInt16 nWhich, bool bDeep = true ) const;
     208             :     sal_uInt16                      GetTrueWhich( sal_uInt16 nSlot, bool bDeep = true ) const;
     209             :     sal_uInt16                      GetTrueSlotId( sal_uInt16 nWhich, bool bDeep = true ) const;
     210             : 
     211             :     void                            SetVersionMap( sal_uInt16 nVer,
     212             :                                                    sal_uInt16 nOldStart, sal_uInt16 nOldEnd,
     213             :                                                    const sal_uInt16 *pWhichIdTab );
     214             :     sal_uInt16                      GetNewWhich( sal_uInt16 nOldWhich ) const;
     215             :     sal_uInt16                      GetVersion() const;
     216             :     void                            SetFileFormatVersion( sal_uInt16 nFileFormatVersion );
     217             :     bool                            IsCurrentVersionLoading() const;
     218             : 
     219      133131 :     static bool                     IsWhich(sal_uInt16 nId) {
     220      133131 :                                         return nId && nId <= SFX_WHICH_MAX; }
     221     2542034 :     static bool                     IsSlot(sal_uInt16 nId) {
     222     2542034 :                                         return nId && nId > SFX_WHICH_MAX; }
     223             : 
     224             :     static const SfxItemPool*       GetStoringPool();
     225             : 
     226             : private:
     227             :     const SfxItemPool&              operator=(const SfxItemPool &);   // n.i.!!
     228             : 
     229             :     static const SfxItemPool*       pStoringPool_;
     230             : };
     231             : 
     232             : // nur der Pool darf den Referenz-Zaehler manipulieren !!!
     233      703405 : inline void SfxItemPool::SetRefCount( SfxPoolItem& rItem, sal_uLong n )
     234             : {
     235      703405 :     rItem.SetRefCount(n);
     236      703405 : }
     237             : 
     238             : // nur der Pool darf den Referenz-Zaehler manipulieren !!!
     239    15874735 : inline sal_uLong SfxItemPool::AddRef( const SfxPoolItem& rItem, sal_uLong n )
     240             : {
     241    15874735 :     return rItem.AddRef(n);
     242             : }
     243             : 
     244             : // nur der Pool darf den Referenz-Zaehler manipulieren !!!
     245     4291804 : inline sal_uLong SfxItemPool::ReleaseRef( const SfxPoolItem& rItem, sal_uLong n )
     246             : {
     247     4291804 :     return rItem.ReleaseRef(n);
     248             : }
     249             : 
     250           0 : inline void SfxItemPool::SetKind( SfxPoolItem& rItem, sal_uInt16 nRef )
     251             : {
     252           0 :     rItem.SetKind( nRef );
     253           0 : }
     254             : 
     255             : #endif
     256             : 
     257             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10