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

Generated by: LCOV version 1.11