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