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

Generated by: LCOV version 1.10