xref: /AOO41X/main/reportdesign/inc/ModuleHelper.hxx (revision 9ee13d1351a4b51ae8bed78e67629c7bd5f4481e)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #ifndef _RPTUI_MODULE_HELPER_RPT_HXX_
25 #define _RPTUI_MODULE_HELPER_RPT_HXX_
26 
27 #include "dllapi.h"
28 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
29 #include <tools/resmgr.hxx>
30 
31 //.........................................................................
32 namespace rptui
33 {
34 //.........................................................................
35     //=========================================================================
36     //= OModule
37     //=========================================================================
38     class OModuleImpl;
39     class REPORTDESIGN_DLLPUBLIC OModule
40     {
41         friend class OModuleClient;
42 
43     private:
44         OModule();
45             // not implemented. OModule is a static class
46 
47     protected:
48         static ::osl::Mutex s_aMutex;       /// access safety
49         static sal_Int32    s_nClients;     /// number of registered clients
50         static OModuleImpl* s_pImpl;        /// impl class. lives as long as at least one client for the module is registered
51 
52     public:
53         /// get the vcl res manager of the module
54         static ResMgr*  getResManager();
55     protected:
56         /// register a client for the module
57         static void registerClient();
58         /// revoke a client for the module
59         static void revokeClient();
60 
61     private:
62         /** ensure that the impl class exists
63             @precond m_aMutex is guarded when this method gets called
64         */
65         static void ensureImpl();
66     };
67 
68     //=========================================================================
69     //= OModuleClient
70     //=========================================================================
71     /** base class for objects which uses any global module-specific ressources
72     */
73     class REPORTDESIGN_DLLPUBLIC OModuleClient
74     {
75     public:
OModuleClient()76         inline OModuleClient()      { OModule::registerClient(); }
~OModuleClient()77         inline ~OModuleClient() { OModule::revokeClient(); }
78     };
79 
80     //=========================================================================
81     //= ModuleRes
82     //=========================================================================
83     /** specialized ResId, using the ressource manager provided by the global module
84     */
85     class REPORTDESIGN_DLLPUBLIC ModuleRes : public ::ResId
86     {
87     public:
ModuleRes(sal_uInt16 _nId)88         inline ModuleRes(sal_uInt16 _nId) : ResId(_nId, *OModule::getResManager()) { }
89     };
90 //.........................................................................
91 }   // namespace rptui
92 //.........................................................................
93 
94 #endif // _RPTUI_MODULE_HELPER_RPT_HXX_
95 
96 
97