ALib C++ Library
Library Version: 2412 R0
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 inner 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#pragma once
12
14ALIB_ASSERT_MODULE(CONFIGURATION)
15
16#include "alib/lang/resources/detail/resourcemap.hpp"
18#if ALIB_THREADS
20#endif
21
22namespace alib { namespace config {
23
24#if ALIB_THREADS || DOXYGEN
25/// This class provides an implementation of abstract interface class
26/// \alib{lang::resources;ResourcePool}, which does externalize resources by using the mechanics
27/// provided with module \alib_config.
28///
29/// A (shared) instance of this class can be attached to each \alibmod, with
30/// \ref alib_manual_bootstrapping "customization the bootstrapping of ALib".
31///
32/// \see
33/// Please consult the \ref alib_basecamp_resources "Programmer's Manual" of module
34/// \alib_basecamp_nl for details on the concept of resources. Details on this specific type are
35/// given in chapter \ref alib_basecamp_resources_interface_config "3.4.2 Class ConfigResourcePool".
37 , public TSharedConfiguration<SharedLock>
38{
39#else
41 , public TSharedConfiguration<void>
42{
43#endif
44 //======================================== Internals =========================================
45 protected:
46
47 /// Protected definition of inherited method.
48 /// @param createDefaults Determines if default plug-ins are to be created.
49 /// Defaults to \c Yes.
52
53 //================================= Construction/Destruction =================================
54 public:
55 /// Constructor. Creates a configuration object without any default plug-ins.
56 /// After construction, the "resource data", in this case variable values, has to be added.
57 /// @param initialBufferSizeInKB The initial size of memory buffers.
58 /// Defaults to \c 16.
59 /// Passed to the constructor parent \alib{config;Configuration}.
60 /// @param bufferGrowthInPercent Optional growth factor in percent, applied to the buffer size
61 /// with each next buffer allocation.
62 /// Should be set to \c 200, to double the size with each
63 /// allocation.
64 /// Defaults to \c 200.
65 /// Passed to the constructor parent \alib{config;Configuration}.
66 ConfigResourcePool(size_t initialBufferSizeInKB = 4,
67 unsigned int bufferGrowthInPercent = 200 )
68 : TSharedConfiguration(initialBufferSizeInKB, bufferGrowthInPercent, lang::CreateDefaults::No) {}
69
70 /// Default Destructor.
71 virtual ~ConfigResourcePool() override = default;
72
73 //================================== ResourcePool Interface ==================================
74 //==============================================================================================
75 /// Implements abstract method \alib{lang::resources;ResourcePool::BootstrapAddOrReplace}.
76 ///
77 /// @param category Category string of the resource.
78 /// @param name Name string of the resource
79 /// @param data The resource string.
80 /// @return \c true if the resource did exist and was replaced, \c false if it was an insertion.
81 //==============================================================================================
82 bool BootstrapAddOrReplace( const NString& category,
83 const NString& name,
84 const String& data ) override;
85
86
87 //==============================================================================================
88 /// Implements abstract method \alib{lang::resources;ResourcePool::BootstrapBulk}.
89 /// All variables are written using \alib{config;Priority;Priority::DefaultValues}.
90 ///
91 /// @param category Category string of the resource. For technical reasons, this has to be
92 /// of type <c>const nchar*</c>.
93 /// @param ... A list of pairs of <b>const nchar*</b> and <b>const character*</b>
94 /// keys and data.
95 //==============================================================================================
97 virtual
98 void BootstrapBulk( const nchar* category, ... ) override;
99
100#if DOXYGEN
101 //==============================================================================================
102 /// Implements abstract method \alib{lang::resources;ResourcePool::Get}.
103 ///
104 /// @param category Category string of the resource.
105 /// @param name Name string of the resource
106 /// @param dbgAssert This parameter is available (and to be passed) only in debug mode.
107 /// If \c true, an assertion is raised if the resource was not found.
108 /// @return The resource string, respectively a \e nulled string on failure.
109 //==============================================================================================
110 NALIB_API
111 const String& Get( const NString& category, const NString& name, bool dbgAssert ) override;
112#else
114 const String& Get( const NString& category, const NString& name
115 ALIB_DBG(, bool dbgAssert) ) override;
116#endif
117
118}; // class ConfigResourcePool
119
120} // namespace alib[::config]
121
122
123/// Type alias in namespace \b alib.
125
126
127} // namespace [alib]
128
129
130#endif // HPP_ALIB_LANG_RESOURCES_CONFIG_RESOURCE_POOL
131
virtual ALIB_API void BootstrapBulk(const nchar *category,...) override
bool BootstrapAddOrReplace(const NString &category, const NString &name, const String &data) override
ConfigResourcePool(size_t initialBufferSizeInKB=4, unsigned int bufferGrowthInPercent=200)
virtual ~ConfigResourcePool() override=default
Default Destructor.
void Reset(lang::CreateDefaults createDefaults=lang::CreateDefaults::Yes)
void Reset(lang::CreateDefaults createDefaults=lang::CreateDefaults::Yes)
#define ALIB_ASSERT_MODULE(modulename)
Definition alib.hpp:223
#define ALIB_API
Definition alib.hpp:639
#define ALIB_DBG(...)
Definition alib.hpp:390
CreateDefaults
Denotes whether default entities should be created or not.
@ Yes
Create default values.
Definition alib.cpp:69
characters::nchar nchar
Type alias in namespace alib.