ALib C++ Library
Library Version: 2402 R1
Documentation generated by doxygen
Loading...
Searching...
No Matches
configresourcepool.hpp
Go to the documentation of this file.
1/** ************************************************************************************************
2 * \file
3 * This header file is part of sub-namespace #alib::lang::resources of module \alib_basecamp of
4 * the \aliblong.
5 *
6 * \emoji :copyright: 2013-2024 A-Worx GmbH, Germany.
7 * Published under \ref mainpage_license "Boost Software License".
8 **************************************************************************************************/
9#ifndef HPP_ALIB_LANG_RESOURCES_CONFIG_RESOURCE_POOL
10#define HPP_ALIB_LANG_RESOURCES_CONFIG_RESOURCE_POOL 1
11
12#if !defined (HPP_ALIB_LANG_RESOURCES_RESOURCES)
14#endif
15
16ALIB_ASSERT_MODULE(CONFIGURATION)
17
18#if !defined (HPP_ALIB_LANG_RESOURCES_DETAIL_RESOURCEMAP)
19# include "alib/lang/resources/detail/resourcemap.hpp"
20#endif
21#if !defined (HPP_ALIB_CONFIG_CONFIGURATION)
23#endif
24
25#if ALIB_THREADS && !defined (HPP_ALIB_THREADS_THREADLOCK)
27#endif
28
29namespace alib::lang::resources {
30
31
32/** ************************************************************************************************
33 * This class provides an implementation of abstract interface class \alib{lang::resources;ResourcePool},
34 * which does externalize resources by using the mechanics provided with module \alib_config.
35 *
36 * A (shared) instance of this class can be attached to each \alibmod, with
37 * \ref alib_manual_bootstrapping "customization the bootstrapping of ALib".
38 *
39 * \see
40 * Please consult the \ref alib_basecamp_resources "Programmer's Manual" of module \alib_basecamp_nl
41 * for details on the concept of resources. Details on this specific type are given in chapter
42 * \ref alib_basecamp_resources_interface_config "3.4.2 Class ConfigResourcePool".
43 **************************************************************************************************/
45#if ALIB_THREADS
46 , public threads::ThreadLock
47#endif
48
49{
50 // #############################################################################################
51 // internal fields
52 // #############################################################################################
53 protected:
54 /**
55 * Monotonic allocator used for the hash map.
56 */
58
59 /** A hash map used to store resources that have been acquired.
60 * While this also improves performance, a cache is needed to assure persistence of
61 * the values. */
63
64 /** An only locally used object. Declared as field member to be reusable. */
66
67 // #############################################################################################
68 // public fields
69 // #############################################################################################
70 public:
71 /** The configuration object for custom resource data. */
73
74
75
76 // #############################################################################################
77 // Constructor/Destructor
78 // #############################################################################################
79 public:
80 /**
81 * Constructor. Creates a configuration object without one plug-in of type
82 * \alib{config;InMemoryPlugin} with
83 * \alib{config;Priorities;Priorities::DefaultValues;default priority}.
84 * After construction, one or more custom plug-ins have to be added. Those may be emplaced
85 * in this object's \alib{monomem;MonoAllocator}
86 */
89
90 /** Destructor. */
92 ~ConfigResourcePool() override;
93
94 // #############################################################################################
95 // Resource Interface
96 // #############################################################################################
97
98 /** ********************************************************************************************
99 * Implements abstract method \alib{lang::resources;ResourcePool::BootstrapAddOrReplace}.
100 *
101 * @param category Category string of the resource.
102 * @param name Name string of the resource
103 * @param data The resource string.
104 * @return \c true if the resource did exist and was replaced, \c false if it was an insertion.
105 **********************************************************************************************/
106 bool BootstrapAddOrReplace( const NString& category,
107 const NString& name,
108 const String& data ) override;
109
110
111 /** ********************************************************************************************
112 * Implements abstract method \alib{lang::resources;ResourcePool::BootstrapBulk}.
113 *
114 * @param category Category string of the resource. For technical reasons, this has to be
115 * of type <c>const nchar*</c>.
116 * @param ... A list of pairs of <b>const nchar*</b> and <b>const character*</b>
117 * keys and data.
118 **********************************************************************************************/
120 virtual
121 void BootstrapBulk( const nchar* category, ... ) override;
122
123#if defined(ALIB_DOX)
124 /** ********************************************************************************************
125 * Implements abstract method \alib{lang::resources;ResourcePool::Get}.
126 *
127 * @param category Category string of the resource.
128 * @param name Name string of the resource
129 * @param dbgAssert This parameter is available only in debug mode. If \c true, an assertion
130 * is raised if the resource was not found.
131 * @return The resource string, respectively a \e nulled string on failure.
132 **********************************************************************************************/
133 NALIB_API
134 const String& Get( const NString& category, const NString& name, bool dbgAssert ) override;
135#else
137 const String& Get( const NString& category, const NString& name
138 ALIB_DBG(, bool dbgAssert) ) override;
139#endif
140
141}; // class ConfigResourcePool
142
143} // namespace [alib::lang::resources]
144
145
146
147#endif // HPP_ALIB_LANG_RESOURCES_CONFIG_RESOURCE_POOL
virtual ALIB_API void BootstrapBulk(const nchar *category,...) override
bool BootstrapAddOrReplace(const NString &category, const NString &name, const String &data) override
#define ALIB_ASSERT_MODULE(modulename)
Definition alib.hpp:190
#define ALIB_API
Definition alib.hpp:538
#define ALIB_DBG(...)
Definition alib.hpp:457
@ Get
Denotes to search data.
characters::nchar nchar
Type alias in namespace alib.