This is the central interface type into the module ALib Variables. 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 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.
- See also
- For a quick tutorial about using ALib variables, consult the tutorial-style Programmer's Manual of camp ALib Variables.
- For this class, a pretty printer for the GNU debugger is provided.
- Besides the constructors found with this class, with the inclusion of the module ALib Camp in the ALib Build, and the inclusion of the header file ALib.Camp.H, a set of overloaded namespace functions allow the construction of variables in the Configuration instance included in ALib Camps. Those are:
- CampVariable(camp::Camp&).
- CampVariable(camp::Camp&, TEnum),
- CampVariable(camp::Camp&, const Declaration*), and
- CampVariable(camp::Camp&, const String&, const String&, const String&),
- CampVariable(camp::Camp&, TEnum, const Box),
Definition at line 733 of file configuration.inl.
|
| | 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) |
| Cursor & | AsCursor () |
| const Cursor & | AsCursor () const |
| Variable & | Declare (const Declaration *declaration) |
| 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) |
| bool | Define (Priority requestedPriority=Priority::Standard) |
| 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 () |
| void | Import (const String &src, Priority priority, const StringEscaper *escaper=nullptr) |
| bool | IsDeclared () const |
| bool | IsDefined () const |
| bool | IsDefinedExternally () const |
| bool | IsNotDefined () const |
| bool | IsWriteBack () 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\() and assigns val.
|
| const String & | operator= (const String &val) |
| | Calls Get\() and resets the string to val.
|
| double | operator= (double val) |
| | Calls Get\() and assigns val.
|
| float | operator= (float val) |
| | Calls Get\() and assigns val.
|
| integer | operator= (integer val) |
| | Calls Get\() and assigns val.
|
| int | Size () |
| bool | Try (const Declaration *decl) |
| bool | Try (const String &name) |
| bool | Try (const String &name, const String &typeName) |
|
| using | Cursor = Configuration::Cursor |
◆ alib::variables::Configuration
◆ Cursor
The base cursor type of the internal StringTree. This type is used to perform cursor operations on Configuration instances.
Definition at line 739 of file configuration.inl.
◆ Variable() [1/8]
| alib::variables::Variable::Variable |
( |
| ) |
|
|
default |
Default constructor.
- Note
- A variable that was default-constructed cannot be used later, without assigning a configuration with declaration. If, for example, a field member of type variable cannot be constructed with the provision of a corresponding Configuration, one of the following options has to be taken:
- The variable value gets a newly constructed instance assigned at a later stage when the configuration is known, or
- the configuration is provided with one of the overloaded Declare methods that accept a configuration.
◆ Variable() [2/8]
| alib::variables::Variable::Variable |
( |
const Cursor & | cursor | ) |
|
|
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 variable has to be declared already, when this constructor is used.
- Parameters
-
| cursor | The StringTree cursor. |
Definition at line 785 of file configuration.inl.
◆ Variable() [3/8]
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.
- Parameters
-
| cursor | The StringTree cursor. |
| typeName | The type name. |
| defaultValue | A default value, if available. Defaults to nulled string. |
Definition at line 796 of file configuration.inl.
◆ Variable() [4/8]
| alib::variables::Variable::Variable |
( |
Configuration & | cfg | ) |
|
|
inlineexplicit |
Constructs an undeclared variable "cursor" associated with the given configuration object.
- Note
- The internal StringTree::Cursor equals the root cursor received with StringTree::Root after this construction.
- See also
- Overloaded namespace functions CampVariable which become accessible with the header file ALib.Camp.H.
- Parameters
-
| cfg | The configuration to use. |
Definition at line 805 of file configuration.inl.
◆ Variable() [5/8]
| alib::variables::Variable::Variable |
( |
Configuration & | cfg, |
|
|
const String & | name, |
|
|
const String & | typeName, |
|
|
const String & | defaultValue = NULL_STRING ) |
|
inline |
Constructs and declares this variable, without using or allocating a declaration struct.
- See also
- Overloaded namespace functions CampVariable which become accessible with the header file ALib.Camp.H.
- Parameters
-
| 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 815 of file configuration.inl.
◆ Variable() [6/8]
| alib::variables::Variable::Variable |
( |
Configuration & | cfg, |
|
|
const Declaration * | decl ) |
|
inline |
Constructs and declares this variable.
- See also
- Overloaded namespace functions CampVariable which become accessible with the header file ALib.Camp.H.
- Parameters
-
| cfg | The configuration to use. |
| decl | The declaration to use. |
Definition at line 826 of file configuration.inl.
◆ Variable() [7/8]
template<typename TEnum>
| alib::variables::Variable::Variable |
( |
Configuration & | cfg, |
|
|
TEnum | Enum ) |
|
inline |
Constructs and declares this variable.
- See also
- Overloaded namespace functions CampVariable which become accessible with the header file ALib.Camp.H.
- Template Parameters
-
| TEnum | The type of parameter Enum |
- Parameters
-
| cfg | The configuration to use. |
| Enum | Element of an enum type that represents resourced configuration variables. |
Definition at line 837 of file configuration.inl.
◆ Variable() [8/8]
template<typename TEnum>
| alib::variables::Variable::Variable |
( |
Configuration & | cfg, |
|
|
TEnum | Enum, |
|
|
const Box | replacements ) |
|
inline |
Constructs and declares this variable.
- Attention
- This constructor might allocate a new record in the mono allocator of cfg. To avoid memory drain, consult the documentation of the method const Declaration * StoreDeclaration(const Declaration*, const Box&) .
- See also
- Overloaded namespace functions CampVariable which become accessible with the header file ALib.Camp.H.
- Template Parameters
-
| TEnum | The type of parameter Enum |
- Parameters
-
| cfg | The configuration to use. |
| Enum | Element of an enum type that represents resourced configuration variables. |
| replacements | Replacement values. |
Definition at line 852 of file configuration.inl.
◆ AsCursor() [1/2]
| Cursor & alib::variables::Variable::AsCursor |
( |
| ) |
|
|
inline |
This is an explicit cast operator to the protected base class.
- Note
- C++, for good reasons, does not allow implicit cast operators to protected base classes, as this would undermine the protected nature of the inheritance. Now, we undermine this explicitly. Why is this still good software design? Well, class Variable restricts and changes the interface of class Cursor in a way that it seems to be a very different entity. And this is right in the vast majority of use cases. In the remaining cases such access to the cursor features is needed. For example, when implementing a custom ConfigurationPlugin.
By the same token, this class has explicit constructors that accept a Cursor.
- Returns
- This instance cast 'down' to its protected base class.
Definition at line 865 of file configuration.inl.
◆ AsCursor() [2/2]
| const Cursor & alib::variables::Variable::AsCursor |
( |
| ) |
const |
|
inline |
const version of the cast operator to the protected base class.
- See also
- For details, see the mutable version of this operator.
- Returns
- This instance cast 'down' to its protected base class.
Definition at line 870 of file configuration.inl.
◆ create()
| void alib::variables::Variable::create |
( |
const String & | typeName, |
|
|
const String & | defaultValue ) |
|
protected |
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
- Parameters
-
| typeName | The type name. |
| defaultValue | A default value, if available. |
Definition at line 110 of file variable.cpp.
◆ Declare() [1/4]
Moves this variable cursor (aka 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 error 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.
- Parameters
-
| declaration | The declaration singleton. |
- Returns
*this to allow concatenated operations.
Definition at line 224 of file variable.cpp.
◆ Declare() [2/4]
Declares this variable, without using or allocating a declaration struct.
- Parameters
-
| name | The name of the variable. |
| typeName | The type of the variable. |
| defaultValue | An optional default value. Defaults to nulled string. |
- Returns
*this to allow concatenated operations.
Definition at line 186 of file variable.cpp.
◆ Declare() [3/4]
template<typename TEnum>
| Variable & alib::variables::Variable::Declare |
( |
TEnum | Enum | ) |
|
|
inline |
Declares this variable.
- Template Parameters
-
| TEnum | The type of parameter Enum |
- Parameters
-
| Enum | Element of an enum type that represents resourced configuration variables. |
- Returns
*this to allow concatenated operations.
Definition at line 906 of file configuration.inl.
◆ Declare() [4/4]
template<typename TEnum>
| Variable & alib::variables::Variable::Declare |
( |
TEnum | Enum, |
|
|
const Box & | replacements ) |
|
inline |
Declares this variable.
- Attention
- This method might allocate a new record in the mono allocator of cfg. To avoid memory drain, consult the documentation of the method const Declaration * StoreDeclaration(const Declaration*, const Box&) .
- Template Parameters
-
| TEnum | The type of parameter Enum |
- Parameters
-
| Enum | Element of an enum type that represents resourced configuration variables. |
| replacements | Replacement values. |
- Returns
*this to allow concatenated operations.
Definition at line 922 of file configuration.inl.
◆ Define()
| bool alib::variables::Variable::Define |
( |
Priority | requestedPriority = Priority::Standard | ) |
|
|
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.
- Note
- A programmer can easily ignore the result of this method. However, the suggested usage is a contract to make the ALib variable system secure. For this reason, this method is attributed
[[nodiscard]].
-
If the return value is to be ignored for good reason (for example, if Protected is passed, add a simple
(void) before the call.
- See also
-
- Parameters
-
| requestedPriority | The new, higher priority to set. |
- Returns
true, if the current priority was lower or equal to the given one, false otherwise.
Definition at line 260 of file variable.cpp.
◆ Delete()
| void alib::variables::Variable::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 272 of file variable.cpp.
◆ Export()
Exports the contents of this variable to the given buffer. This is done by calling virtual void exPort(detail::VDATA*, Configuration&, const StringEscaper&, AString&) =0 on the virtual meta object associated with this variable's type.
- Parameters
-
| 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. |
- Returns
- dest to allow concatenated operations.
Definition at line 1149 of file configuration.inl.
◆ Get() [1/2]
template<typename T>
| T & alib::variables::Variable::Get |
( |
| ) |
|
|
inline |
Returns a reference to the variable's value. To receive a value the variable has to be defined, which is either done, by
- A provision of a default value with declaration,
- A configuration plug-in like CLIVariablesPlugin or EnvironmentVariablesPlugin,
- Some bootstrap or other code entities like reading external configuration data from 3rd party sources,
- or finally "hard coded" with method Define.
If this is not done, in debug-compilations an error 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 error is raised if the type does not match the declaration.
- Template Parameters
-
- Returns
- A reference to the value of the variable.
Definition at line 1183 of file configuration.inl.
◆ Get() [2/2]
template<typename T>
| const T & alib::variables::Variable::Get |
( |
| ) |
const |
|
inline |
const-version of overloaded method.
- Template Parameters
-
- Returns
- A reference to the value of the variable.
Definition at line 1202 of file configuration.inl.
◆ GetBool()
| bool alib::variables::Variable::GetBool |
( |
| ) |
|
|
inline |
◆ GetBox()
| Box & alib::variables::Variable::GetBox |
( |
| ) |
|
|
inline |
◆ GetConfiguration()
| Configuration & alib::variables::Variable::GetConfiguration |
( |
| ) |
const |
|
inline |
Returns a reference to the configuration this variable resides in.
- Returns
- The associated configuration instance.
Definition at line 1054 of file configuration.inl.
◆ GetDeclaration()
| const Declaration * alib::variables::Variable::GetDeclaration |
( |
| ) |
const |
|
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.
- Note
- If a variable is doubly declared by two or more code entities (which is the usual case), a first declaration given is stored and returned from now on. If a second, different declaration struct is passed for the same variable, an assertion is raised in debug compilation. Hence, once a declaration is given, it is always available for inspection.
- Returns
nullptr, if no declaration struct was given. Otherwise, the singleton declaration object provided.
Definition at line 1050 of file configuration.inl.
◆ GetDouble()
| double alib::variables::Variable::GetDouble |
( |
| ) |
|
|
inline |
◆ GetFloat()
| float alib::variables::Variable::GetFloat |
( |
| ) |
|
|
inline |
◆ GetInt()
| integer alib::variables::Variable::GetInt |
( |
| ) |
|
|
inline |
◆ getMeta()
| VMeta * alib::variables::Variable::getMeta |
( |
| ) |
const |
|
inlineprotected |
Returns the meta-information object.
- Returns
- The virtual meta handler.
Definition at line 761 of file configuration.inl.
◆ GetOrSetDefault() [1/3]
| bool alib::variables::Variable::GetOrSetDefault |
( |
bool | value, |
|
|
Priority | priority = Priority::DefaultValues ) |
|
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.
- Parameters
-
| 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. |
- Returns
false if data of any priority is available in this variable, true if not.
Definition at line 1262 of file configuration.inl.
◆ GetOrSetDefault() [2/3]
| String & alib::variables::Variable::GetOrSetDefault |
( |
const String & | value, |
|
|
Priority | priority = Priority::DefaultValues ) |
|
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.
- Parameters
-
| 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. |
- Returns
false if data of any priority is available in this variable, true if not.
Definition at line 1247 of file configuration.inl.
◆ GetOrSetDefault() [3/3]
| bool alib::variables::Variable::GetOrSetDefault |
( |
integer | value, |
|
|
Priority | priority = Priority::DefaultValues ) |
|
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.
- Parameters
-
| 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. |
- Returns
false if data of any priority is available in this variable, true if not.
Definition at line 1277 of file configuration.inl.
◆ GetPriority()
| Priority alib::variables::Variable::GetPriority |
( |
| ) |
const |
|
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.
- Returns
- The priority setting for this variable, given with the last successful call to Define.
Definition at line 1071 of file configuration.inl.
◆ GetString() [1/2]
| AStringPA & alib::variables::Variable::GetString |
( |
| ) |
|
|
inline |
◆ GetString() [2/2]
| String & alib::variables::Variable::GetString |
( |
int | idx | ) |
|
|
inline |
◆ GetStrings()
◆ Import()
Imports a variable value from a serialized string representation. Internally, this is performed by calling virtual void imPort(detail::VDATA*, Configuration&, const StringEscaper&, const String&) =0 on the virtual meta object associated with this variable's type.
- Parameters
-
| 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 330 of file variable.cpp.
◆ IsDeclared()
| bool alib::variables::Variable::IsDeclared |
( |
| ) |
const |
|
inline |
Returns true if this variable is declared. If false is returned, this is just a path node inside the StringTree of the Configuration.
false will be returned only if:
- An instance of a variable was created with the constructor that only accepts a Configuration instance (an undeclared variable).
- An instance of a variable was created with the constructor that accepts a cursor object of a Configuration, and this cursor does not point to a declared variable.
- Method Try was called on an instance of this type, and the given variable name did not represent a declared variable.
- Returns
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 942 of file configuration.inl.
◆ IsDefined()
| bool alib::variables::Variable::IsDefined |
( |
| ) |
const |
|
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 Declaration that contains a default value, will have this default value parsed and contain a data set of priority DefaultValues.
- Returns
true if data of any priority is available in this variable, false if not.
Definition at line 1081 of file configuration.inl.
◆ IsDefinedExternally()
| bool alib::variables::Variable::IsDefinedExternally |
( |
| ) |
const |
|
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.
- Returns
true if data contained has a higher priority than Standard, false if not.
Definition at line 1101 of file configuration.inl.
◆ IsNotDefined()
| bool alib::variables::Variable::IsNotDefined |
( |
| ) |
const |
|
inline |
This is the negation of method IsDefined.
- Returns
false if data of any priority is available in this variable, true if not.
Definition at line 1091 of file configuration.inl.
◆ IsWriteBack()
| bool alib::variables::Variable::IsWriteBack |
( |
| ) |
const |
|
inline |
Returns true if the variable is considered to be written back to configuration data sources.
The built-in variables types return false. The behavior can be changed with custom variable types by overriding the method isWriteBack for the custom type.
It is not further specified when and how variable values are written back. This is dependent on the use case and implementation of the data sources.
The built-in type IniFileFeeder acknowledges and supports this flag. Class App of the module ALib App supports writing INI-files with write-back entries by invoking this method on all exported variables.
A sample of a variable using this feature is found with the module ALox and method bool SetVerbosityExport(Lox*, bool, Priority) .
- Returns
true if this variable is considered to be written back to its configuration source.
Definition at line 1120 of file configuration.inl.
◆ Name()
Assembles the variable's name from its path within the internal StringTree.
- Parameters
-
| target | The string buffer to append this variable's name to. |
- Returns
- The given AString to allow concatenated operations.
Definition at line 1003 of file configuration.inl.
◆ operator bool()
| alib::variables::Variable::operator bool |
( |
| ) |
|
|
inline |
◆ operator const String &()
| alib::variables::Variable::operator const String & |
( |
| ) |
|
|
inline |
◆ operator const Substring()
| alib::variables::Variable::operator const Substring |
( |
| ) |
|
|
inline |
◆ operator double()
| alib::variables::Variable::operator double |
( |
| ) |
|
|
inline |
◆ operator float()
| alib::variables::Variable::operator float |
( |
| ) |
|
|
inline |
◆ operator integer()
| alib::variables::Variable::operator integer |
( |
| ) |
|
|
inline |
◆ operator=() [1/5]
| bool alib::variables::Variable::operator= |
( |
bool | val | ) |
|
|
inline |
◆ operator=() [2/5]
| const String & alib::variables::Variable::operator= |
( |
const String & | val | ) |
|
|
inline |
◆ operator=() [3/5]
| double alib::variables::Variable::operator= |
( |
double | val | ) |
|
|
inline |
◆ operator=() [4/5]
| float alib::variables::Variable::operator= |
( |
float | val | ) |
|
|
inline |
◆ operator=() [5/5]
◆ Size()
| int alib::variables::Variable::Size |
( |
| ) |
|
|
inline |
◆ substitute()
◆ Try() [1/3]
| bool alib::variables::Variable::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.
- Note
- This method automatically declares and defines variables, for which an preset value is set.
- Parameters
-
| decl | The declaration of the variable to use. |
- Returns
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 313 of file variable.cpp.
◆ Try() [2/3]
| bool alib::variables::Variable::Try |
( |
const String & | name | ) |
|
|
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.
- See also
- Overloaded versions, which declare and define a variable if a preset exists.
- Parameters
-
| name | The name of the variable to try. |
- Returns
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 959 of file configuration.inl.
◆ Try() [3/3]
| bool alib::variables::Variable::Try |
( |
const String & | name, |
|
|
const String & | typeName ) |
Tries to move the underlying StringTree::Cursor of the Configuration that this variable is associated with, to the given path (aka variable name).
- Note
- This method automatically declares and defines variables, for which an preset value is set.
- Parameters
-
| name | The name of the variable. |
| typeName | The type of the variable. |
- Returns
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 281 of file variable.cpp.
The documentation for this class was generated from the following files: