bump product version to 4.2.0.1
[LibreOffice.git] / include / unotools / componentresmodule.hxx
blob64f4c886fa30495920f00a47e83b521cc5fd8b75
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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>
27 #include <memory>
29 class ResMgr;
31 //........................................................................
32 namespace utl
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
46 private:
47 typedef ::comphelper::OModule BaseClass;
49 private:
50 ::std::auto_ptr< OComponentResModuleImpl > m_pImpl;
52 public:
53 OComponentResourceModule( const OString& _rResFilePrefix );
54 ~OComponentResourceModule();
56 /// get the vcl res manager of the module
57 ResMgr* getResManager();
59 protected:
60 // OModule overridables
61 virtual void onFirstClient();
62 virtual void onLastClient();
65 //=========================================================================
66 //= ModuleRes
67 //=========================================================================
68 /** specialized ResId, using the resource manager provided by a given OModule
70 class UNOTOOLS_DLLPUBLIC ModuleRes : public ::ResId
72 public:
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 \
82 { \
83 friend struct CreateModuleClass; \
84 typedef ::utl::OComponentResourceModule BaseClass; \
86 public: \
87 static ModuleClass& getInstance(); \
89 private: \
90 ModuleClass(); \
91 }; \
93 /* -------------------------------------------------------------------- */ \
94 class ClientClass : public ::comphelper::OModuleClient \
95 { \
96 private: \
97 typedef ::comphelper::OModuleClient BaseClass; \
99 public: \
100 ClientClass() : BaseClass( ModuleClass::getInstance() ) \
103 }; \
105 /* -------------------------------------------------------------------- */ \
106 class ResClass : public ::utl::ModuleRes \
108 private: \
109 typedef ::utl::ModuleRes BaseClass; \
111 public: \
112 ResClass( sal_uInt16 _nId ) : BaseClass( _nId, ModuleClass::getInstance() ) \
115 }; \
117 /* -------------------------------------------------------------------- */ \
118 template < class TYPE > \
119 class OAutoRegistration : public ::comphelper::OAutoRegistration< TYPE > \
121 private: \
122 typedef ::comphelper::OAutoRegistration< TYPE > BaseClass; \
124 public: \
125 OAutoRegistration() : BaseClass( ModuleClass::getInstance() ) \
128 }; \
130 /* -------------------------------------------------------------------- */ \
131 template < class TYPE > \
132 class OSingletonRegistration : public ::comphelper::OSingletonRegistration< TYPE > \
134 private: \
135 typedef ::comphelper::OSingletonRegistration< TYPE > BaseClass; \
137 public: \
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; \
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. */ \
161 }; \
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 //........................................................................
175 } // namespace utl
176 //........................................................................
178 #endif // INCLUDED_UNOTOOLS_COMPONENTRESMODULE_HXX
180 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */