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