ALib C++ Library
Library Version: 2510 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 C++ Module of the \aliblong. Due to the dual-compile option - as either
23 /// C++20 Modules or legacy C++ inclusion, the C++20 Module names are not of further interest
24 /// 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 /// This chapter, among others, provides further explanations.
28 export module ALib.Variables.ResourcePool;
29 import ALib.Lang;
30# if !ALIB_SINGLE_THREADED
31 import ALib.Threads;
32# endif
33 import ALib.Monomem;
36 import ALib.Strings;
37 import ALib.Boxing;
38 import ALib.Exceptions;
39 import ALib.Resources;
40 import ALib.System;
41 import ALib.Variables;
42#else
43# include "ALib.Lang.H"
44# if !ALIB_SINGLE_THREADED
45# include "ALib.Threads.H"
46# endif
47# include "ALib.Monomem.H"
48# include "ALib.Containers.List.H"
50# include "ALib.Strings.H"
51# include "ALib.Boxing.H"
52# include "ALib.Exceptions.H"
53# include "ALib.Resources.H"
54# include "ALib.System.H"
55# include "ALib.Variables.H"
56#endif
57
58// ========================================== Exports ==========================================
59ALIB_EXPORT namespace alib { namespace variables {
60
61#if !ALIB_SINGLE_THREADED || DOXYGEN
62/// This class provides an implementation of abstract interface class
63/// \alib{resources;ResourcePool}, which does externalize resources by using the mechanics
64/// provided with module \alib_variables.
65///
66/// A (shared) instance of this class can be attached to each \alibmod, by
67/// \ref alib_mod_bs "customizing the bootstrapping of ALib".
68///
69/// \see
70/// Please consult the \ref alib_mod_resources "Programmer's Manual" of module
71/// \alib_resources_nl for details on the concept of resources. Details on this specific type are
72/// given in chapter \ref alib_resources_interface_config "3.4.2 Class ConfigResourcePool".
74 , public TSharedConfiguration<SharedLock>
75{
76#else
78 , public TSharedConfiguration<void>
79{
80#endif
81 //======================================== Internals =========================================
82 protected:
83
84 /// Protected definition of inherited method.
85 /// @param createDefaults Determines if default plug-ins are to be created.
86 /// Defaults to \c Yes.
89
90 //================================= Construction/Destruction =================================
91 public:
92 /// Constructor. Creates a configuration object without any default plug-ins.
93 /// After construction, the "resource data", in this case variable values, has to be added.
94 /// @param initialBufferSizeInKB The initial size of memory buffers.
95 /// Defaults to \c 16.
96 /// Passed to the constructor parent \alib{variables;Configuration}.
97 /// @param bufferGrowthInPercent Optional growth factor in percent, applied to the buffer size
98 /// with each next buffer allocation.
99 /// Should be set to \c 200, to double the size with each
100 /// allocation.
101 /// Defaults to \c 200.
102 /// Passed to the constructor parent \alib{variables;Configuration}.
103 ConfigResourcePool(size_t initialBufferSizeInKB = 4,
104 unsigned int bufferGrowthInPercent = 200 )
105 : TSharedConfiguration(initialBufferSizeInKB, bufferGrowthInPercent, lang::CreateDefaults::No) {}
106
107 /// Default Destructor.
108 virtual ~ConfigResourcePool() override = default;
109
110 //================================== ResourcePool Interface ==================================
111 //==============================================================================================
112 /// Implements abstract method \alib{resources;ResourcePool::BootstrapAddOrReplace}.
113 ///
114 /// @param category Category string of the resource.
115 /// @param name Name string of the resource
116 /// @param data The resource string.
117 /// @return \c true if the resource did exist and was replaced, \c false if it was an insertion.
118 //==============================================================================================
119 bool BootstrapAddOrReplace( const NString& category,
120 const NString& name,
121 const String& data ) override;
122
123
124 //==============================================================================================
125 /// Implements abstract method \alib{resources;ResourcePool::BootstrapBulk}.
126 /// All variables are written using \alib{variables;Priority;Priority::DefaultValues}.
127 ///
128 /// @param category Category string of the resource. For technical reasons, this has to be
129 /// of type <c>const nchar*</c>.
130 /// @param ... A list of pairs of <b>const nchar*</b> and <b>const character*</b>
131 /// keys and data.
132 //==============================================================================================
134 virtual
135 void BootstrapBulk( const nchar* category, ... ) override;
136
137#if DOXYGEN
138 //==============================================================================================
139 /// Implements abstract method \alib{resources;ResourcePool::Get}.
140 ///
141 /// @param category Category string of the resource.
142 /// @param name Name string of the resource
143 /// @param dbgAssert This parameter is available (and to be passed) only in debug mode.
144 /// If \c true, an \ref alib_mod_assert "error is raised" if the resource was not found.
145 /// @return The resource string, respectively a \e nulled string on failure.
146 //==============================================================================================
148 const String& Get( const NString& category, const NString& name, bool dbgAssert ) override;
149#else
151 const String& Get( const NString& category, const NString& name
152 ALIB_DBG(, bool dbgAssert) ) override;
153#endif
154
155}; // class ConfigResourcePool
156
157} // namespace alib[::config]
158
159/// Type alias in namespace \b alib.
161
162} // namespace [alib]
163
164
virtual ALIB_DLL void BootstrapBulk(const nchar *category,...) override
void Reset(lang::CreateDefaults createDefaults=lang::CreateDefaults::Yes)
virtual ~ConfigResourcePool() override=default
Default Destructor.
ConfigResourcePool(size_t initialBufferSizeInKB=4, unsigned int bufferGrowthInPercent=200)
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:496
#define ALIB_EXPORT
Definition alib.inl:488
#define ALIB_DBG(...)
Definition alib.inl:836
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:2390
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:2381