LCOV - code coverage report
Current view: top level - svl/source/inc - poolio.hxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 29 29 100.0 %
Date: 2014-11-03 Functions: 8 8 100.0 %
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_SOURCE_INC_POOLIO_HXX
      21             : #define INCLUDED_SVL_SOURCE_INC_POOLIO_HXX
      22             : 
      23             : #include <svl/SfxBroadcaster.hxx>
      24             : #include <boost/shared_ptr.hpp>
      25             : #include <boost/unordered_map.hpp>
      26             : #include <deque>
      27             : #include <vector>
      28             : 
      29             : class SfxPoolItem;
      30             : class SfxItemPoolUser;
      31             : 
      32             : #ifndef DELETEZ
      33             : #define DELETEZ(pPtr) { delete pPtr; pPtr = 0; }
      34             : #endif
      35             : 
      36             : static const sal_uInt32 SFX_ITEMS_DIRECT  = 0xffffffff;
      37             : static const sal_uInt32 SFX_ITEMS_NULL    = 0xfffffff0;  // instead StoreSurrogate
      38             : static const sal_uInt32 SFX_ITEMS_DEFAULT = 0xfffffffe;
      39             : 
      40             : struct SfxPoolVersion_Impl
      41             : {
      42             :     sal_uInt16          _nVer;
      43             :     sal_uInt16          _nStart, _nEnd;
      44             :     const sal_uInt16*         _pMap;
      45             : 
      46      596140 :                     SfxPoolVersion_Impl( sal_uInt16 nVer, sal_uInt16 nStart, sal_uInt16 nEnd,
      47             :                                          const sal_uInt16 *pMap )
      48             :                     :   _nVer( nVer ),
      49             :                         _nStart( nStart ),
      50             :                         _nEnd( nEnd ),
      51      596140 :                         _pMap( pMap )
      52      596140 :                     {}
      53         444 :                     SfxPoolVersion_Impl( const SfxPoolVersion_Impl &rOrig )
      54             :                     :   _nVer( rOrig._nVer ),
      55             :                         _nStart( rOrig._nStart ),
      56             :                         _nEnd( rOrig._nEnd ),
      57         444 :                         _pMap( rOrig._pMap )
      58         444 :                     {}
      59             : };
      60             : 
      61             : typedef std::vector<SfxPoolItem*> SfxPoolItemArrayBase_Impl;
      62             : 
      63             : typedef boost::shared_ptr< SfxPoolVersion_Impl > SfxPoolVersion_ImplPtr;
      64             : typedef std::deque< SfxPoolVersion_ImplPtr > SfxPoolVersionArr_Impl;
      65             : 
      66             : /**
      67             :  * This array contains a set of SfxPoolItems, if those items are
      68             :  * poolable then each item has a unique set of properties, and we
      69             :  * often search linearly to ensure uniqueness. If they are
      70             :  * non-poolable we maintain an (often large) list of pointers.
      71             :  */
      72      945735 : struct SfxPoolItemArray_Impl: public SfxPoolItemArrayBase_Impl
      73             : {
      74             :     typedef std::vector<sal_uInt32> FreeList;
      75             :     typedef boost::unordered_map<SfxPoolItem*,sal_uInt32> Hash;
      76             : 
      77             : public:
      78             :     /// Track list of indices into our array that contain an empty slot
      79             :     FreeList maFree;
      80             :     /// Hash of SfxPoolItem pointer to index into our array that contains that slot
      81             :     Hash     maHash;
      82             : 
      83      949944 :     SfxPoolItemArray_Impl () {}
      84             : 
      85             :     /// re-build the list of free slots and hash from clean
      86             :     void SVL_DLLPUBLIC ReHash();
      87             : };
      88             : 
      89             : struct SfxItemPool_Impl
      90             : {
      91             :     SfxBroadcaster                  aBC;
      92             :     std::vector<SfxPoolItemArray_Impl*> maPoolItems;
      93             :     std::vector<SfxItemPoolUser*> maSfxItemPoolUsers; /// ObjectUser section
      94             :     OUString                        aName;
      95             :     SfxPoolItem**                   ppPoolDefaults;
      96             :     SfxPoolItem**                   ppStaticDefaults;
      97             :     SfxItemPool*                    mpMaster;
      98             :     SfxItemPool*                    mpSecondary;
      99             :     sal_uInt16*                     mpPoolRanges;
     100             :     SfxPoolVersionArr_Impl          aVersions;
     101             :     sal_uInt16                      mnStart;
     102             :     sal_uInt16                      mnEnd;
     103             :     sal_uInt16                      mnFileFormatVersion;
     104             :     sal_uInt16                      nVersion;
     105             :     sal_uInt16                      nLoadingVersion;
     106             :     sal_uInt16                      nInitRefCount; // 1, during load, may be 2
     107             :     sal_uInt16                      nVerStart, nVerEnd; // WhichRange in versions
     108             :     sal_uInt16                      nStoringStart, nStoringEnd; // Range to be saved
     109             :     sal_uInt8                       nMajorVer, nMinorVer; // The Pool itself
     110             :     SfxMapUnit                      eDefMetric;
     111             :     bool                            bInSetItem;
     112             :     bool                            bStreaming; // in Load() or Store()
     113             :     bool                            mbPersistentRefCounts;
     114             : 
     115      105019 :     SfxItemPool_Impl( SfxItemPool* pMaster, const OUString& rName, sal_uInt16 nStart, sal_uInt16 nEnd )
     116      105019 :         : maPoolItems(nEnd - nStart + 1, static_cast<SfxPoolItemArray_Impl*>(NULL))
     117             :         , aName(rName)
     118      105019 :         , ppPoolDefaults(new SfxPoolItem* [nEnd - nStart + 1])
     119             :         , ppStaticDefaults(0)
     120             :         , mpMaster(pMaster)
     121             :         , mpSecondary(NULL)
     122             :         , mpPoolRanges(NULL)
     123             :         , mnStart(nStart)
     124             :         , mnEnd(nEnd)
     125             :         , mnFileFormatVersion(0)
     126             :         , nVersion(0)
     127             :         , nLoadingVersion(0)
     128             :         , nInitRefCount(0)
     129             :         , nVerStart(0)
     130             :         , nVerEnd(0)
     131             :         , nStoringStart(0)
     132             :         , nStoringEnd(0)
     133             :         , nMajorVer(0)
     134             :         , nMinorVer(0)
     135             :         , eDefMetric(SFX_MAPUNIT_CM)
     136             :         , bInSetItem(false)
     137             :         , bStreaming(false)
     138      315057 :         , mbPersistentRefCounts(false)
     139             :     {
     140             :         DBG_ASSERT(mnStart, "Start-Which-Id must be greater 0" );
     141      105019 :         memset( ppPoolDefaults, 0, sizeof( SfxPoolItem* ) * (nEnd - nStart + 1));
     142      105019 :     }
     143             : 
     144      104171 :     ~SfxItemPool_Impl()
     145      104171 :     {
     146      104171 :         DeleteItems();
     147      104171 :     }
     148             : 
     149      208342 :     void DeleteItems()
     150             :     {
     151      208342 :         std::vector<SfxPoolItemArray_Impl*>::iterator itr = maPoolItems.begin(), itrEnd = maPoolItems.end();
     152     7900277 :         for (; itr != itrEnd; ++itr)
     153     7691935 :             delete *itr;
     154      208342 :         maPoolItems.clear();
     155             : 
     156      208342 :         delete[] mpPoolRanges;
     157      208342 :         mpPoolRanges = NULL;
     158      208342 :         delete[] ppPoolDefaults;
     159      208342 :         ppPoolDefaults = NULL;
     160      208342 :     }
     161             : 
     162             :     void readTheItems(SvStream & rStream, sal_uInt32 nCount, sal_uInt16 nVersion,
     163             :                       SfxPoolItem * pDefItem, SfxPoolItemArray_Impl ** pArr);
     164             : 
     165             :     // unit testing
     166             :     friend class PoolItemTest;
     167           2 :     static SfxItemPool_Impl *GetImpl(SfxItemPool *pPool) { return pPool->pImp; }
     168             : };
     169             : 
     170             : 
     171             : #define CHECK_FILEFORMAT( rStream, nTag ) \
     172             :     {   sal_uInt16 nFileTag; \
     173             :         rStream.ReadUInt16( nFileTag ); \
     174             :         if ( nTag != nFileTag ) \
     175             :         { \
     176             :             OSL_FAIL( #nTag ); /*! s.u. */ \
     177             :             /*! Set error code and evaluate! */ \
     178             :             (rStream).SetError(SVSTREAM_FILEFORMAT_ERROR); \
     179             :             pImp->bStreaming = false; \
     180             :             return rStream; \
     181             :         } \
     182             :     }
     183             : 
     184             : #define CHECK_FILEFORMAT_RELEASE( rStream, nTag, pPointer ) \
     185             :    {   sal_uInt16 nFileTag; \
     186             :        rStream.ReadUInt16( nFileTag ); \
     187             :        if ( nTag != nFileTag ) \
     188             :         { \
     189             :            OSL_FAIL( #nTag ); /*! s.u. */ \
     190             :            /*! Set error code and evaluate! */ \
     191             :            (rStream).SetError(SVSTREAM_FILEFORMAT_ERROR); \
     192             :            pImp->bStreaming = false; \
     193             :            delete pPointer; \
     194             :             return rStream; \
     195             :         } \
     196             :     }
     197             : 
     198             : #define CHECK_FILEFORMAT2( rStream, nTag1, nTag2 ) \
     199             :     {   sal_uInt16 nFileTag; \
     200             :         rStream.ReadUInt16( nFileTag ); \
     201             :         if ( nTag1 != nFileTag && nTag2 != nFileTag ) \
     202             :         { \
     203             :             OSL_FAIL( #nTag1 ); /*! s.u. */ \
     204             :             /*! Set error code and evaluate! */ \
     205             :             (rStream).SetError(SVSTREAM_FILEFORMAT_ERROR); \
     206             :             pImp->bStreaming = false; \
     207             :             return rStream; \
     208             :         } \
     209             :     }
     210             : 
     211             : #define SFX_ITEMPOOL_VER_MAJOR          sal_uInt8(2)
     212             : #define SFX_ITEMPOOL_VER_MINOR          sal_uInt8(0)
     213             : 
     214             : #define SFX_ITEMPOOL_TAG_STARTPOOL_4    sal_uInt16(0x1111)
     215             : #define SFX_ITEMPOOL_TAG_STARTPOOL_5    sal_uInt16(0xBBBB)
     216             : #define SFX_ITEMPOOL_TAG_ITEMPOOL       sal_uInt16(0xAAAA)
     217             : #define SFX_ITEMPOOL_TAG_ITEMS          sal_uInt16(0x2222)
     218             : #define SFX_ITEMPOOL_TAG_ITEM           sal_uInt16(0x7777)
     219             : #define SFX_ITEMPOOL_TAG_SIZES          sal_uInt16(0x3333)
     220             : #define SFX_ITEMPOOL_TAG_DEFAULTS       sal_uInt16(0x4444)
     221             : #define SFX_ITEMPOOL_TAG_VERSIONMAP     sal_uInt16(0x5555)
     222             : #define SFX_ITEMPOOL_TAG_HEADER         sal_uInt16(0x6666)
     223             : #define SFX_ITEMPOOL_TAG_ENDPOOL        sal_uInt16(0xEEEE)
     224             : #define SFX_ITEMPOOL_TAG_TRICK4OLD      sal_uInt16(0xFFFF)
     225             : 
     226             : #define SFX_ITEMPOOL_REC                sal_uInt8(0x01)
     227             : #define SFX_ITEMPOOL_REC_HEADER         sal_uInt8(0x10)
     228             : #define SFX_ITEMPOOL_REC_VERSIONMAP     sal_uInt16(0x0020)
     229             : #define SFX_ITEMPOOL_REC_WHICHIDS       sal_uInt16(0x0030)
     230             : #define SFX_ITEMPOOL_REC_ITEMS          sal_uInt16(0x0040)
     231             : #define SFX_ITEMPOOL_REC_DEFAULTS       sal_uInt16(0x0050)
     232             : 
     233             : #define SFX_ITEMSET_REC                 sal_uInt8(0x02)
     234             : 
     235             : #define SFX_STYLES_REC                  sal_uInt8(0x03)
     236             : #define SFX_STYLES_REC_HEADER       sal_uInt16(0x0010)
     237             : #define SFX_STYLES_REC_STYLES       sal_uInt16(0x0020)
     238             : 
     239             : /** Read in a Unicode string from a streamed byte string representation.
     240             : 
     241             :     @param rStream  Some (input) stream.  Its Stream/TargetCharSets must
     242             :     be set to correct values!
     243             : 
     244             :     @return  On success, returns the reconstructed Unicode string.
     245             :  */
     246             : OUString readByteString(SvStream & rStream);
     247             : 
     248             : /** Write a byte string representation of a Unicode string into a stream.
     249             : 
     250             :     @param rStream  Some (output) stream.  Its Stream/TargetCharSets must
     251             :     be set to correct values!
     252             : 
     253             :     @param rString  Some Unicode string.
     254             :  */
     255             : void writeByteString(SvStream & rStream, const OUString& rString);
     256             : 
     257             : /** Read in a Unicode string from either a streamed Unicode or byte string
     258             :     representation.
     259             : 
     260             :     @param rStream  Some (input) stream.  If bUnicode is false, its
     261             :     Stream/TargetCharSets must be set to correct values!
     262             : 
     263             :     @param bUnicode  Whether to read in a stream Unicode (true) or byte
     264             :     string (false) representation.
     265             : 
     266             :     @return          On success, returns the reconstructed Unicode string.
     267             :  */
     268             : OUString readUnicodeString(SvStream & rStream, bool bUnicode);
     269             : 
     270             : /** Write a Unicode string representation of a Unicode string into a
     271             :     stream.
     272             : 
     273             :     @param rStream  Some (output) stream.
     274             : 
     275             :     @param rString  Some Unicode string.
     276             :  */
     277             : void writeUnicodeString(SvStream & rStream, const OUString& rString);
     278             : 
     279             : 
     280             : #endif // INCLUDED_SVL_SOURCE_INC_POOLIO_HXX
     281             : 
     282             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10