LCOV - code coverage report
Current view: top level - libreoffice/unotools/source/misc - componentresmodule.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 6 32 18.8 %
Date: 2012-12-27 Functions: 2 10 20.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 <unotools/componentresmodule.hxx>
      21             : 
      22             : #include <tools/resmgr.hxx>
      23             : #include <osl/diagnose.h>
      24             : #include <rtl/strbuf.hxx>
      25             : 
      26             : //........................................................................
      27             : namespace utl
      28             : {
      29             : //........................................................................
      30             : 
      31             :     //====================================================================
      32             :     //= OComponentResModuleImpl
      33             :     //====================================================================
      34             :     /** PIMPL-class for OComponentResourceModule
      35             : 
      36             :         not threadsafe!
      37             :     */
      38             :     class OComponentResModuleImpl
      39             :     {
      40             :     private:
      41             :         ResMgr*         m_pResources;
      42             :         bool            m_bInitialized;
      43             :         ::rtl::OString  m_sResFilePrefix;
      44             : 
      45             :     public:
      46           2 :         OComponentResModuleImpl( const ::rtl::OString& _rResFilePrefix )
      47             :             :m_pResources( NULL )
      48             :             ,m_bInitialized( false )
      49           2 :             ,m_sResFilePrefix( _rResFilePrefix )
      50             :         {
      51           2 :         }
      52             : 
      53           0 :         ~OComponentResModuleImpl()
      54           0 :         {
      55           0 :             freeResManager();
      56           0 :         }
      57             : 
      58             :         /** releases our resource manager
      59             :         */
      60             :         void freeResManager();
      61             : 
      62             :         /** retrieves our resource manager
      63             :         */
      64             :         ResMgr* getResManager();
      65             : 
      66             :     private:
      67             :         OComponentResModuleImpl();                                              // never implemented
      68             :         OComponentResModuleImpl( const OComponentResModuleImpl& );              // never implemented
      69             :         OComponentResModuleImpl& operator=( const OComponentResModuleImpl& );   // never implemented
      70             :     };
      71             : 
      72             :     //--------------------------------------------------------------------
      73           0 :     void OComponentResModuleImpl::freeResManager()
      74             :     {
      75           0 :         delete m_pResources, m_pResources = NULL;
      76           0 :         m_bInitialized = false;
      77           0 :     }
      78             : 
      79             :     //--------------------------------------------------------------------
      80           0 :     ResMgr* OComponentResModuleImpl::getResManager()
      81             :     {
      82           0 :         if ( !m_pResources && !m_bInitialized )
      83             :         {
      84             :             // create a manager with a fixed prefix
      85           0 :             rtl::OString aMgrName = m_sResFilePrefix;
      86             : 
      87           0 :             m_pResources = ResMgr::CreateResMgr( aMgrName.getStr() );
      88             :             OSL_ENSURE( m_pResources,
      89             :                     rtl::OStringBuffer( "OModuleImpl::getResManager: could not create the resource manager (file name: " )
      90             :                 .append(aMgrName)
      91             :                 .append(")!").getStr() );
      92             : 
      93           0 :             m_bInitialized = sal_True;
      94             :         }
      95           0 :         return m_pResources;
      96             :     }
      97             : 
      98             :     //====================================================================
      99             :     //= OComponentResourceModule
     100             :     //====================================================================
     101             :     //--------------------------------------------------------------------
     102           2 :     OComponentResourceModule::OComponentResourceModule( const ::rtl::OString& _rResFilePrefix )
     103             :         :BaseClass()
     104           2 :         ,m_pImpl( new OComponentResModuleImpl( _rResFilePrefix ) )
     105             :     {
     106           2 :     }
     107             : 
     108             :     //--------------------------------------------------------------------
     109           0 :     OComponentResourceModule::~OComponentResourceModule()
     110             :     {
     111           0 :     }
     112             : 
     113             :     //-------------------------------------------------------------------------
     114           0 :     ResMgr* OComponentResourceModule::getResManager()
     115             :     {
     116           0 :         ::osl::MutexGuard aGuard( m_aMutex );
     117           0 :         return m_pImpl->getResManager();
     118             :     }
     119             : 
     120             :     //--------------------------------------------------------------------------
     121           0 :     void OComponentResourceModule::onFirstClient()
     122             :     {
     123           0 :         BaseClass::onFirstClient();
     124           0 :     }
     125             : 
     126             :     //--------------------------------------------------------------------------
     127           0 :     void OComponentResourceModule::onLastClient()
     128             :     {
     129           0 :         m_pImpl->freeResManager();
     130           0 :         BaseClass::onLastClient();
     131           0 :     }
     132             : 
     133             : //........................................................................
     134             : } // namespace utl
     135             : //........................................................................
     136             : 
     137             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10