The latter may be used by external configuration file to place human-readable comments next to each configuration entry.
With a Declaration instance in place, constructors Variable(Configuration& cfg, const Declaration* ), and Variable(lang::Camp& camp, const Declaration* ), as well as methods Declare(const Declaration*), and Try(const Declaration*) can be used.
Nevertheless, as seen below, a much nicer option exists.
All fields support placeholders "%1"
, "%2"
... "%N"
, which are replaced with optional constructors of class Variable, some of its methods Declare and with this classes' static method Get.-
This allows defining a series of variables whose name, description, default value and comments are dependent on run-time information. For example, the text logging types of camp ALox, have an own name. Now this name fills the placeholders within the variable declarations that each logger creates. This way, one resourced declaration is copied to be used by one or more loggers.
If a programmer provides self-generated variable names in combination with declarations, it has to be ensured that these variable names survive the lifecycle of the declaration.
ALIB_ENUMS_ASSIGN_RECORD( MyEnum, alib::config::Declaration )
(For more information, see ALib Enum Records.)
With these prerequisites in place, variables can be declared very conveniently by passing just a C++ enum element of custom enum type to one of the following methods:
Furthermore, a whole set of variables can be declared by passing just the enum type itself to method
This is usually done with bootstrap which makes all variables seamlessly available at least with a resourced default value, or overwritten by configuration files, CLI arguments or command lines. Usually the using code does not care and just accesses a variables value through the enumeration.
The resource data has to provide only three values in the following order:
0
.As already noted above, fields DefaultValue and Comments can be defined in two separate resource strings named like the variable's resource itself with concatenated postfixes _D, respectively _C and the variable's underlying enumeration element's integral value. Both resources are optional and not mandatory to be existent.
A sample of variable resources is given with the documentation of class PropertyFormatter.
This makes it very convenient to have all attributes of a variable, including their name managed independently from the program code and allows localizing variable names to other languages. Of course, this applies to such variables only which become externalized. Therefore, this library likewise allows declaring and use variables without providing an instance of this type.
Definition at line 148 of file declaration.hpp.
#include <declaration.hpp>
Public Static Method Index: | |
template<typename TEnum , typename TEnableIf = void> | |
static const Declaration * | Get (TEnum element) |
Public Method Index: | |
Declaration ()=default | |
Default constructor. | |
Declaration (const String &pName, const String &pTypeName, const String &pDefaultValue, const String &pComments) | |
const String & | Comments () const |
const String & | DefaultValue () const |
const String & | Name () const |
ALIB_API void | Parse () |
const String & | TypeName () const |
Public Method Index: inherited from ERSerializable | |
ERSerializable () noexcept=default | |
Defaulted constructor leaving the record undefined. | |
ERSerializable (const String &name, int minLength=0) noexcept | |
ALIB_API void | Parse () |
Protected Field Index: | |
String | comments |
String | defaultValue |
String | typeName |
Additional Inherited Members | |
Public Field Index: inherited from ERSerializable | |
String | EnumElementName |
The name of the enum element. | |
int | MinimumRecognitionLength |
|
friend |
Definition at line 150 of file declaration.hpp.
|
friend |
Definition at line 151 of file declaration.hpp.
|
protected |
The configuration variable's comments.
Definition at line 170 of file declaration.hpp.
|
protected |
The default value provided as an C++ string that may have to be parsed when imported into a variable definition. If set, the variable becomes automatically defined with Priority::DefaultValues when declared passing this instance.
Definition at line 164 of file declaration.hpp.
|
protected |
The type of the variable. Corresponds to what is defined with macros ALIB_CONFIG_VARIABLE_DEFINE_TYPE and ALIB_CONFIG_VARIABLE_REGISTER_TYPE.
Built-in types are listed with chapter 5.1 Built-In Variable Types of the Programmer's Manual.
Definition at line 158 of file declaration.hpp.
|
inline |
Constructor usually used with static variable declarations (declarations that are not using enumeration types associated with ALib Enum Records of this type).
If used however to define an enum record during bootstrap of a software (by user code that omits the preferred option of parsing resourced strings to create such records), then each parameter of type String passed, has to be of "static nature". This means, that string buffers and their contents are deemed to survive the life-cycle of an application. Usually, C++ string literals are passed in such situation.
pName | Value for field ERSerializable::EnumElementName. |
pTypeName | Value for field typeName. |
pDefaultValue | Value for field defaultValue. |
pComments | Value for field comments. |
Definition at line 192 of file declaration.hpp.
|
inline |
Returns this configuration variable's comments.
Definition at line 270 of file declaration.hpp.
|
inline |
The default value provided as a C++ string (not escaped). If provided, the variable becomes automatically defined with Priority::DefaultValues.
Definition at line 266 of file declaration.hpp.
|
static |
Static method that accepts an element of a C++ enum type equipped with ALib Enum Records of this type, that contains the declaration data.
In the case that a specialization of type T_Resourced exists for the enumeration type, DefaultValue and Comments are interpreted as a resource name given and are loaded with this method separatedly from the resource pool.
TEnum | The custom enum type that is associated with variable declarations. |
TEnableIf | Not to be specified. Used by the compiler to select this method only for associated custom C++ enum types. |
element | The desired variable (aka element of type TEnum. |
|
inline |
Returns this configuration variable's name.
Definition at line 259 of file declaration.hpp.
void Parse | ( | ) |
Implementation of EnumRecordPrototype::Parse.
0
. Definition at line 26 of file vmeta.cpp.
|
inline |
Returns this configuration variable's type.
Definition at line 255 of file declaration.hpp.