LCOV - code coverage report
Current view: top level - sfx2/source/explorer - nochaos.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 52 53 98.1 %
Date: 2012-08-25 Functions: 12 12 100.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 23 44 52.3 %

           Branch data     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/itempool.hxx>
      22                 :            : #include <svl/poolitem.hxx>
      23                 :            : #include <svl/stritem.hxx>
      24                 :            : #include <nochaos.hxx>
      25                 :            : #include <sfx2/sfxuno.hxx>
      26                 :            : 
      27                 :            : 
      28                 :            : #define WID_CHAOS_START 500
      29                 :            : //=========================================================================
      30                 :            : // class CntStaticPoolDefaults_Impl
      31                 :            : //=========================================================================
      32                 :            : 
      33                 :            : class CntItemPool;
      34                 :            : 
      35                 :            : class CntStaticPoolDefaults_Impl
      36                 :            : {
      37                 :            :     sal_uInt32        m_nItems;
      38                 :            :     SfxPoolItem** m_ppDefaults;
      39                 :            :     SfxItemInfo*  m_pItemInfos;
      40                 :            : 
      41                 :            : private:
      42                 :            :     // Forbidden and not implemented...
      43                 :            :     CntStaticPoolDefaults_Impl( const CntStaticPoolDefaults_Impl& );
      44                 :            :     CntStaticPoolDefaults_Impl& operator=( const CntStaticPoolDefaults_Impl& );
      45                 :            : 
      46                 :            :     inline void Insert( SfxPoolItem* pItem, sal_uInt16 nSID, sal_uInt16 nFlags );
      47                 :            : 
      48                 :            : public:
      49                 :            :     CntStaticPoolDefaults_Impl( CntItemPool* pPool );
      50                 :            :     ~CntStaticPoolDefaults_Impl();
      51                 :            : 
      52                 :        233 :     SfxPoolItem**      GetDefaults() const  { return m_ppDefaults; }
      53                 :        233 :     const SfxItemInfo* GetItemInfos() const { return m_pItemInfos; }
      54                 :            : };
      55                 :            : 
      56                 :            : //----------------------------------------------------------------------------
      57                 :            : 
      58                 :            : //=========================================================================
      59                 :            : 
      60                 :            : class CntItemPool: public SfxItemPool
      61                 :            : {
      62                 :            :     static CntItemPool* _pThePool;
      63                 :            :     sal_uInt16              _nRefs;
      64                 :            : 
      65                 :            : protected:
      66                 :            :              CntItemPool();
      67                 :            :     virtual ~CntItemPool();
      68                 :            : 
      69                 :            : public:
      70                 :            :     static CntItemPool* Acquire();
      71                 :            :     static sal_uInt16       Release();
      72                 :            : };
      73                 :            : 
      74                 :            : //----------------------------------------------------------------------------
      75                 :            : 
      76                 :            : //----------------------------------------------------------------------------
      77                 :            : // static
      78                 :        233 : SfxItemPool* NoChaos::GetItemPool()
      79                 :            : {
      80                 :            :     // Get and hold CHAOS item pool.
      81                 :        233 :     return CntItemPool::Acquire();
      82                 :            : }
      83                 :            : 
      84                 :            : //----------------------------------------------------------------------------
      85                 :            : // static
      86                 :        158 : sal_uInt16 NoChaos::ReleaseItemPool()
      87                 :            : {
      88                 :            :     // Release CHAOS item pool.
      89                 :        158 :     return CntItemPool::Release();
      90                 :            : }
      91                 :            : 
      92                 :            : //=========================================================================
      93                 :            : //  CntItemPool implementation
      94                 :            : //=========================================================================
      95                 :            : 
      96                 :            : static CntStaticPoolDefaults_Impl* pPoolDefs_Impl = NULL;
      97                 :            : 
      98                 :            : // static member!
      99                 :            : CntItemPool* CntItemPool::_pThePool = NULL;
     100                 :            : 
     101                 :            : //-------------------------------------------------------------------------
     102                 :        233 : CntItemPool::CntItemPool()
     103                 :            : : SfxItemPool( DEFINE_CONST_UNICODE("chaos"), WID_CHAOS_START, WID_CHAOS_START, NULL ),
     104 [ +  - ][ +  - ]:        233 :   _nRefs( 0 )
     105                 :            : {
     106         [ +  - ]:        233 :     SetFileFormatVersion( SOFFICE_FILEFORMAT_50 );
     107                 :            : 
     108         [ +  - ]:        233 :     FreezeIdRanges();
     109                 :            : 
     110                 :            :     // Create static defaults.
     111 [ +  - ][ +  - ]:        233 :     pPoolDefs_Impl = new CntStaticPoolDefaults_Impl( this );
     112                 :            : 
     113                 :            :     // Set item infos.
     114                 :        233 :     SetItemInfos( pPoolDefs_Impl->GetItemInfos() );
     115                 :            : 
     116                 :            :     // Set static pool default items.
     117         [ +  - ]:        233 :     SetDefaults( pPoolDefs_Impl->GetDefaults() );
     118                 :        233 : }
     119                 :            : 
     120                 :            : //-------------------------------------------------------------------------
     121                 :            : //virtual
     122                 :        158 : CntItemPool::~CntItemPool()
     123                 :            : {
     124                 :            :     // Release static pool default items.
     125         [ +  - ]:        158 :     ReleaseDefaults( sal_False );
     126         [ -  + ]:        316 : }
     127                 :            : 
     128                 :            : //-------------------------------------------------------------------------
     129                 :            : // static
     130                 :        233 : CntItemPool* CntItemPool::Acquire()
     131                 :            : {
     132         [ +  - ]:        233 :     if ( !_pThePool )
     133         [ +  - ]:        233 :         _pThePool = new CntItemPool;
     134                 :            : 
     135                 :        233 :     _pThePool->_nRefs++;
     136                 :            : 
     137                 :        233 :     return _pThePool;
     138                 :            : }
     139                 :            : 
     140                 :            : //-------------------------------------------------------------------------
     141                 :            : // static
     142                 :        158 : sal_uInt16 CntItemPool::Release()
     143                 :            : {
     144         [ -  + ]:        158 :     if ( !_pThePool )
     145                 :          0 :         return 0;
     146                 :            : 
     147                 :        158 :     sal_uInt16& nRefs = _pThePool->_nRefs;
     148                 :            : 
     149         [ +  - ]:        158 :     if ( nRefs )
     150                 :        158 :         --nRefs;
     151                 :            : 
     152         [ +  - ]:        158 :     if ( !nRefs )
     153                 :            :     {
     154         [ +  - ]:        158 :         DELETEZ( _pThePool );
     155         [ +  - ]:        158 :         DELETEZ( pPoolDefs_Impl );
     156                 :        158 :         return 0;
     157                 :            :     }
     158                 :            : 
     159                 :        158 :     return nRefs;
     160                 :            : }
     161                 :            : 
     162                 :            : //=========================================================================
     163                 :            : // CntStaticPoolDefaults_Impl implementation.
     164                 :            : //=========================================================================
     165                 :            : 
     166                 :        233 : inline void CntStaticPoolDefaults_Impl::Insert(
     167                 :            :          SfxPoolItem* pItem,        /* Static Pool Default Item */
     168                 :            :          sal_uInt16 nSID, sal_uInt16 nFlags  /* Item Info */    )
     169                 :            : {
     170                 :        233 :     sal_uInt16 nPos = pItem->Which() - WID_CHAOS_START;
     171                 :            : 
     172                 :        233 :     m_ppDefaults[ nPos ]         = pItem;
     173                 :        233 :     m_pItemInfos[ nPos ]._nSID   = nSID;
     174                 :        233 :     m_pItemInfos[ nPos ]._nFlags = nFlags;
     175                 :        233 : }
     176                 :            : 
     177                 :            : //-------------------------------------------------------------------------
     178                 :        158 : CntStaticPoolDefaults_Impl::~CntStaticPoolDefaults_Impl()
     179                 :            : {
     180         [ +  + ]:        316 :     for ( sal_uInt32 n = 0; n < m_nItems; ++n )
     181         [ +  - ]:        158 :         delete m_ppDefaults[ n ];
     182                 :            : 
     183         [ +  - ]:        158 :     delete [] m_ppDefaults;
     184         [ +  - ]:        158 :     delete [] m_pItemInfos;
     185                 :        158 : }
     186                 :            : 
     187                 :            : //-------------------------------------------------------------------------
     188                 :        233 : CntStaticPoolDefaults_Impl::CntStaticPoolDefaults_Impl( CntItemPool* /*pPool*/ )
     189                 :            : : m_nItems( 1 ),
     190                 :        233 :   m_ppDefaults( new SfxPoolItem* [ m_nItems ] ),
     191                 :        233 :   m_pItemInfos( new SfxItemInfo  [ m_nItems ] )
     192                 :            : {
     193                 :        233 :     rtl_zeroMemory( m_ppDefaults, sizeof( SfxPoolItem* ) * m_nItems );
     194                 :        233 :     rtl_zeroMemory( m_pItemInfos, sizeof( SfxItemInfo ) * m_nItems );
     195                 :            :     Insert(
     196         [ +  - ]:        233 :         new SfxStringItem( WID_CHAOS_START, String() ),
     197                 :            :         0,
     198         [ +  - ]:        466 :         SFX_ITEM_POOLABLE );
     199                 :        233 : }
     200                 :            : 
     201                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10