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

Generated by: LCOV version 1.11