Orxonox  0.0.5 Codename: Arcturus
Namespaces | Macros | Functions
ConfigValueIncludes.h File Reference

Definition of macros and functions for config-values. More...

#include "core/CorePrereqs.h"
#include "core/class/Identifier.h"
#include "ConfigValueContainer.h"

Go to the source code of this file.

Namespaces

 orxonox
 Die Wagnis Klasse hat die folgenden Aufgaben:
 

Macros

#define ModifyConfigValue(varname, modifier, ...)   ModifyConfigValueGeneric(this, &varname, #varname, modifier, __VA_ARGS__)
 Modifies a runtime configurable value by using a modifier and some arguments. More...
 
#define ModifyConfigValueExternal(variable, entryName, modifier, ...)   ModifyConfigValueGeneric(this, &variable, entryName, modifier, __VA_ARGS__)
 Modifies a runtime configurable value by using a modifier and some arguments. More...
 
#define ModifyConfigValueGeneric(object, variable, entryName, modifier, ...)
 Modifies a runtime configurable value by using a modifier and some arguments. More...
 
#define ResetConfigValue(varname)   orxonox::resetConfigValueGeneric(this, &varname, #varname)
 Resets a runtime configurable value to its default (simplified macro version of modifyConfigValueGeneric) If the container for the value doesn't yet exist, a warning is displayed. More...
 
#define SetConfigValue(varname, defaultValue)   orxonox::setConfigValueGeneric(this, &varname, ConfigFileType::Settings, this->getIdentifier()->getName(), #varname, defaultValue)
 Sets a runtime configurable value (simplified macro version of setConfigValueGeneric) If the container for the value doesn't yet exist, a new one is created. More...
 
#define SetConfigValueAlias(variable, entryName, defaultValue)   orxonox::setConfigValueGeneric(this, &variable, ConfigFileType::Settings, this->getIdentifier()->getName(), entryName, defaultValue)
 Sets a runtime configurable value (simplified macro version of setConfigValueGeneric) If the container for the value doesn't yet exist, a new one is created. More...
 
#define SetConfigValueExternal(variable, sectionName, entryName, defaultValue)   orxonox::setConfigValueGeneric(this, &variable, ConfigFileType::Settings, sectionName, entryName, defaultValue)
 Sets a runtime configurable value (simplified macro version of setConfigValueGeneric) If the container for the value doesn't yet exist, a new one is created. More...
 

Functions

template<class T , class V >
void orxonox::resetConfigValueGeneric (T *object, V *variable, const std::string &entryName)
 Resets a runtime configurable value to its default. More...
 
template<class T , class D , class V >
ConfigValueContainer & orxonox::setConfigValueGeneric (T *object, V *variable, ConfigFileType::Value type, const std::string &sectionName, const std::string &entryName, const D &defaultValue)
 Sets a runtime configurable value. More...
 

Detailed Description

Definition of macros and functions for config-values.

An example of how to use SetConfigValue():

Definition of a class in the header-file:

class MyClass : public BaseObject
{
public:
MyClass(); // Constructor
void setConfigValues(); // Inherited function
const std::string& getName()
{ return this->name_; }
float getVersion()
{ return this->version_; }
private:
float version_;
};

Implementation of the class source-file:

MyClass::MyClass()
{
// Macro-call to create an Identifier
RegisterObject(MyClass);
// Function-call to assign the config-values to the new object
this->setConfigValues();
}
void MyClass::setConfigValues()
{
SetConfigValue(name_, "Orxonox").description("The name of the game");
SetConfigValue(version_, "1.0").description("The version-number");
}

Extract of orxonox.ini:

[MyClass]
name_ = "Orxonox"
version_ = 1.1 // We have changed this value from 1.0 to 1.1

Some other code:

MyObject orxonoxobject;
orxout() << "Name: " << orxonoxobject.getName() << endl;
orxout() << "Version: " << orxonoxobject.getVersion() << endl;

Output:

Name: Orxonox
Version: 1.1

Macro Definition Documentation

#define ModifyConfigValue (   varname,
  modifier,
  ... 
)    ModifyConfigValueGeneric(this, &varname, #varname, modifier, __VA_ARGS__)

Modifies a runtime configurable value by using a modifier and some arguments.

If the container for the value doesn't yet exist, a warning is displayed. Also, the varname argument will be modified and set to the current value.

Parameters
varnameVariable name as C++ identifier. It will be used as entry name and as variable pointer
modifierOn of these functions: set, tset, add, remove, reset, update
...Arguments for the modifier function
#define ModifyConfigValueExternal (   variable,
  entryName,
  modifier,
  ... 
)    ModifyConfigValueGeneric(this, &variable, entryName, modifier, __VA_ARGS__)

