ALib C++ Framework
by
Library Version: 2511 R0
Documentation generated by doxygen
Loading...
Searching...
No Matches
alib::variables::Variable Class Reference

Description:

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

Definition at line 733 of file configuration.inl.

Inheritance diagram for alib::variables::Variable:

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)
CursorAsCursor ()
const CursorAsCursor () const
VariableDeclare (const Declaration *declaration)
VariableDeclare (const String &name, const String &typeName, const String &defaultValue=NULL_STRING)
template<typename TEnum>
VariableDeclare (TEnum Enum)
template<typename TEnum>
VariableDeclare (TEnum Enum, const Box &replacements)
bool Define (Priority requestedPriority=Priority::Standard)
void Delete ()
AStringExport (AString &dest, const StringEscaper *escaper=nullptr) const
template<typename T>
T & Get ()
template<typename T>
const T & Get () const
bool GetBool ()
BoxGetBox ()
Configuration & GetConfiguration () const
const DeclarationGetDeclaration () const
double GetDouble ()
float GetFloat ()
integer GetInt ()
bool GetOrSetDefault (bool value, Priority priority=Priority::DefaultValues)
StringGetOrSetDefault (const String &value, Priority priority=Priority::DefaultValues)
bool GetOrSetDefault (integer value, Priority priority=Priority::DefaultValues)
Priority GetPriority () const
AStringPAGetString ()
StringGetString (int idx)
StringVectorPAGetStrings ()
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
AStringName (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 Stringoperator= (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)

Protected Method Index:

void create (const String &typeName, const String &defaultValue)
VMetagetMeta () const
const Stringsubstitute (const String &importString, AString &buf, const StringEscaper *escaper)

Private Type Index:

using Cursor = Configuration::Cursor

◆ alib::variables::Configuration

friend class alib::variables::Configuration
friend

Definition at line 735 of file configuration.inl.

Type Definition Details:

◆ Cursor

using alib::variables::Variable::Cursor = Configuration::Cursor
private

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.

Constructor(s) / Destructor Details:

◆ 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
cursorThe StringTree cursor.

Definition at line 785 of file configuration.inl.

◆ Variable() [3/8]

alib::variables::Variable::Variable ( const Cursor & cursor,
const String & typeName,
const String & defaultValue = NULL_STRING )
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.

Parameters
cursorThe StringTree cursor.
typeNameThe type name.
defaultValueA 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
cfgThe 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
cfgThe configuration to use.
nameThe name of the variable.
typeNameThe type of the variable.
defaultValueAn 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
cfgThe configuration to use.
declThe 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
TEnumThe type of parameter Enum
Parameters
cfgThe configuration to use.
EnumElement 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
TEnumThe type of parameter Enum
Parameters
cfgThe configuration to use.
EnumElement of an enum type that represents resourced configuration variables.
replacementsReplacement values.

Definition at line 852 of file configuration.inl.

Method Details:

◆ 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
typeNameThe type name.
defaultValueA default value, if available.

Definition at line 110 of file variable.cpp.

◆ Declare() [1/4]

Variable & alib::variables::Variable::Declare ( const Declaration * declaration)

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
declarationThe declaration singleton.
Returns
*this to allow concatenated operations.

Definition at line 224 of file variable.cpp.

◆ Declare() [2/4]

Variable & alib::variables::Variable::Declare ( const String & name,
const String & typeName,
const String & defaultValue = NULL_STRING )

Declares this variable, without using or allocating a declaration struct.

Parameters
nameThe name of the variable.
typeNameThe type of the variable.
defaultValueAn 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
TEnumThe type of parameter Enum
Parameters
EnumElement 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
TEnumThe type of parameter Enum
Parameters
EnumElement of an enum type that represents resourced configuration variables.
replacementsReplacement 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
requestedPriorityThe 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()

AString & alib::variables::Variable::Export ( AString & dest,
const StringEscaper * escaper = nullptr ) const
inline

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
destThe destination string. Must not be reset prior writing, but appended.
escaperThe 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
TThe type to receive.
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
TThe type to receive.
Returns
A reference to the value of the variable.

Definition at line 1202 of file configuration.inl.

◆ GetBool()

bool alib::variables::Variable::GetBool ( )
inline
Returns
Calls and returns Get\().

Definition at line 1224 of file configuration.inl.

◆ GetBox()

Box & alib::variables::Variable::GetBox ( )
inline
Returns
Calls and returns Get\().

Definition at line 1228 of file configuration.inl.

◆ 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
Returns
Calls and returns Get\().

Definition at line 1227 of file configuration.inl.

◆ GetFloat()

float alib::variables::Variable::GetFloat ( )
inline
Returns
Calls and returns Get\() cast to float.

Definition at line 1226 of file configuration.inl.

◆ GetInt()

integer alib::variables::Variable::GetInt ( )
inline
Returns
Calls and returns Get\().

Definition at line 1225 of file configuration.inl.

◆ 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
valueThe value to import in case the variable is not defined.
priorityThe 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
valueThe value to import in case the variable is not defined.
priorityThe 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
valueThe value to import in case the variable is not defined.
priorityThe 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
Returns
Calls and returns Get\().

Definition at line 1229 of file configuration.inl.

◆ GetString() [2/2]

String & alib::variables::Variable::GetString ( int idx)
inline
Parameters
idxThe index of the requested string.
Returns
Calls and returns Get\().Lines.at(idx).

Definition at line 1231 of file configuration.inl.

◆ GetStrings()

StringVectorPA & alib::variables::Variable::GetStrings ( )
inline
Returns
Calls and returns Get\().

Definition at line 1230 of file configuration.inl.

◆ Import()

void alib::variables::Variable::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 virtual void imPort(detail::VDATA*, Configuration&, const StringEscaper&, const String&) =0 on the virtual meta object associated with this variable's type.

Parameters
srcThe source string.
priorityThe priority of the import. If the variable is already defined in a higher priority, nothing is done.
escaperThe 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()

AString & alib::variables::Variable::Name ( AString & target) const
inline

Assembles the variable's name from its path within the internal StringTree.

Parameters
targetThe 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
Returns
Calls and returns Get\().

Definition at line 1217 of file configuration.inl.

◆ operator const String &()

alib::variables::Variable::operator const String & ( )
inline
Returns
Calls and returns Get\().

Definition at line 1221 of file configuration.inl.

◆ operator const Substring()

alib::variables::Variable::operator const Substring ( )
inline
Returns
Calls and returns Get\().

Definition at line 1222 of file configuration.inl.

◆ operator double()

alib::variables::Variable::operator double ( )
inline
Returns
Calls and returns Get\().

Definition at line 1220 of file configuration.inl.

◆ operator float()

alib::variables::Variable::operator float ( )
inline
Returns
Calls and returns Get\() cast to float.

Definition at line 1219 of file configuration.inl.

◆ operator integer()

alib::variables::Variable::operator integer ( )
inline
Returns
Calls and returns Get\().

Definition at line 1218 of file configuration.inl.

◆ operator=() [1/5]

bool alib::variables::Variable::operator= ( bool val)
inline

Calls Get\() and assigns val.

Parameters
valThe value to assign.
Returns
The val given.

Definition at line 1234 of file configuration.inl.

◆ operator=() [2/5]

const String & alib::variables::Variable::operator= ( const String & val)
inline

Calls Get\() and resets the string to val.

Parameters
valThe value to assign.
Returns
The val given.

Definition at line 1238 of file configuration.inl.

◆ operator=() [3/5]

double alib::variables::Variable::operator= ( double val)
inline

Calls Get\() and assigns val.

Parameters
valThe value to assign.
Returns
The val given.

Definition at line 1237 of file configuration.inl.

◆ operator=() [4/5]

float alib::variables::Variable::operator= ( float val)
inline

Calls Get\() and assigns val.

Parameters
valThe value to assign.
Returns
The val given.

Definition at line 1236 of file configuration.inl.

◆ operator=() [5/5]

integer alib::variables::Variable::operator= ( integer val)
inline

Calls Get\() and assigns val.

Parameters
valThe value to assign.
Returns
The val given.

Definition at line 1235 of file configuration.inl.

◆ Size()

int alib::variables::Variable::Size ( )
inline
Returns
Calls and returns Get\().Lines.size().

Definition at line 1232 of file configuration.inl.

◆ substitute()

const String & alib::variables::Variable::substitute ( const String & importString,
AString & buf,
const StringEscaper * escaper )
protected

Performs variable substitution. This method is called before any call to virtual void imPort(detail::VDATA*, Configuration&, const StringEscaper&, const String&) =0.

Parameters
importStringThe import string.
bufThe substitution buffer.
escaperThe escaper used to externalize substitution values.
Returns
Either the original import string, or a reference to the given buffer containing the substituted copy.

Definition at line 26 of file variable.cpp.

◆ 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
declThe 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
nameThe 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
nameThe name of the variable.
typeNameThe 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: