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

Generated by: LCOV version 1.10