This class is the container for ALib variables.
The use of this type is documented with the Programmer's Manual of camp ALib Configuration.
Beside the interface that this class provides, publicly inherited interfaces of base types StringTree and PluginContainer are available for use.
Definition at line 165 of file configuration.hpp.
#include <configuration.hpp>
Inner Type Index: | |
struct | ListenerRecord |
Record used to manage registered listeners. More... | |
struct | ValueDescriptorRD |
Helper-struct used for implementing field replacementDeclarations. More... | |
struct | ValueDescriptorTypes |
Helper-struct used for implementing field types. More... | |
Public Field Index: | |
List< MonoAllocator, std::pair< Token, Token >, Recycling::None > | BooleanTokens |
StringEscaperStandard | Escaper |
alib::NumberFormat | NumberFormat |
PoolAllocator | Pool |
CString | SubstitutionVariableDelimiters = A_CHAR(" $@,.;:\"\'+-*\\§%&()[]{}<>=?'`~#") |
String | SubstitutionVariableEnd = A_CHAR("}") |
String | SubstitutionVariableStart = A_CHAR("${") |
Protected Type Index: | |
using | RDHashTable |
using | TypesHashTable |
A hashtable for the registered types. Key is the type name, value is the VMeta singleton. | |
Protected Type Index: inherited from StringTreeBase< TAllocator, T, TNodeHandler, TRecycling > | |
using | CharacterType = typename TNodeHandler::CharacterType |
using | ConstCursorBase = TCursorBase<true> |
The constant version of type StringTreeBase::TCursorBase<TConst>. | |
using | CursorBase = TCursorBase<false> |
The mutable version of type StringTreeBase::TCursorBase<TConst>. | |
using | NameStorageType = typename TNodeHandler::NameStringType |
using | NameType = const strings::TString<CharacterType> |
The string-type of node names and paths if provided externally for comparison. | |
using | NodeList = lang::BidiListHook<NodeBase> |
Alias shortcut for a bidirectional list of Node elements. | |
using | SharedRecyclerType = typename decltype(nodeTable)::SharedRecyclerType |
using | SubstringType = typename strings::TSubstring<CharacterType> |
Protected Field Index: | |
CLIVariablesPlugin * | cliPlugin |
A default plugin created and inserted with construction. | |
EnvironmentVariablesPlugin * | environmentPlugin |
A default plugin created and inserted with construction. | |
List< MonoAllocator, ListenerRecord > | listeners |
The list of registered listeners. | |
RDHashTable | replacementDeclarations |
TypesHashTable | types |
A hashtable for the registered types. Key is the type name, value is the VMeta singleton. | |
Protected Field Index: inherited from StringTreeBase< TAllocator, T, TNodeHandler, TRecycling > | |
int | dbgRootDataSet = 0 |
HashTable< TAllocator, typename NodeKey::ValueDescriptor, typename NodeKey::Hash, typename NodeKey::EqualTo, lang::Caching::Enabled, TRecycling > | nodeTable |
RootNodeSpacer | root |
The root node. | |
CharacterType | separator |
Protected Field Index: inherited from PluginContainer< ConfigurationPlugin, Priority > | |
std::vector< Slot > | plugins |
The plug-ins we have attached in descending priority order. | |
Protected Method Index: | |
ALIB_API void | notifyListeners (int event, const Variable &variable, const String &variablePath, Priority previousPriority) |
ALIB_API void | presetImportString (const String &name, const String &value, const StringEscaper *escaper, Priority priority) |
ALIB_API void | registerListener (ConfigurationListener *listener, lang::ContainerOp insertOrRemove, int event, const Variable *variable, const StringTree::Cursor *subTree, const String &variableName, const String &pathPrefix, const String &pathSubstring) |
template<typename TVMeta > | |
void | registerType () |
Protected Method Index: inherited from StringTree< TAllocator, T, TNodeHandler, TRecycling > | |
Cursor | createCursor (baseNode &node) |
Protected Method Index: inherited from StringTreeBase< TAllocator, T, TNodeHandler, TRecycling > | |
StringTreeBase (TAllocator &allocator, CharacterType pathSeparator) | |
template<typename TSharedRecycler = SharedRecyclerType, ATMP_T_IF(int, !ATMP_EQ(TSharedRecycler, void)) = 0> | |
StringTreeBase (TAllocator &allocator, TSharedRecycler &pRecycler, CharacterType pathSeparator) | |
template<typename TSharedRecycler = SharedRecyclerType, ATMP_T_IF(int, !ATMP_EQ(TSharedRecycler, void)) = 0> | |
StringTreeBase (TSharedRecycler &pRecycler, CharacterType pathSeparator) | |
bool | checkChildName (const NameType &name) const |
TAllocator & | GetAllocator () noexcept |
Private Type Index: | |
using | base = StringTree<MonoAllocator,detail::Entry, detail::ConfigNodeHandler> |
Alias to the StringTree-parent. | |
Additional Inherited Members | |
Public Type Index: inherited from StringTree< TAllocator, T, TNodeHandler, TRecycling > | |
using | AllocatorType = TAllocator |
Type definition publishing template parameter TAllocator. | |
using | CharacterType = typename TNodeHandler::CharacterType |
using | ConstCursor = TCursor<true> |
The constant version of type StringTree::TCursor<TConst>. | |
using | ConstRecursiveIterator = TRecursiveIterator<true> |
The constant version of type StringTree::TRecursiveIterator<TConst>. | |
using | Cursor = TCursor<false> |
The mutable version of type StringTree::TCursor<TConst>. | |
using | HandlerType = TNodeHandler |
Type definition publishing template parameter TNodeHandler. | |
using | NameType = strings::TString<CharacterType> |
using | RecursiveIterator = TRecursiveIterator<false> |
The mutable version of type StringTree::TRecursiveIterator<TConst>. | |
using | SharedRecyclerType = typename basetree::SharedRecyclerType |
using | SubstringType = typename strings::TSubstring<CharacterType> |
Public Type Index: inherited from PluginContainer< ConfigurationPlugin, Priority > | |
using | PluginType |
This exposes the template parameter pTPlugin to the outer world. | |
using | PrioritiesType |
This exposes the template parameter pTPlugin to the outer world. | |
|
friend |
Definition at line 174 of file configuration.hpp.
|
friend |
Definition at line 173 of file configuration.hpp.
|
friend |
Type alias in namespace alib.
Definition at line 172 of file configuration.hpp.
|
private |
Alias to the StringTree-parent.
Definition at line 169 of file configuration.hpp.
|
protected |
Type definition of the container that stores declarations allocated with method Configuration::StoreDeclaration.
Definition at line 239 of file configuration.hpp.
|
protected |
A hashtable for the registered types. Key is the type name, value is the VMeta singleton.
Definition at line 217 of file configuration.hpp.
List<MonoAllocator, std::pair<Token,Token>, Recycling::None> BooleanTokens |
This is a list that holds pairs of type strings::util::Token which is used by the built-in boolean variable type (type name "B"). The list defines how extern string data (for example, from command line args, environment variables, or INI-files) is converted to boolean values.
When parsed from outside, the index of the pair that had the match is stored and in the case of writing back (e.g., to the INI-file), the corresponding representation of this pair will be written out. (For example, if a user used "On" in the configuration file, and the software switched it to false
, the word "Off" is to be written.
During bootstrap, this list might be modified, but before any variable was read. Otherwise the indices would become invalid. However, the preferred way of changing the accepted tokens is to modify the resources. This allows having localization of terms, in case this should be needed some day.
If even with modification of the predefined list, some other needs or flexibility is wanted, then the definition of an alternative boolean configuration variable type is the way to go.
The list of resourced predefined tokens after construction of a configuration is:
Index | True Token | False Token |
---|---|---|
0 | false I 1 | true I 1 |
1 | 0 I 1 | 1 I 1 |
2 | no I 1 | yes I 1 |
3 | off I 3 | on I 2 |
4 | — I 1 | OK I 2 |
Definition at line 360 of file configuration.hpp.
|
protected |
A default plugin created and inserted with construction.
Definition at line 201 of file configuration.hpp.
|
protected |
A default plugin created and inserted with construction.
Definition at line 204 of file configuration.hpp.
StringEscaperStandard Escaper |
A standard string escaper that can be used to set preset values received from external escaped strings.
Definition at line 311 of file configuration.hpp.
|
protected |
The list of registered listeners.
Definition at line 252 of file configuration.hpp.
Number format definition used to read and write int and float values. Can be tweaked to change the way external information is parsed.
Definition at line 307 of file configuration.hpp.
PoolAllocator Pool |
An object pool for recycling variable values as well as the hashtable entries. It is chained to the allocator provided with construction.
The pool may be used in accordance with the general rules imposed by camp ALib Monomem. If so, in multithreaded environments, this configuration has to be locked (in addition to all other custom locks when interfacing this type), when using this pool from custom code.
Definition at line 184 of file configuration.hpp.
|
protected |
A hashtable for declarations allocated with method Configuration::StoreDeclaration.
Definition at line 249 of file configuration.hpp.
The delimiters used to identify the end of a substitutable variable. If field SubstitutionVariableEnd is not empty, this field is ignored. Otherwise, all characters defined in this string are used to identify the end of a substitution variable.
Definition at line 328 of file configuration.hpp.
The end of a substitution variables. If this field is set, then field SubstitutionVariableDelimiters is ignored. If this field is nullptr (the default) or empty, it is ignored and characters in field SubstitutionVariableDelimiters are used to identify the end of the variable.
Definition at line 322 of file configuration.hpp.
The start string to identify substitution variables. Defaults to single character '$'
. If a string is set, i.e., "${"
, then field SubstitutionVariableEnd may be set accordingly, i.e., "}"
Definition at line 316 of file configuration.hpp.
|
protected |
A hashtable for the registered types. Key is the type name, value is the VMeta singleton.
Definition at line 225 of file configuration.hpp.
Configuration | ( | MonoAllocator & | allocator, |
lang::CreateDefaults | createDefaults = lang::CreateDefaults::Yes ) |
Constructs a Configuration.
If addDefaultPlugins is true
, registers the initial plug-ins as follows:
Priority | Plug-in Type |
---|---|
Priority::Environment | EnvironmentVariablesPlugin |
Priority::CLI | CLIVariablesPlugin |
Furthermore all built-in variable types are registered.
Modifications (in respect to plug-ins and registered types) should be performed during bootstrap, right after construction of this type (when no parallel threads are active) or with prior locking the Configuration instance.
allocator | The allocator to use. |
createDefaults | Determines if default plug-ins are to be created. Defaults to Yes . |
Definition at line 55 of file configuration.cpp.
~Configuration | ( | ) |
Destructor.
Definition at line 89 of file configuration.cpp.
bool DeletePath | ( | const String & | path | ) |
Deletes the given variable path, respectively all variables under the given path as well as the path node itself.
This is a convenience method. Full access to the underlying StringTree is provided by public inheritance, which offers many other ways of manipulating variable data. As an example, consider the implementation of this method:
path | The path in the variable tree. |
true
on success, false
, if the given path was not found. Definition at line 394 of file configuration.cpp.
|
inline |
Inserts or removes a listener to a specific variable. Note that this version of the method cannot be used to fetch declaration events, because the given variable obviously is already declared and created.
insertOrRemove | Denotes whether the listener should be inserted or removed. (Only enum elements ContainerOp::Insert or ContainerOp::Remove must be passed.) |
listener | The listener to register. |
event | The event to listen to. |
variable | The variable to listen to. |
Definition at line 557 of file configuration.hpp.
|
inline |
Inserts or removes a listener for all variables below subtree specified by the given cursor.
insertOrRemove | Denotes whether the listener should be inserted or removed. (Only enum elements ContainerOp::Insert or ContainerOp::Remove must be passed.) |
listener | The listener to register. |
event | The event to listen to. |
cursor | The parent node in the configuration variable tree of the variables to monitor. |
Definition at line 600 of file configuration.hpp.
|
inline |
Inserts or removes a listener for all variables below the subtree specified by the given startPath.
insertOrRemove | Denotes whether the listener should be inserted or removed. (Only enum elements ContainerOp::Insert or ContainerOp::Remove must be passed.) |
listener | The listener to register. |
event | The event to listen to. |
pathPrefix | The path prefix of the subtree of variables to monitor. Note that a missing leading separator character '/' will be added. |
Definition at line 624 of file configuration.hpp.
|
inline |
Inserts or removes a listener for all variables below the subtree specified by the given startPath.
insertOrRemove | Denotes whether the listener should be inserted or removed. (Only enum elements ContainerOp::Insert or ContainerOp::Remove must be passed.) |
listener | The listener to register. |
event | The event to listen to. |
pathSubstring | The substring to match in the path (including the variable name) of the variables to monitor. |
Definition at line 647 of file configuration.hpp.
int MonitorStop | ( | ConfigurationListener * | listener | ) |
Removes all registrations of the given listener.
listener | The listener to remove. |
Definition at line 155 of file configuration.cpp.
|
inline |
Inserts or removes a listener for all variables that share the given variableName.
insertOrRemove | Denotes whether the listener should be inserted or removed. (Only enum elements ContainerOp::Insert or ContainerOp::Remove must be passed.) |
listener | The listener to register. |
event | The event to listen to. |
variableName | The name of one or more variables to listen to. |
Definition at line 579 of file configuration.hpp.
|
protected |
Notifies registered listeners on events.
event | The event that occurred. |
variable | The variable. |
variablePath | The full path of the variable. Might be nulled if not available, yet. |
previousPriority | The priority of the variable before the event. |
Definition at line 174 of file configuration.cpp.
std::pair< bool, int8_t > ParseBooleanToken | ( | const String & | src | ) |
Utility method that checks if a given value represents boolean true.
src | The input string to check. |
(false,-1)
is returned. Definition at line 360 of file configuration.cpp.
|
inline |
Declares and defines all variables of the given enum type which do not contain placeholders are contained in the variable's name.
The purpose of this method is to fill the configuration system with variables (usually during or right after bootstrap) regardless of their later use, which depends on the concrete execution path of a run of a software. The rationale to do this is is twofold:
Alltogether, the use of this method does not not impose much of an overhead, because:
TEnum | Enumeration type equipped with ALib Enum Records of type Declaration. |
|
inline |
Same as overloaded version PresetImportString(const String&, const String&,StringEscaper*, Priority), but does not accept an StringEscaper and thus expects the value is in C++ internal string format (aka 'not escaped').
name | The name of the variable. |
value | The value to import. |
priority | The priority to set for the value. Defaults to Default. |
Definition at line 500 of file configuration.hpp.
|
inline |
Stores the given information as a default value, which will be assigned to a variable as soon as it is declared. If a variable is deleted and later again declared, the given value is again imported. In other words, a preset will not be removed with a first declaration and use.
To delete a previously set import string, a nulled string is to be passed with for parameter value.
This method is to be used in cases when a declaration of a variable is not possible, i.e., when a variable's type is not known, which often is the case when external configuration values are to be set.
name | The name of the variable. |
value | The value to import. Will be 'unescaped' using escaper. |
escaper | The escaper to use for importing. Has to be still valid at the time(s) the value read. A pointer to field Escaper might be passed here. |
priority | The priority to set for the value. Defaults to Default. |
Definition at line 488 of file configuration.hpp.
|
protected |
Stores the given information as a default value, which is imported to a variable as soon as it becomes declared.
name | The name of the variable. |
value | The value to import. |
escaper | The escaper to use for importing. |
priority | The priority to set for the value. |
Definition at line 209 of file configuration.cpp.
|
protected |
Implements the various overloaded listener registration methods.
listener | The listener to register or dispose. |
insertOrRemove | Denotes registration or disposal of a listener. |
event | The event to listen to. |
variable | If given, the exported value of the variable to listen to. |
subTree | If given, the exported value of the subtree of variables to listen to. |
variableName | If given, the variable's name to listen to. |
pathPrefix | If given, the start string of the path of the variables to monitor. |
pathSubstring | If given, the substring to match in the path (including the variable name) of the variables to monitor. |
Definition at line 99 of file configuration.cpp.
|
inline |
Registers a variable type with this configuration. The only parameter is the template parameter TVMeta. The function will create the singleton of this type and store it in a hash table of types. When a variable associated with this configuration object is declared, this variable type is used as the key to this hash table. Then this singleton object of the given type is responsible for construction, destruction and import/export of variables of this type.
TVMeta | The meta-information type of the type to register. |
Definition at line 398 of file configuration.hpp.
|
inlineprotected |
Implementation of Configuration::RegisterType.
TVMeta | The meta-information type of the type to register. |
Definition at line 258 of file configuration.hpp.
const Declaration * StoreDeclaration | ( | const Declaration * | orig, |
const Box & | replacements ) |
Creates and stores a declaration. Placeholders "%1"
, "%2"
... "%N"
found in the fields (except typeName) are replaced with the replacement values given with boxed argument (list) replacements.
orig | The original, typically resourced declaration with placeholders. |
replacements | A list of replacement values. Must be of boxed types that are alib::strings,T_Append,appendable "strings,T_Append,appendable" to class AString. To provide more than one object, pass an object of class alib::boxing,Boxes "boxing,Boxes" or a boxed array. |
Definition at line 272 of file configuration.cpp.
Utility method that writes the given boolean value as specified with the token found at index in BooleanTokens.
This method is used internally by the meta-information handler of variable type "B"
/bool
.
value | The boolean value to write. |
index | The token to use. If negative, this is corrected to 0 . |
dest | The destination string. |
Definition at line 376 of file configuration.cpp.