This is the central interface type into ALib Configuration Data. The class is a very lightweight (size of two times sizeof(void*)
) object, because it rather is a pointer to a variable instead of an implementation of its data structures. The types' true nature is inherited from class StringTree::Cursor which is the base of this class. The inheritance is defined protected
and this class received its own dedicated interface reflecting the domain of configuration variables. Nevertheless, the protected base type is accessible with the explicit cast method AsCursor. While a reader might think this is a contradiction, this was made by design: Casting to a StringTree::Cursor is only necessary for implementing ConfigurationPlugin or similar extraordinary things. For the common use, the dedicated interface is all that is needed.
Definition at line 698 of file configuration.hpp.
#include <configuration.hpp>
Public Method Index: | |
Variable ()=default | |
Variable (Configuration &cfg) | |
Variable (Configuration &cfg, const Declaration *decl) | |
Variable (Configuration &cfg, const String &name, const String &typeName, const String &defaultValue=NULL_STRING) | |
template<typename TEnum > | |
Variable (Configuration &cfg, TEnum Enum) | |
template<typename TEnum > | |
Variable (Configuration &cfg, TEnum Enum, const Box replacements) | |
Variable (const Cursor &cursor) | |
Variable (const Cursor &cursor, const String &typeName, const String &defaultValue=NULL_STRING) | |
Variable (const String &name, const String &typeName, const String &defaultValue=NULL_STRING) | |
Variable (lang::Camp &camp) | |
Variable (lang::Camp &camp, const Declaration *decl) | |
Variable (lang::Camp &camp, const String &name, const String &typeName, const String &defaultValue=NULL_STRING) | |
template<typename TEnum > | |
Variable (lang::Camp &camp, TEnum Enum) | |
template<typename TEnum > | |
Variable (lang::Camp &camp, TEnum Enum, const Box replacements) | |
Cursor & | AsCursor () |
const Cursor & | AsCursor () const |
ALIB_API Variable & | Declare (const Declaration *declaration) |
ALIB_API Variable & | Declare (const String &name, const String &typeName, const String &defaultValue=NULL_STRING) |
template<typename TEnum > | |
Variable & | Declare (TEnum Enum) |
template<typename TEnum > | |
Variable & | Declare (TEnum Enum, const Box &replacements) |
ALIB_API bool | Define (Priority requestedPriority=Priority::Standard) |
ALIB_API void | Delete () |
AString & | Export (AString &dest, const StringEscaper *escaper=nullptr) const |
template<typename T > | |
T & | Get () |
template<typename T > | |
const T & | Get () const |
bool | GetBool () |
Box & | GetBox () |
Configuration & | GetConfiguration () const |
const Declaration * | GetDeclaration () const |
double | GetDouble () |
float | GetFloat () |
integer | GetInt () |
bool | GetOrSetDefault (bool value, Priority priority=Priority::DefaultValues) |
String & | GetOrSetDefault (const String &value, Priority priority=Priority::DefaultValues) |
bool | GetOrSetDefault (integer value, Priority priority=Priority::DefaultValues) |
Priority | GetPriority () const |
AStringPA & | GetString () |
String & | GetString (int idx) |
StringVectorPA & | GetStrings () |
ALIB_API void | Import (const String &src, Priority priority, const StringEscaper *escaper=nullptr) |
bool | IsDeclared () const |
bool | IsDefined () const |
bool | IsDefinedExternally () const |
bool | IsNotDefined () const |
AString & | Name (AString &target) const |
operator bool () | |
operator const String & () | |
operator const Substring () | |
operator double () | |
operator float () | |
operator integer () | |
bool | operator= (bool val) |
Calls Get<Bool>() and assigns val. | |
const String & | operator= (const String &val) |
Calls Get<AStringPA>() and resets the string to val. | |
double | operator= (double val) |
Calls Get<double>() and assigns val. | |
float | operator= (float val) |
Calls Get<double>() and assigns val. | |
integer | operator= (integer val) |
Calls Get<integer>() and assigns val. | |
int | Size () |
ALIB_API bool | Try (const Declaration *decl) |
bool | Try (const String &name) |
ALIB_API bool | Try (const String &name, const String &typeName) |
Protected Method Index: | |
void | create (const String &typeName, const String &defaultValue) |
VMeta * | getMeta () const |
const String & | substitute (const String &importString, AString &buf, const StringEscaper *escaper) |
Protected Method Index: inherited from StringTree< TAllocator, T, TNodeHandler, TRecycling >::TCursor< TConst > | |
TCursor (cmTree *pTree, cmNode *pNode) noexcept | |
void | dbgCheckTree () const |
void | dbgCheckTreeAndNode () const |
TCursor () noexcept=default | |
TCursor (const TCursor &src) noexcept | |
TCursor (TCursor &&src) noexcept | |
~TCursor () noexcept=default | |
Trivial default destructor. | |
strings::TAString< typename cmTree::CharacterType, lang::HeapAllocator > & | AssemblePath (strings::TAString< typename cmTree::CharacterType, lang::HeapAllocator > &targetString, const TCursor< true > &parent, lang::CurrentData targetData=lang::CurrentData::Clear) const |
strings::TAString< typename cmTree::CharacterType, lang::HeapAllocator > & | AssemblePath (strings::TAString< typename cmTree::CharacterType, lang::HeapAllocator > &targetString, lang::CurrentData targetData=lang::CurrentData::Clear) const |
TCursor | Child (const NameType &name) const |
uinteger | CountChildren () const |
template<typename TCheck = CHK, typename... TArgs> | |
TCursor | CreateChild (const NameType &childName, TArgs &&... args) const |
template<typename... TArgs> | |
std::pair< TCursor, bool > | CreateChildIfNotExistent (const NameType &name, TArgs &&... args) |
template<typename... TArgs> | |
std::pair< TCursor, integer > | CreatePathIfNotExistent (const NameType &path, TArgs &&... args) |
uinteger | Delete () |
bool | DeleteChild (const NameType &childName) const |
void | DeleteChild (TCursor &child) const |
uinteger | DeleteChildren () const |
int | Depth () const |
int | Distance (const TCursor< true > &other) const |
CursorHandle | Export () |
ConstCursorHandle | Export () const |
TCursor | FirstChild () const |
SubstringType | GoTo (const NameType &path) |
bool | GoToChild (const NameType &name) |
template<typename... TArgs> | |
bool | GoToCreateChildIfNotExistent (const NameType &name, TArgs &&... args) |
template<typename... TArgs> | |
integer | GoToCreatedPathIfNotExistent (const NameType &path, TArgs &&... args) |
bool | GoToFirstChild () |
bool | GoToLastChild () |
bool | GoToNextSibling () |
TCursor & | GoToParent () |
bool | GoToPreviousSibling () |
TCursor & | GoToRoot () |
bool | HasChildren () const |
bool | HasNextSibling () const |
bool | HasPreviousSibling () const |
bool | IsInvalid () const |
bool | IsRoot () const |
bool | IsValid () const |
TCursor | LastChild () const |
const NameType & | Name () const |
TCursor | NextSibling () const |
operator TCursor<!TConst > () | |
bool | operator!= (const TCursor &other) const |
std::pair< TCursor, SubstringType > | operator() (const NameType &path) const |
T & | operator* () |
const T & | operator* () const |
T * | operator-> () |
const T * | operator-> () const |
TCursor & | operator= (const TCursor &) noexcept=default |
TCursor & | operator= (TCursor &&) noexcept=default |
bool | operator== (const TCursor &other) const |
TCursor | Parent () const |
TCursor | PreviousSibling () const |
TCursor | Root () const |
template<typename TParent = StringTree> | |
const TParent & | Tree () |
T & | Value () |
const T & | Value () const |
Private Type Index: | |
using | Cursor = Configuration::Cursor |
Additional Inherited Members | |
Protected Type Index: inherited from StringTree< TAllocator, T, TNodeHandler, TRecycling >::TCursor< TConst > | |
using | cmCursor = ATMP_IF_T_F(!TConst, baseCursor, baseConstCursor) |
using | cmNode = ATMP_IF_T_F(!TConst, baseNode, const baseNode) |
using | cmTree = ATMP_IF_T_F(!TConst, basetree, const basetree) |
using | TStringTree = ATMP_IF_T_F(!TConst, StringTree, const StringTree) |
|
friend |
Definition at line 700 of file configuration.hpp.
|
private |
The base cursor type of the internal StringTree. This type is used to perform cursor operations on Configuration instances.
Definition at line 704 of file configuration.hpp.
|
default |
Default constructor.
Constructs an instance of this type from its base type. This constructor is for advanced use when direct operations with class StringTree and its cursor and iterator types are performed.
Note that the variable has to be declared already, when this constructor is used.
cursor | The StringTree cursor. |
Definition at line 750 of file configuration.hpp.
|
inline |
Constructs an instance of this type from its base type. This constructor is for advanced use when direct operations with class StringTree and its cursor and iterator types are performed.
Note that the previous variable declaratin will be destroyed, in case a variable had been declared at this cursor already.
cursor | The StringTree cursor. |
typeName | The type name. |
defaultValue | A default value, if available. Defaults to nulled string. |
Definition at line 761 of file configuration.hpp.
|
inlineexplicit |
Constructs an undeclared variable "cursor" associated with the given configuration object.
cfg | The configuration to use. |
Definition at line 769 of file configuration.hpp.
|
inlineexplicit |
Same as Variable(Configuration&), but takes the configuration from an ALib Camp.
camp | An ALib Camp singleton wich supplies the Configuration instance. |
Definition at line 774 of file configuration.hpp.
|
inline |
Constructs and declares this variable, without using or allocating a declaration struct.
cfg | The configuration to use. |
name | The name of the variable. |
typeName | The type of the variable. |
defaultValue | An optional default value. Defaults to nulled string. |
Definition at line 783 of file configuration.hpp.
|
inline |
Constructs and declares this variable, without using or allocating a declaration struct.
camp | An ALib Camp An ALib Camp singleton which supplies the Configuration instance. |
name | The name of the variable. |
typeName | The type of the variable. |
defaultValue | An optional default value. Defaults to nulled string. |
Definition at line 795 of file configuration.hpp.
|
inline |
Constructs and declares this variable, without using or allocating a declaration struct. This overload omits a parameter that specifies a configuration and uses the configuration object of the ALib Camp singleton alib::BASECAMP.
name | The name of the variable. |
typeName | The type of the variable. |
defaultValue | An optional default value. Defaults to nulled string. |
Definition at line 807 of file configuration.hpp.
|
inline |
Constructs and declares this variable.
cfg | The configuration to use. |
decl | The declaration to use. |
Definition at line 814 of file configuration.hpp.
|
inline |
Constructs and declares this variable.
camp | An ALib Camp singleton which supplies the Configuration instance. |
decl | The declaration to use. |
Definition at line 820 of file configuration.hpp.
|
inline |
Constructs and declares this variable.
TEnum | The type of parameter Enum |
cfg | The configuration to use. |
Enum | Element of an enum type that represents resourced configuration variables. |
Definition at line 829 of file configuration.hpp.
|
inline |
Constructs and declares this variable.
TEnum | The type of parameter Enum |
camp | An ALib Camp singleton wich supplies the Configuration instance. |
Enum | Element of an enum type that represents resourced configuration variables. |
Definition at line 838 of file configuration.hpp.
|
inline |
Constructs and declares this variable.
TEnum | The type of parameter Enum |
cfg | The configuration to use. |
Enum | Element of an enum type that represents resourced configuration variables. |
replacements | Replacement values. |
|
inline |
Constructs and declares this variable.
TEnum | The type of parameter Enum |
camp | An ALib Camp singleton wich supplies the Configuration instance. |
Enum | Element of an enum type that represents resourced configuration variables. |
replacements | Replacement values. |
|
inline |
This is an explicit cast operator
to the protected base class.
Cursor
. Definition at line 890 of file configuration.hpp.
|
inline |
const
version of the cast operator
to the protected base class.
Definition at line 895 of file configuration.hpp.
Called by declaration methods. Creates necessary internal data structs, searches configuration plug-ins for data, and, in case not found, optionally applies the given defaultValue
typeName | The type name. |
defaultValue | A default value, if available. |
Definition at line 110 of file variable.cpp.
Variable & Declare | ( | const Declaration * | declaration | ) |
Moves this variable cursor (aka StringTree::Cursor) to represent the variable of the given declaration. If the variable does not exist, yet it is created. If the variable exists, the given decl is ignored. In debug compilations, an assertion is raised in case the variable existed but has a different declaration attached.
If the variable is created and the declaration contains a default value, such value is imported from the string. In this case, DefaultValues is returned.
declaration | The declaration singleton. |
*this
to allow concatenated operations. Definition at line 233 of file variable.cpp.
Variable & Declare | ( | const String & | name, |
const String & | typeName, | ||
const String & | defaultValue = NULL_STRING ) |
Declares this variable, without using or allocating a declaration struct.
name | The name of the variable. |
typeName | The type of the variable. |
defaultValue | An optional default value. Defaults to nulled string. |
*this
to allow concatenated operations. Definition at line 193 of file variable.cpp.
|
inline |
Declares this variable.
TEnum | The type of parameter Enum |
Enum | Element of an enum type that represents resourced configuration variables. |
Definition at line 932 of file configuration.hpp.
Declares this variable.
TEnum | The type of parameter Enum |
Enum | Element of an enum type that represents resourced configuration variables. |
replacements | Replacement values. |
|
nodiscard |
Increases the reported priority of this variable to the value given. If the current value is higher than the given one, it is not increased and false
is returned. In this case, a program should not write the variable's value.
[[nodiscard]]
.(void)
before the call.requestedPriority | The new, higher priority to set. |
true
, if the current priority was lower or equal to the given one, false
otherwise. Definition at line 272 of file variable.cpp.
void Delete | ( | ) |
Deletes a variable. After this method is executed, the internal cursor will be invalid and further operations on this variable instance can only be made after a next declaration.
Definition at line 285 of file variable.cpp.
|
inline |
Exports the contents of this variable to the given buffer. This is done by calling VMeta::exPort on the virtual meta object associated with this variable's type.
dest | The destination string. Must not be reset prior writing, but appended. |
escaper | The StringEscaper to use for exporting a C++ string to a (probably) escaped string format. Defaults to nullptr which indicates that no conversion (aka 'escaping') has to be performed. Usually, if a ConfigurationPlugin invokes this method to write-back the contents of a variable, it would pass its own suitable implementation here. |
Definition at line 1172 of file configuration.hpp.
|
inline |
Returns a reference to the variable's value. To receive a value the variable has to be defined, which is either done, by
If this is not done, in debug-compilations an assertion is raised. In release-builds, it is defined (!) behavior: A default constructed value of T is returned. Hence, the whole concept of defining a variable and methods IsDefined, etc. is rather a contract than a necessity. This is explained in section 4. Variable Definition of the Programmer's Manual of this ALib Camp.
Template parameter T has to be specified in alignment with the declaration of the variable. It is the users responsibility to specify the right type, as internally a reinterpret_cast
has to be performed. In other words, providing a wrong type is undefined behavior.
In debug-compilations, an assertion is raised if the type does not match the declaration.
T | The type to receive. |
Definition at line 1205 of file configuration.hpp.
|
inline |
const
-version of overloaded method.
T | The type to receive. |
Definition at line 1225 of file configuration.hpp.
|
inline |
Definition at line 1248 of file configuration.hpp.
|
inline |
Definition at line 1252 of file configuration.hpp.
|
inline |
Returns a reference
to the configuration this variable resides in.
Definition at line 1095 of file configuration.hpp.
|
inline |
Returns the declaration struct of this variable, in case it was constructed or declared with an overloaded constructor or method Declare, which accepts such struct. Otherwise, a nullptr is returned.
nullptr
, if no declaration struct was given. Otherwise, the singleton declaration object provided. Definition at line 1091 of file configuration.hpp.
|
inline |
Definition at line 1251 of file configuration.hpp.
|
inline |
float
. Definition at line 1250 of file configuration.hpp.
|
inline |
Definition at line 1249 of file configuration.hpp.
|
inlineprotected |
Returns the meta-information object.
Definition at line 726 of file configuration.hpp.
|
inline |
Convenience method. If IsDefined returns true
, the value of this variable is returned. Otherwise the variable gets defined with the given priority and value is imported.
value | The value to import in case the variable is not defined. |
priority | The priority to set on import in case the variable is not defined. Defaults to DefaultValues. |
false
if data of any priority is available in this variable, true
if not. Definition at line 1289 of file configuration.hpp.
|
inline |
Convenience method. If IsDefined returns true
, the value of this variable is returned. Otherwise the variable gets defined with the given priority and value is imported.
value | The value to import in case the variable is not defined. |
priority | The priority to set on import in case the variable is not defined. Defaults to DefaultValues. |
false
if data of any priority is available in this variable, true
if not. Definition at line 1273 of file configuration.hpp.
Convenience method. If IsDefined returns true
, the value of this variable is returned. Otherwise the variable gets defined with the given priority and value is imported.
value | The value to import in case the variable is not defined. |
priority | The priority to set on import in case the variable is not defined. Defaults to DefaultValues. |
false
if data of any priority is available in this variable, true
if not. Definition at line 1305 of file configuration.hpp.
|
inline |
The priority of a variable indicates "who" or "what" defined the variable and provided the current value. It may be defaulted values, values coming from external configuration files, from command line arguments, environment variables or from common code entities ('hard-coded' values). Besides the elements in enumeration Priority, also any value in between may be given. Doing so, allows fine-tuning which entity exacly is allowed to write values. For example, if a variable's priority is set in code to Environment, then environment variables and CLI arguments may still overwrite a value. If set to Environment + 1, then environment variables would not overwrite, but still CLI arguments could.
A priority of Protected disallows any code entity to make further changes, but those that again use this priority.
Definition at line 1112 of file configuration.hpp.
|
inline |
Definition at line 1253 of file configuration.hpp.
|
inline |
idx | The index of the requested string. |
Definition at line 1255 of file configuration.hpp.
|
inline |
Definition at line 1254 of file configuration.hpp.
void Import | ( | const String & | src, |
Priority | priority, | ||
const StringEscaper * | escaper = nullptr ) |
Imports a variable value from a serialized string representation. Internally, this is performed by calling VMeta::imPort on the virtual meta object associated with this variable's type.
src | The source string. |
priority | The priority of the import. If the variable is already defined in a higher priority, nothing is done. |
escaper | The StringEscaper to use for importing an escaped string. Defaults to nullptr which indicates that a programmatically defined C++ string is to be parsed. Usually, if a ConfigurationPlugin invokes this method it would pass its own suitable implementation here. |
Definition at line 349 of file variable.cpp.
|
inline |
Returns true
if this variable is declared. If false
is returned, this the is just a path node inside the StringTree of the Configuration.
false
will be returned only if:
true
if the underlying StringTree::Cursor of the Configuration that this variable is associated with, points to a declared variable. Otherwise false
is returned. Definition at line 979 of file configuration.hpp.
|
inline |
This is a shortcut to Priority() != Priority::NONE
and thus, this method checks whether any data is defined.
Variables which are declared using a alib::config,Declaration "config,Declaration" that contains a default value, will have this default value parsed and contain a data set of priority DefaultValues.
true
if data of any priority is available in this variable, false
if not. Definition at line 1122 of file configuration.hpp.
|
inline |
This is a shortcut to Priority() > Priority::Standard
and thus, this method checks whether an explicit definition with a priority higher than Standard was performed, which - by contract - is done only when external data sources are read, for example configuration files, environment variables, or command line parameters.
true
if data contained has a higher priority than Standard, false
if not. Definition at line 1142 of file configuration.hpp.
|
inline |
This is the negation of method IsDefined.
false
if data of any priority is available in this variable, true
if not. Definition at line 1132 of file configuration.hpp.
Assembles the variable's name from its path within the internal StringTree.
target | The string buffer to append this variable's name to. |
Definition at line 1043 of file configuration.hpp.
|
inline |
Definition at line 1241 of file configuration.hpp.
|
inline |
Definition at line 1245 of file configuration.hpp.
|
inline |
Definition at line 1246 of file configuration.hpp.
|
inline |
Definition at line 1244 of file configuration.hpp.
|
inline |
float
. Definition at line 1243 of file configuration.hpp.
|
inline |
Definition at line 1242 of file configuration.hpp.
|
inline |
Calls Get<Bool>() and assigns val.
val | The value to assign. |
Definition at line 1258 of file configuration.hpp.
Calls Get<AStringPA>() and resets the string to val.
val | The value to assign. |
Definition at line 1262 of file configuration.hpp.
|
inline |
Calls Get<double>() and assigns val.
val | The value to assign. |
Definition at line 1261 of file configuration.hpp.
|
inline |
Calls Get<double>() and assigns val.
val | The value to assign. |
Definition at line 1260 of file configuration.hpp.
Calls Get<integer>() and assigns val.
val | The value to assign. |
Definition at line 1259 of file configuration.hpp.
|
inline |
Definition at line 1256 of file configuration.hpp.
|
protected |
Performs variable substitution. This method is called before any call to VMeta::imPort.
importString | The import string. |
buf | The substitution buffer. |
escaper | The escaper used to externalize substitution values. |
Definition at line 18 of file variable.cpp.
bool Try | ( | const Declaration * | decl | ) |
Tries to move the underlying StringTree::Cursor of the Configuration that this variable is associated with, to the variable name found with given declaration. If this succeeds, it is checked if the variable has no declaration record set, and if not, the one given is stored with the variable.
decl | The declaration of the variable to use. |
true
if the variable name specified with the given declaration existed and was declared, or if a preset value existed. Otherwise false
is returned and the variable's value is not allowed to be accessed. Definition at line 330 of file variable.cpp.
|
inline |
Tries to move the underlying StringTree::Cursor of the Configuration that this variable is associated with, to the given path (aka variable name). If this succeeds, the result of IsDeclared() is returned. Otherwise false
.
Note that this method still returns false
if a preset value exists for the variable, because preset values can only be imported if a variable's type is known, hence when a variable is declared. But this method explicitly avoids declarations.
name | The name of the variable to try. |
true
if the variable name specified with the given declaration existed and was declared. Otherwise false
is returned and the variable's value is not allowed to be accessed. Definition at line 996 of file configuration.hpp.
Tries to move the underlying StringTree::Cursor of the Configuration that this variable is associated with, to the given path (aka variable name).
name | The name of the variable. |
typeName | The type of the variable. |
true
if the variable name specified with the given declaration existed and was declared. Otherwise false
is returned and the variable's value is not allowed to be accessed. Definition at line 295 of file variable.cpp.