1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
19 #ifndef INCLUDED_UNOTOOLS_COMPONENTRESMODULE_HXX
20 #define INCLUDED_UNOTOOLS_COMPONENTRESMODULE_HXX
22 #include <comphelper/componentmodule.hxx>
23 #include <unotools/unotoolsdllapi.h>
25 #include <tools/resid.hxx>
31 //........................................................................
34 //........................................................................
36 class OComponentResModuleImpl
;
38 //====================================================================
39 //= OComponentResourceModule
40 //====================================================================
41 /** extends the comphelper::OModule implementation with
42 simply resource access
44 class UNOTOOLS_DLLPUBLIC OComponentResourceModule
: public ::comphelper::OModule
47 typedef ::comphelper::OModule BaseClass
;
50 ::std::auto_ptr
< OComponentResModuleImpl
> m_pImpl
;
53 OComponentResourceModule( const OString
& _rResFilePrefix
);
54 ~OComponentResourceModule();
56 /// get the vcl res manager of the module
57 ResMgr
* getResManager();
60 // OModule overridables
61 virtual void onFirstClient();
62 virtual void onLastClient();
65 //=========================================================================
67 //=========================================================================
68 /** specialized ResId, using the resource manager provided by a given OModule
70 class UNOTOOLS_DLLPUBLIC ModuleRes
: public ::ResId
73 ModuleRes( sal_uInt16 _nId
, OComponentResourceModule
& _rModule
) : ResId( _nId
, *_rModule
.getResManager() ) { }
76 //====================================================================
77 //= defining a concrete module
78 //====================================================================
79 #define DEFINE_MODULE( ModuleClass, ClientClass, ResClass ) \
80 /* -------------------------------------------------------------------- */ \
81 class ModuleClass : public ::utl::OComponentResourceModule \
83 friend struct CreateModuleClass; \
84 typedef ::utl::OComponentResourceModule BaseClass; \
87 static ModuleClass& getInstance(); \
93 /* -------------------------------------------------------------------- */ \
94 class ClientClass : public ::comphelper::OModuleClient \
97 typedef ::comphelper::OModuleClient BaseClass; \
100 ClientClass() : BaseClass( ModuleClass::getInstance() ) \
105 /* -------------------------------------------------------------------- */ \
106 class ResClass : public ::utl::ModuleRes \
109 typedef ::utl::ModuleRes BaseClass; \
112 ResClass( sal_uInt16 _nId ) : BaseClass( _nId, ModuleClass::getInstance() ) \
117 /* -------------------------------------------------------------------- */ \
118 template < class TYPE > \
119 class OAutoRegistration : public ::comphelper::OAutoRegistration< TYPE > \
122 typedef ::comphelper::OAutoRegistration< TYPE > BaseClass; \
125 OAutoRegistration() : BaseClass( ModuleClass::getInstance() ) \
130 /* -------------------------------------------------------------------- */ \
131 template < class TYPE > \
132 class OSingletonRegistration : public ::comphelper::OSingletonRegistration< TYPE > \
135 typedef ::comphelper::OSingletonRegistration< TYPE > BaseClass; \
138 OSingletonRegistration() : BaseClass( ModuleClass::getInstance() ) \
143 //====================================================================
144 //= implementing a concrete module
145 //====================================================================
146 #define IMPLEMENT_MODULE( ModuleClass, resprefix ) \
147 struct CreateModuleClass \
149 ModuleClass* operator()() \
151 static ModuleClass* pModule = new ModuleClass; \
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. */ \
163 ModuleClass::ModuleClass() \
164 :BaseClass( OString( resprefix ) ) \
168 ModuleClass& ModuleClass::getInstance() \
170 return *rtl_Instance< ModuleClass, CreateModuleClass, ::osl::MutexGuard, ::osl::GetGlobalMutex >:: \
171 create( CreateModuleClass(), ::osl::GetGlobalMutex() ); \
174 //........................................................................
176 //........................................................................
178 #endif // INCLUDED_UNOTOOLS_COMPONENTRESMODULE_HXX
180 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */