xref: /AOO41X/main/dbaccess/source/core/inc/core_resource.hxx (revision 2e2212a7c22e96cf6f6fab0dd042c34a45a64bd6)
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 _DBA_CORE_RESOURCE_HXX_
25 #define _DBA_CORE_RESOURCE_HXX_
26 
27 #ifndef _RTL_USTRING_HXX_
28 #include <rtl/ustring.hxx>
29 #endif
30 #include <osl/mutex.hxx>
31 
32 class ResMgr;
33 //.........................................................................
34 namespace dbaccess
35 {
36 
37 #define DBA_RES( id )                       ResourceManager::loadString( id )
38 #define DBA_RES_PARAM( id, ascii, replace ) ResourceManager::loadString( id, ascii, replace )
39 
40 #define DBACORE_RESSTRING( id ) DBA_RES( id )
41         // (compatibility)
42 
43     //==================================================================
44     //= ResourceManager
45     //= handling ressources within the DBA-Core library
46     //==================================================================
47     class ResourceManager
48     {
49         friend class OModuleClient;
50         static ::osl::Mutex s_aMutex;       /// access safety
51         static sal_Int32    s_nClients;     /// number of registered clients
52         static ResMgr*  m_pImpl;
53 
54     private:
55         // no instantiation allowed
ResourceManager()56         ResourceManager() { }
~ResourceManager()57         ~ResourceManager() { }
58 
59     protected:
60         static void ensureImplExists();
61         /// register a client for the module
62         static void registerClient();
63         /// revoke a client for the module
64         static void revokeClient();
65 
66     public:
67         /** loads the string with the specified resource id
68         */
69         static ::rtl::OUString  loadString(sal_uInt16 _nResId);
70 
71         /** loads a string from the resource file, substituting a placeholder with a given string
72 
73             @param  _nResId
74                 the resource ID of the string to load
75             @param  _pPlaceholderAscii
76                 the ASCII representation of the placeholder string
77             @param  _rReplace
78                 the string which should substitute the placeholder
79         */
80         static ::rtl::OUString  loadString(
81                 sal_uInt16              _nResId,
82                 const sal_Char*         _pPlaceholderAscii,
83                 const ::rtl::OUString&  _rReplace
84         );
85 
86         /** loads a string from the resource file, substituting two placeholders with given strings
87 
88             @param  _nResId
89                 the resource ID of the string to load
90             @param  _pPlaceholderAscii1
91                 the ASCII representation of the first placeholder string
92             @param  _rReplace1
93                 the string which should substitute the first placeholder
94             @param  _pPlaceholderAscii2
95                 the ASCII representation of the second placeholder string
96             @param  _rReplace2
97                 the string which should substitute the second placeholder
98         */
99         static ::rtl::OUString  loadString(
100                 sal_uInt16              _nResId,
101                 const sal_Char*         _pPlaceholderAscii1,
102                 const ::rtl::OUString&  _rReplace1,
103                 const sal_Char*         _pPlaceholderAscii2,
104                 const ::rtl::OUString&  _rReplace2
105         );
106     };
107 
108     //=========================================================================
109     //= OModuleClient
110     //=========================================================================
111     /** base class for objects which uses any global module-specific ressources
112     */
113     class OModuleClient
114     {
115     public:
OModuleClient()116         OModuleClient()     { ResourceManager::registerClient(); }
~OModuleClient()117         ~OModuleClient()    { ResourceManager::revokeClient(); }
118     };
119 
120 
121 //.........................................................................
122 }
123 //.........................................................................
124 
125 #endif // _DBA_CORE_RESOURCE_HXX_
126 
127