LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/include/unotools - componentresmodule.hxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 1 0.0 %
Date: 2013-07-09 Functions: 0 1 0.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             : #ifndef UNOTOOLS_INC_UNOTOOLS_COMPONENTRESMODULE_HXX
      20             : #define UNOTOOLS_INC_UNOTOOLS_COMPONENTRESMODULE_HXX
      21             : 
      22             : #include <comphelper/componentmodule.hxx>
      23             : #include <unotools/unotoolsdllapi.h>
      24             : 
      25             : #include <tools/resid.hxx>
      26             : 
      27             : #include <memory>
      28             : 
      29             : class ResMgr;
      30             : 
      31             : //........................................................................
      32             : namespace utl
      33             : {
      34             : //........................................................................
      35             : 
      36             :     class OComponentResModuleImpl;
      37             : 
      38             :     //====================================================================
      39             :     //= OComponentResourceModule
      40             :     //====================================================================
      41             :     /** extends the comphelper::OModule implementation with
      42             :         simply resource access
      43             :     */
      44             :     class UNOTOOLS_DLLPUBLIC OComponentResourceModule : public ::comphelper::OModule
      45             :     {
      46             :     private:
      47             :         typedef ::comphelper::OModule   BaseClass;
      48             : 
      49             :     private:
      50             :         ::std::auto_ptr< OComponentResModuleImpl >  m_pImpl;
      51             : 
      52             :     public:
      53             :         OComponentResourceModule( const OString& _rResFilePrefix );
      54             :         ~OComponentResourceModule();
      55             : 
      56             :         /// get the vcl res manager of the module
      57             :         ResMgr* getResManager();
      58             : 
      59             :     protected:
      60             :         // OModule overridables
      61             :         virtual void onFirstClient();
      62             :         virtual void onLastClient();
      63             :     };
      64             : 
      65             :     //=========================================================================
      66             :     //= ModuleRes
      67             :     //=========================================================================
      68             :     /** specialized ResId, using the resource manager provided by a given OModule
      69             :     */
      70             :     class UNOTOOLS_DLLPUBLIC ModuleRes : public ::ResId
      71             :     {
      72             :     public:
      73           0 :         ModuleRes( sal_uInt16 _nId, OComponentResourceModule& _rModule ) : ResId( _nId, *_rModule.getResManager() ) { }
      74             :     };
      75             : 
      76             :     //====================================================================
      77             :     //= defining a concrete module
      78             :     //====================================================================
      79             : #define DEFINE_MODULE( ModuleClass, ClientClass, ResClass ) \
      80             :     /* -------------------------------------------------------------------- */ \
      81             :     class ModuleClass : public ::utl::OComponentResourceModule \
      82             :     { \
      83             :         friend struct CreateModuleClass; \
      84             :         typedef ::utl::OComponentResourceModule BaseClass; \
      85             :     \
      86             :     public: \
      87             :         static ModuleClass& getInstance(); \
      88             :     \
      89             :     private: \
      90             :         ModuleClass(); \
      91             :     }; \
      92             :     \
      93             :     /* -------------------------------------------------------------------- */ \
      94             :     class ClientClass : public ::comphelper::OModuleClient \
      95             :     { \
      96             :     private: \
      97             :         typedef ::comphelper::OModuleClient BaseClass; \
      98             :     \
      99             :     public: \
     100             :         ClientClass() : BaseClass( ModuleClass::getInstance() ) \
     101             :         { \
     102             :         } \
     103             :     }; \
     104             :     \
     105             :     /* -------------------------------------------------------------------- */ \
     106             :     class ResClass : public ::utl::ModuleRes \
     107             :     { \
     108             :     private: \
     109             :         typedef ::utl::ModuleRes    BaseClass; \
     110             :     \
     111             :     public: \
     112             :         ResClass( sal_uInt16 _nId ) : BaseClass( _nId, ModuleClass::getInstance() ) \
     113             :         { \
     114             :         } \
     115             :     }; \
     116             :     \
     117             :     /* -------------------------------------------------------------------- */ \
     118             :     template < class TYPE > \
     119             :     class OAutoRegistration : public ::comphelper::OAutoRegistration< TYPE > \
     120             :     { \
     121             :     private: \
     122             :         typedef ::comphelper::OAutoRegistration< TYPE >    BaseClass; \
     123             :     \
     124             :     public: \
     125             :         OAutoRegistration() : BaseClass( ModuleClass::getInstance() ) \
     126             :         { \
     127             :         } \
     128             :     }; \
     129             :     \
     130             :     /* -------------------------------------------------------------------- */ \
     131             :     template < class TYPE > \
     132             :     class OSingletonRegistration : public ::comphelper::OSingletonRegistration< TYPE > \
     133             :     { \
     134             :     private: \
     135             :         typedef ::comphelper::OSingletonRegistration< TYPE >    BaseClass; \
     136             :     \
     137             :     public: \
     138             :         OSingletonRegistration() : BaseClass( ModuleClass::getInstance() ) \
     139             :         { \
     140             :         } \
     141             :     };
     142             : 
     143             :     //====================================================================
     144             :     //= implementing a concrete module
     145             :     //====================================================================
     146             : #define IMPLEMENT_MODULE( ModuleClass, resprefix ) \
     147             :     struct CreateModuleClass \
     148             :     { \
     149             :         ModuleClass* operator()() \
     150             :         { \
     151             :             static ModuleClass* pModule = new ModuleClass; \
     152             :             return pModule; \
     153             :             /*  yes, in theory, this is a resource leak, since the ModuleClass \
     154             :                 will never be cleaned up. However, using a non-heap instance of ModuleClass \
     155             :                 would not work: It would be cleaned up when the module is unloaded. \
     156             :                 This might happen (and is likely to happen) *after* the tools-library \
     157             :                 has been unloaded. However, the module's dtor is where we would delete \
     158             :                 our resource manager (in case not all our clients de-registered) - which \
     159             :                 would call into the already-unloaded tools-library. */ \
     160             :         } \
     161             :     }; \
     162             :     \
     163             :     ModuleClass::ModuleClass() \
     164             :         :BaseClass( OString( resprefix ) ) \
     165             :     { \
     166             :     } \
     167             :     \
     168             :     ModuleClass& ModuleClass::getInstance() \
     169             :     { \
     170             :         return *rtl_Instance< ModuleClass, CreateModuleClass, ::osl::MutexGuard, ::osl::GetGlobalMutex >:: \
     171             :             create( CreateModuleClass(), ::osl::GetGlobalMutex() ); \
     172             :     } \
     173             : 
     174             : //........................................................................
     175             : } // namespace utl
     176             : //........................................................................
     177             : 
     178             : #endif // UNOTOOLS_INC_UNOTOOLS_COMPONENTRESMODULE_HXX
     179             : 
     180             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10