LCOV - code coverage report
Current view: top level - include/svl - itempool.hxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 16 19 84.2 %
Date: 2014-11-03 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      372972 : class SVL_DLLPUBLIC SfxItemPoolUser
      50             : {
      51             : public:
      52             :     virtual void ObjectInDestruction(const SfxItemPool& rSfxItemPool) = 0;
      53             : 
      54             : protected:
      55      372606 :     ~SfxItemPoolUser() {}
      56             : };
      57             : 
      58             : /** Base class for providers of defaults of SfxPoolItems.
      59             :  *
      60             :  * The derived classes hold the concrete (const) instances which are referenced in several places
      61             :  * (usually within a single document).
      62             :  * This helps to lower the amount of calls to lifecycle methods, speeds up comparisons within a document
      63             :  * and facilitates loading and saving of attributes.
      64             :  */
      65             : class SVL_DLLPUBLIC SfxItemPool
      66             : {
      67             :     friend struct SfxItemPool_Impl;
      68             : 
      69             :     const SfxItemInfo*              pItemInfos;
      70             :     SfxItemPool_Impl*               pImp;
      71             : 
      72             : public:
      73             :     void AddSfxItemPoolUser(SfxItemPoolUser& rNewUser);
      74             :     void RemoveSfxItemPoolUser(SfxItemPoolUser& rOldUser);
      75             : 
      76             : private:
      77             :     sal_uInt16                      GetIndex_Impl(sal_uInt16 nWhich) const;
      78             :     sal_uInt16                      GetSize_Impl() const;
      79             : 
      80             :     SVL_DLLPRIVATE SvStream&        Load1_Impl( SvStream &rStream );
      81             :     SVL_DLLPRIVATE bool             IsItemFlag_Impl( sal_uInt16 nWhich, sal_uInt16 nFlag ) const;
      82             : 
      83             : public:
      84             :     // for default SfxItemSet::CTOR, set default WhichRanges
      85             :     void                            FillItemIdRanges_Impl( sal_uInt16*& pWhichRanges ) const;
      86             :     const sal_uInt16*               GetFrozenIdRanges() const;
      87             : 
      88             : protected:
      89             :     static inline void              SetRefCount( SfxPoolItem& rItem, sal_uLong n );
      90             :     static inline void              AddRef( const SfxPoolItem& rItem, sal_uLong n = 1 );
      91             :     static inline sal_uLong         ReleaseRef( const SfxPoolItem& rItem, sal_uLong n = 1);
      92             :     static inline void              SetKind( SfxPoolItem& rItem, SfxItemKind nRef );
      93             : 
      94             : public:
      95             :                                     SfxItemPool( const SfxItemPool &rPool,
      96             :                                                  bool bCloneStaticDefaults = false );
      97             :                                     SfxItemPool( const OUString &rName,
      98             :                                                  sal_uInt16 nStart, sal_uInt16 nEnd,
      99             :                                                  const SfxItemInfo *pItemInfos,
     100             :                                                  SfxPoolItem **pDefaults = 0,
     101             :                                                  bool bLoadRefCounts = true );
     102             : 
     103             : protected:
     104             :     virtual                         ~SfxItemPool();
     105             : 
     106             : public:
     107             :     static void Free(SfxItemPool* pPool);
     108             : 
     109             :     SfxBroadcaster&                 BC();
     110             : 
     111             :     void                            SetPoolDefaultItem( const SfxPoolItem& );
     112             :     const SfxPoolItem*              GetPoolDefaultItem( sal_uInt16 nWhich ) const;
     113             :     void                            ResetPoolDefaultItem( sal_uInt16 nWhich );
     114             : 
     115             :     void                            SetDefaults( SfxPoolItem **pDefaults );
     116             :     void                            ReleaseDefaults( bool bDelete = false );
     117             :     static void                     ReleaseDefaults( SfxPoolItem **pDefaults, sal_uInt16 nCount, bool bDelete = false );
     118             : 
     119             :     virtual SfxMapUnit              GetMetric( sal_uInt16 nWhich ) const;
     120             :     void                            SetDefaultMetric( SfxMapUnit eNewMetric );
     121             : 
     122             :     /** Request string representation of pool items.
     123             : 
     124             :         This virtual function produces a string representation
     125             :         from the respective SfxItemPool subclass' known SfxPoolItems.
     126             : 
     127             :         Subclasses, please override this method, and handle
     128             :         SfxPoolItems that don't return useful/complete information on
     129             :         SfxPoolItem::GetPresentation()
     130             : 
     131             :         This baseclass yields the unmodified string representation of
     132             :         rItem.
     133             : 
     134             :         @param[in] rItem
     135             :         SfxPoolItem to query the string representation of
     136             : 
     137             :         @param[in] ePresent
     138             :         requested kind of representation - see SfxItemPresentation
     139             : 
     140             :         @param[in] eMetric
     141             :         requested unit of measure of the representation
     142             : 
     143             :         @param[out] rText
     144             :         string representation of 'rItem'
     145             : 
     146             :         @return true if it has a valid string representation
     147             :     */
     148             :     virtual bool                    GetPresentation( const SfxPoolItem& rItem,
     149             :                                         SfxMapUnit          ePresentationMetric,
     150             :                                         OUString&           rText,
     151             :                                         const IntlWrapper * pIntlWrapper = 0 ) const;
     152             :     virtual SfxItemPool*            Clone() const;
     153             :     const OUString&                 GetName() const;
     154             : 
     155             :     virtual const SfxPoolItem&      Put( const SfxPoolItem&, sal_uInt16 nWhich = 0 );
     156             :     virtual void                    Remove( const SfxPoolItem& );
     157             :     virtual const SfxPoolItem&      GetDefaultItem( sal_uInt16 nWhich ) const;
     158             : 
     159             :     const SfxPoolItem*              LoadItem( SvStream &rStream,
     160             :                                               bool bDirect = false,
     161             :                                               const SfxItemPool *pRefPool = 0 );
     162             :     bool                            StoreItem( SvStream &rStream,
     163             :                                                const SfxPoolItem &rItem,
     164             :                                                bool bDirect = false ) const;
     165             : 
     166             :     sal_uInt32                      GetSurrogate(const SfxPoolItem *) const;
     167             :     const SfxPoolItem *             GetItem2(sal_uInt16 nWhich, sal_uInt32 nSurrogate) const;
     168             :     const SfxPoolItem *             GetItem2Default(sal_uInt16 nWhich) const;
     169             :     sal_uInt32                      GetItemCount2(sal_uInt16 nWhich) const;
     170             :     const SfxPoolItem*              LoadSurrogate(SvStream& rStream,
     171             :                                             sal_uInt16 &rWhich, sal_uInt16 nSlotId,
     172             :                                             const SfxItemPool* pRefPool = 0 );
     173             :     bool                            StoreSurrogate(SvStream& rStream,
     174             :                                             const SfxPoolItem *pItem ) const;
     175             : 
     176             :     virtual SvStream &              Load(SvStream &);
     177             :     virtual SvStream &              Store(SvStream &) const;
     178             :     bool                            HasPersistentRefCounts() const;
     179             :     void                            LoadCompleted();
     180             : 
     181             :     sal_uInt16                      GetFirstWhich() const;
     182             :     sal_uInt16                      GetLastWhich() const;
     183             :     bool                            IsInRange( sal_uInt16 nWhich ) const;
     184             :     bool                            IsInVersionsRange( sal_uInt16 nWhich ) const;
     185             :     bool                            IsInStoringRange( sal_uInt16 nWhich ) const;
     186             :     void                            SetStoringRange( sal_uInt16 nFrom, sal_uInt16 nTo );
     187             :     void                            SetSecondaryPool( SfxItemPool *pPool );
     188             :     SfxItemPool*                    GetSecondaryPool() const;
     189             : #ifdef DBG_UTIL
     190             :     SfxItemPool*                    GetMasterPool() const;
     191             : #endif
     192             :     void                            FreezeIdRanges();
     193             : 
     194             :     void                            Delete();
     195             : 
     196             :     bool                            IsItemFlag( sal_uInt16 nWhich, sal_uInt16 nFlag ) const;
     197    23218442 :     bool                            IsItemFlag( const SfxPoolItem &rItem, sal_uInt16 nFlag ) const
     198    23218442 :                                     { return IsItemFlag( rItem.Which(), nFlag ); }
     199             :     void                            SetItemInfos( const SfxItemInfo *pInfos );
     200             :     sal_uInt16                      GetWhich( sal_uInt16 nSlot, bool bDeep = true ) const;
     201             :     sal_uInt16                      GetSlotId( sal_uInt16 nWhich, bool bDeep = true ) const;
     202             :     sal_uInt16                      GetTrueWhich( sal_uInt16 nSlot, bool bDeep = true ) const;
     203             :     sal_uInt16                      GetTrueSlotId( sal_uInt16 nWhich, bool bDeep = true ) const;
     204             : 
     205             :     void                            SetVersionMap( sal_uInt16 nVer,
     206             :                                                    sal_uInt16 nOldStart, sal_uInt16 nOldEnd,
     207             :                                                    const sal_uInt16 *pWhichIdTab );
     208             :     sal_uInt16                      GetNewWhich( sal_uInt16 nOldWhich ) const;
     209             :     sal_uInt16                      GetVersion() const;
     210             :     void                            SetFileFormatVersion( sal_uInt16 nFileFormatVersion );
     211             :     bool                            IsCurrentVersionLoading() const;
     212             : 
     213      260801 :     static bool                     IsWhich(sal_uInt16 nId) {
     214      260801 :                                         return nId && nId <= SFX_WHICH_MAX; }
     215     6531624 :     static bool                     IsSlot(sal_uInt16 nId) {
     216     6531624 :                                         return nId && nId > SFX_WHICH_MAX; }
     217             : 
     218             :     static const SfxItemPool*       GetStoringPool();
     219             : 
     220             : private:
     221             :     const SfxItemPool&              operator=(const SfxItemPool &);   // n.i.!!
     222             : 
     223             :     static const SfxItemPool*       pStoringPool_;
     224             : };
     225             : 
     226             : // only the pool may manipulate the reference counts
     227     2058112 : inline void SfxItemPool::SetRefCount( SfxPoolItem& rItem, sal_uLong n )
     228             : {
     229     2058112 :     rItem.SetRefCount(n);
     230     2058112 : }
     231             : 
     232             : // only the pool may manipulate the reference counts
     233    30083254 : inline void SfxItemPool::AddRef( const SfxPoolItem& rItem, sal_uLong n )
     234             : {
     235    30083254 :     rItem.AddRef(n);
     236    30083254 : }
     237             : 
     238             : // only the pool may manipulate the reference counts
     239    12655829 : inline sal_uLong SfxItemPool::ReleaseRef( const SfxPoolItem& rItem, sal_uLong n )
     240             : {
     241    12655829 :     return rItem.ReleaseRef(n);
     242             : }
     243             : 
     244           0 : inline void SfxItemPool::SetKind( SfxPoolItem& rItem, SfxItemKind nRef )
     245             : {
     246           0 :     rItem.SetKind( nRef );
     247           0 : }
     248             : 
     249             : #endif
     250             : 
     251             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10