ALib C++ Library
Library Version: 2511 R0
Documentation generated by doxygen
Loading...
Searching...
No Matches
configresourcepool.mpp
Go to the documentation of this file.
1//==================================================================================================
2/// \file
3/// This header-file is part of the \aliblong.
4/// With supporting legacy or module builds, .mpp-files are either recognized by the build-system
5/// as C++20 Module interface files, or are included by the
6/// \ref alib_manual_modules_impludes "import/include headers".
7///
8/// \emoji :copyright: 2013-2025 A-Worx GmbH, Germany.
9/// Published under \ref mainpage_license "Boost Software License".
10//==================================================================================================
11#if !defined(ALIB_C20_MODULES) || ((ALIB_C20_MODULES != 0) && (ALIB_C20_MODULES != 1))
12# error "Symbol ALIB_C20_MODULES has to be given to the compiler as either 0 or 1"
13#endif
14#if ALIB_C20_MODULES
15 module;
16#endif
17//========================================= Global Fragment ========================================
19
20//============================================== Module ============================================
21#if ALIB_C20_MODULES
22 /// This is a <em><b>C++ Module</b></em> of the \aliblong.
23 /// Due to the dual-compile option (either as C++20 Modules or using legacy C++ inclusion),
24 /// the C++20 Module names are not of further interest or use.<br>
25 /// In general, the names equal the names of the header files listed in the chapter
26 /// \ref alib_manual_modules_impludes of the \alib User Manual.
27 ///
28 /// @see The documentation of the <em><b>"ALib Module"</b></em> given with the corresponding
29 /// Programmer's Manual \alib_variables.
30 export module ALib.Variables.ResourcePool;
31 import ALib.Lang;
32# if !ALIB_SINGLE_THREADED
33 import ALib.Threads;
34# endif
35 import ALib.Monomem;
36 import ALib.Containers.List;
37 import ALib.Containers.HashTable;
38 import ALib.Strings;
39 import ALib.Boxing;
40 import ALib.Exceptions;
41 import ALib.Resources;
42 import ALib.System;
43 import ALib.Variables;
44#else
45# include "ALib.Lang.H"
46# if !ALIB_SINGLE_THREADED
47# include "ALib.Threads.H"
48# endif
49# include "ALib.Monomem.H"
50# include "ALib.Containers.List.H"
52# include "ALib.Strings.H"
53# include "ALib.Boxing.H"
54# include "ALib.Exceptions.H"
55# include "ALib.Resources.H"
56# include "ALib.System.H"
57# include "ALib.Variables.H"
58#endif
59
60//============================================= Exports ============================================
61ALIB_EXPORT namespace alib { namespace variables {
62
63#if !ALIB_SINGLE_THREADED || DOXYGEN
64/// This class provides an implementation of abstract interface class
65/// \alib{resources;ResourcePool}, which does externalize resources by using the mechanics
66/// provided with module \alib_variables.
67///
68/// A (shared) instance of this class can be attached to each \alibmod, by
69/// \ref alib_mod_bs "customizing the bootstrapping of ALib".
70///
71/// \see
72/// Please consult the \ref alib_mod_resources "Programmer's Manual" of module
73/// \alib_resources_nl for details on the concept of resources. Details on this specific type are
74/// given in chapter \ref alib_resources_interface_config "3.4.2 Class ConfigResourcePool".
76 , public TSharedConfiguration<SharedLock>
77{
78#else
80 , public TSharedConfiguration<void>
81{
82#endif
83 //=========================================== Internals ==========================================
84 protected:
85
86 /// Protected definition of inherited method.
87 /// @param createDefaults Determines if default plug-ins are to be created.
88 /// Defaults to \c Yes.
91
92 //==================================== Construction/Destruction ==================================
93 public:
94 /// Constructor. Creates a configuration object without any default plug-ins.
95 /// After construction, the "resource data", in this case variable values, has to be added.
96 /// @param initialBufferSizeInKB The initial size of memory buffers.
97 /// Defaults to \c 16.
98 /// Passed to the constructor parent \alib{variables;Configuration}.
99 /// @param bufferGrowthInPercent Optional growth factor in percent, applied to the buffer size
100 /// with each next buffer allocation.
101 /// Should be set to \c 200, to double the size with each
102 /// allocation.
103 /// Defaults to \c 200.
104 /// Passed to the constructor parent \alib{variables;Configuration}.
105 ConfigResourcePool(size_t initialBufferSizeInKB = 4,
106 unsigned bufferGrowthInPercent = 200 )
107 : TSharedConfiguration(initialBufferSizeInKB,bufferGrowthInPercent,lang::CreateDefaults::No) {}
108
109 /// Default Destructor.
110 virtual ~ConfigResourcePool() override =default;
111
112 //===================================== ResourcePool Interface ===================================
113 /// Implements abstract method \alib{resources;ResourcePool::BootstrapAddOrReplace}.
114 ///
115 /// @param category Category string of the resource.
116 /// @param name Name string of the resource
117 /// @param data The resource string.
118 /// @return \c true if the resource did exist and was replaced, \c false if it was an insertion.
119 bool BootstrapAddOrReplace( const NString& category,
120 const NString& name,
121 const String& data ) override;
122
123
124 /// Implements abstract method \alib{resources;ResourcePool::BootstrapBulk}.
125 /// All variables are written using \alib{variables;Priority;Priority::DefaultValues}.
126 ///
127 /// @param category Category string of the resource. For technical reasons, this has to be
128 /// of type <c>const nchar*</c>.
129 /// @param ... A list of pairs of <b>const nchar*</b> and <b>const character*</b>
130 /// keys and data.
132 virtual
133 void BootstrapBulk( const nchar* category, ... ) override;
134
135#if DOXYGEN
136 //==============================================================================================
137 /// Implements abstract method \alib{resources;ResourcePool::Get}.
138 ///
139 /// @param category Category string of the resource.
140 /// @param name Name string of the resource
141 /// @param dbgAssert This parameter is available (and to be passed) only in debug mode.
142 /// If \c true, an \ref alib_mod_assert "error is raised" if the resource was not found.
143 /// @return The resource string, respectively a \e nulled string on failure.
144 //==============================================================================================
146 const String& Get( const NString& category, const NString& name, bool dbgAssert ) override;
147#else
149 const String& Get( const NString& category, const NString& name
150 ALIB_DBG(, bool dbgAssert) ) override;
151#endif
152
153}; // class ConfigResourcePool
154
155} // namespace alib[::config]
156
157/// Type alias in namespace \b alib.
159
160} // namespace [alib]
virtual ALIB_DLL void BootstrapBulk(const nchar *category,...) override
ConfigResourcePool(size_t initialBufferSizeInKB=4, unsigned bufferGrowthInPercent=200)
void Reset(lang::CreateDefaults createDefaults=lang::CreateDefaults::Yes)
virtual ~ConfigResourcePool() override=default
Default Destructor.
bool BootstrapAddOrReplace(const NString &category, const NString &name, const String &data) override
void Reset(lang::CreateDefaults createDefaults=lang::CreateDefaults::Yes)
#define ALIB_DLL
Definition alib.inl:503
#define ALIB_EXPORT
Definition alib.inl:497
#define ALIB_DBG(...)
Definition alib.inl:853
CreateDefaults
Denotes whether default entities should be created or not.
@ Yes
Create default values.
strings::TString< nchar > NString
Type alias in namespace alib.
Definition string.inl:2198
resources::ResourcePool ResourcePool
Type alias in namespace alib.
characters::nchar nchar
Type alias in namespace alib.
variables::ConfigResourcePool ConfigResourcePool
Type alias in namespace alib.
strings::TString< character > String
Type alias in namespace alib.
Definition string.inl:2189