Modifies a runtime configurable value by using a modifier and some arguments.

If the container for the value doesn't yet exist, a warning is displayed. Also, the variable argument will be modified and set to the current value.

Parameters
variablePointer to the variable where the value should be written to
entryNameName of the entry in the ini file (e.g. [MySection] myValue)
modifierOn of these functions: set, tset, add, remove, reset, update
...Arguments for the modifier function
#define ModifyConfigValueGeneric (   object,
  variable,
  entryName,
  modifier,
  ... 
)
Value:
if (orxonox::ConfigValueContainer* container = ClassByObjectType(object)->getConfigValueContainer(entryName)) \
{ \
container->modifier(__VA_ARGS__); \
container->getValue(variable, object); \
} \
else \
{ \
orxout(user_warning, context::config) << "Couldn't modify config-value '" << entryName << "' in class '" \
<< ClassByObjectType(object)->getName() << "', corresponding container doesn't exist." << endl; \
}
The ConfigValuecontainer contains all needed information about a configurable variable.
Definition: ConfigValueContainer.h:98
OutputStream & orxout(OutputLevel level=level::debug_output, const OutputContextContainer &context=context::undefined())
This helper function returns a reference to a commonly used instance of OutputStream.
Definition: Output.h:81
Identifier * ClassByObjectType(const T *p)
Returns the Identifier with a given &#39;this&#39; pointer.
Definition: CoreIncludes.h:208
const std::string & getName() const
Returns the name of the class the Identifier belongs to.
Definition: Identifier.h:127
Output level, used for warnings which are important for the user.
Definition: OutputDefinitions.h:92

Modifies a runtime configurable value by using a modifier and some arguments.

If the container for the value doesn't yet exist, a warning is displayed. Also, the variable argument will be modified and set to the current value.

Parameters
objectClass instance that the config value should belong to (usually just 'this')
variablePointer to the variable where the value should be written to
entryNameName of the entry in the ini file (e.g. [MySection] myValue)
modifierOn of these functions: set, tset, add, remove, reset, update
...Arguments for the modifier function
#define ResetConfigValue (   varname)    orxonox::resetConfigValueGeneric(this, &varname, #varname)

Resets a runtime configurable value to its default (simplified macro version of modifyConfigValueGeneric) If the container for the value doesn't yet exist, a warning is displayed.

Also, the varname argument will be modified and set to the default value.

Parameters
varnameVariable name as C++ identifier. It will be used as entry name and as variable pointer
#define SetConfigValue (   varname,
  defaultValue 
)    orxonox::setConfigValueGeneric(this, &varname, ConfigFileType::Settings, this->getIdentifier()->getName(), #varname, defaultValue)

Sets a runtime configurable value (simplified macro version of setConfigValueGeneric) If the container for the value doesn't yet exist, a new one is created.

Also, the varname argument will be modified and set to the new value (default or from ini file).

Parameters
varnameVariable name as C++ identifier. It will be used as entry name and as variable pointer
defaultValueValue to be used if it cannot be read from the ini file
#define SetConfigValueAlias (   variable,
  entryName,
  defaultValue 
)    orxonox::setConfigValueGeneric(this, &variable, ConfigFileType::Settings, this->getIdentifier()->getName(), entryName, defaultValue)

Sets a runtime configurable value (simplified macro version of setConfigValueGeneric) If the container for the value doesn't yet exist, a new one is created.

Also, the varname argument will be modified and set to the new value (default or from ini file).

Parameters
variableVariable name as C++ identifier.
entryNameName of the entry in the ini file (e.g. [MySection] myValue)
defaultValueValue to be used if it cannot be read from the ini file
#define SetConfigValueExternal (   variable,
  sectionName,
  entryName,
  defaultValue 
)    orxonox::setConfigValueGeneric(this, &variable, ConfigFileType::Settings, sectionName, entryName, defaultValue)

Sets a runtime configurable value (simplified macro version of setConfigValueGeneric) If the container for the value doesn't yet exist, a new one is created.

Also, the varname argument will be modified and set to the new value (default or from ini file).

Parameters
variableVariable name as C++ identifier.
sectionNameName of the section in the ini file (e.g. [MySection])
entryNameName of the entry in the ini file (e.g. [MySection] myValue)
defaultValueValue to be used if it cannot be read from the ini file