#include <src/core/ConfigValueContainer.h>
Public Member Functions | |
bool | add (const MultiType &input) |
Adds a new entry to the end of the vector. | |
template<class T> | |
ConfigValueContainer & | callback (T *object, void(T::*function)(void)) |
Adds a callback function, that gets called after getValue() if the newly assigned value differs from the old value of the variable. | |
template<class V> | |
ConfigValueContainer (ConfigFileType type, Identifier *identifier, const std::string §ionname, const std::string &varname, const std::vector< V > &defvalue) | |
Constructor: Converts the default-value to a string, checks the config-file for a changed value, sets the intern value variable. | |
template<class D, class V> | |
ConfigValueContainer (ConfigFileType type, Identifier *identifier, const std::string §ionname, const std::string &varname, const D &defvalue, const V &value) | |
Constructor: Converts the default-value to a string, checks the config-file for a changed value, sets the intern value variable. | |
ConfigValueContainer & | description (const std::string &description) |
Adds a description to the config-value. | |
const std::string & | getDescription () const |
Returns the description of the config-value. | |
const std::string & | getName () const |
Returns the name of this container. | |
const std::string & | getSectionName () const |
Retuns the name of the section this config value is in. | |
std::string | getTypename () const |
Returns the typename of the assigned config-value. | |
template<typename T, class C> | |
ConfigValueContainer & | getValue (std::vector< T > *value, C *object) |
Returns the configured vector. | |
template<typename T, class C> | |
ConfigValueContainer & | getValue (T *value, C *object) |
Returns the configured value. | |
unsigned int | getVectorSize () const |
Returns the vectors size (or zero if it's not a vector). | |
bool | isVector () const |
Returns true if this config-value is a vector. | |
bool | remove (unsigned int index) |
Removes an existing entry from the vector. | |
bool | reset () |
Sets the value of the variable back to the default value and resets the config-file entry. | |
bool | set (unsigned int index, const MultiType &input) |
Assigns a new value to the config-value of all objects and writes the change into the config-file. | |
bool | set (const MultiType &input) |
Assigns a new value to the config-value of all objects and writes the change into the config-file. | |
std::string | toString () const |
Converts the config-value to a string. | |
bool | tset (unsigned int index, const MultiType &input) |
Assigns a new value to the config-value of all objects, but doesn't change the config-file (t stands for temporary). | |
bool | tset (const MultiType &input) |
Assigns a new value to the config-value of all objects, but doesn't change the config-file (t stands for temporary). | |
void | update () |
Retrieves the configured value from the currently loaded config-file. | |
~ConfigValueContainer () | |
Destructor: Deletes the callback object if necessary. | |
Private Member Functions | |
bool | callFunctionWithIndex (bool(ConfigValueContainer::*function)(unsigned int, const MultiType &), const std::string &input) |
Calls the given function with parsed index and the parsed argument from the input string. | |
void | init (ConfigFileType type, Identifier *identifier, const std::string §ionname, const std::string &varname) |
Initializes the ConfigValueContainer with defaultvalues. | |
void | initValue (const MultiType &defvalue) |
Does some special initialization for single config-values. | |
void | initVector () |
Does some special initialization for vector config-values. | |
Private Attributes | |
bool | bAddedDescription_ |
True if a description was added. | |
bool | bContainerIsNew_ |
True if it's the first time getValue() gets called. | |
bool | bDoInitialCallback_ |
True if the callback should be called as soon as it gets created. | |
bool | bIsVector_ |
True if the container contains a std::vector. | |
ConfigValueCallbackBase * | callback_ |
A callback function to call after getValue if the value changed. | |
std::string | defvalueString_ |
The string of the default-value. | |
std::vector< std::string > | defvalueStringVector_ |
A vector, containg the strings of the default-values in case we're storing a vector. | |
LanguageEntryLabel | description_ |
The description. | |
Identifier * | identifier_ |
The identifier of the class. | |
std::string | sectionname_ |
The name of the class the variable belongs to. | |
ConfigFileType | type_ |
The type of the corresponding config-file. | |
MultiType | value_ |
The value. | |
std::vector< MultiType > | valueVector_ |
A vector, containg the values in case we're storing a vector. | |
std::string | varname_ |
The name of the variable. |
The ConfigValueContainer class contains all needed informations about a configurable variable:
This is needed to assign the configured values to all newly created objects.
The container searches for the entry in the config file. If there is an entry, it parses the specified value and assigns it to the variable of the right type. If there is no entry, it adds the entry with the default-value to the section of the variables class. If there is no section, the section and the entry are added to the end of the config-file.
orxonox::ConfigValueContainer::ConfigValueContainer | ( | ConfigFileType | type, | |
Identifier * | identifier, | |||
const std::string & | sectionname, | |||
const std::string & | varname, | |||
const D & | defvalue, | |||
const V & | value | |||
) | [inline] |
Constructor: Converts the default-value to a string, checks the config-file for a changed value, sets the intern value variable.
type | The type of the corresponding config-file | |
identifier | The identifier of the class the variable belongs to | |
sectionname | Name of the section the configValue should be put in. | |
varname | The name of the variable | |
defvalue | The default-value | |
value | Only needed do determine the right type. |
orxonox::ConfigValueContainer::ConfigValueContainer | ( | ConfigFileType | type, | |
Identifier * | identifier, | |||
const std::string & | sectionname, | |||
const std::string & | varname, | |||
const std::vector< V > & | defvalue | |||
) | [inline] |
Constructor: Converts the default-value to a string, checks the config-file for a changed value, sets the intern value variable.
type | The type of the corresponding config-file | |
identifier | The identifier of the class the variable belongs to | |
varname | The name of the variable | |
defvalue | The default-value |
References orxonox::KeyCode::V.
orxonox::ConfigValueContainer::~ConfigValueContainer | ( | ) |
bool orxonox::ConfigValueContainer::add | ( | const MultiType & | input | ) |
Adds a new entry to the end of the vector.
input | The new entry |
References bIsVector_, COUT, sectionname_, valueVector_, and varname_.
ConfigValueContainer& orxonox::ConfigValueContainer::callback | ( | T * | object, | |
void(T::*)(void) | function | |||
) | [inline] |
Adds a callback function, that gets called after getValue() if the newly assigned value differs from the old value of the variable.
object | The object to call the function | |
function | The callback function |
Referenced by orxonox::Button::readConfigValue().
bool orxonox::ConfigValueContainer::callFunctionWithIndex | ( | bool(ConfigValueContainer::*)(unsigned int, const MultiType &) | function, | |
const std::string & | input | |||
) | [private] |
Calls the given function with parsed index and the parsed argument from the input string.
function | The function to call | |
input | The input string |
References orxonox::convertValue(), COUT, orxonox::SubString::join(), orxonox::MAX_VECTOR_INDEX, sectionname_, orxonox::SubString::size(), orxonox::SubString::subSet(), varname_, and orxonox::SubString::WhiteSpaces.
ConfigValueContainer & orxonox::ConfigValueContainer::description | ( | const std::string & | description | ) |
Adds a description to the config-value.
description | The description |
References AddLanguageEntry, bAddedDescription_, description_, sectionname_, and varname_.
const std::string & orxonox::ConfigValueContainer::getDescription | ( | ) | const |
Returns the description of the config-value.
References description_, and GetLocalisation.
const std::string& orxonox::ConfigValueContainer::getName | ( | ) | const [inline] |
Returns the name of this container.
const std::string& orxonox::ConfigValueContainer::getSectionName | ( | ) | const [inline] |
Retuns the name of the section this config value is in.
std::string orxonox::ConfigValueContainer::getTypename | ( | ) | const [inline] |
Returns the typename of the assigned config-value.
ConfigValueContainer& orxonox::ConfigValueContainer::getValue | ( | std::vector< T > * | value, | |
C * | object | |||
) | [inline] |
Returns the configured vector.
value | A pointer to the vector to store the values. | |
object | The object calling this function |
ConfigValueContainer& orxonox::ConfigValueContainer::getValue | ( | T * | value, | |
C * | object | |||
) | [inline] |
Returns the configured value.
value | A pointer to the variable to store the value. | |
object | The object calling this function |
References orxonox::KeyCode::T.
Referenced by orxonox::Button::readConfigValue().
unsigned int orxonox::ConfigValueContainer::getVectorSize | ( | ) | const [inline] |
Returns the vectors size (or zero if it's not a vector).
void orxonox::ConfigValueContainer::init | ( | ConfigFileType | type, | |
Identifier * | identifier, | |||
const std::string & | sectionname, | |||
const std::string & | varname | |||
) | [private] |
Initializes the ConfigValueContainer with defaultvalues.
References bAddedDescription_, bContainerIsNew_, bDoInitialCallback_, callback_, identifier_, sectionname_, type_, and varname_.
void orxonox::ConfigValueContainer::initValue | ( | const MultiType & | defvalue | ) | [private] |
Does some special initialization for single config-values.
References bIsVector_, defvalueString_, orxonox::MultiType::getString(), update(), and value_.
void orxonox::ConfigValueContainer::initVector | ( | ) | [private] |
Does some special initialization for vector config-values.
References bIsVector_, defvalueStringVector_, orxonox::ConfigFileManager::getInstance(), orxonox::ConfigFileManager::getValue(), orxonox::MultiType::isType(), sectionname_, orxonox::MT_Type::String, type_, update(), value_, valueVector_, and varname_.
bool orxonox::ConfigValueContainer::isVector | ( | ) | const [inline] |
Returns true if this config-value is a vector.
bool orxonox::ConfigValueContainer::remove | ( | unsigned int | index | ) |
Removes an existing entry from the vector.
index | The index of the entry |
References bIsVector_, COUT, orxonox::ConfigFileManager::deleteVectorEntries(), orxonox::ConfigFileManager::getInstance(), orxonox::MultiType::isType(), sectionname_, orxonox::ConfigFileManager::setValue(), orxonox::MT_Type::String, type_, value_, valueVector_, and varname_.
bool orxonox::ConfigValueContainer::reset | ( | ) |
Sets the value of the variable back to the default value and resets the config-file entry.
References bIsVector_, defvalueString_, defvalueStringVector_, orxonox::ConfigFileManager::deleteVectorEntries(), orxonox::ConfigFileManager::getInstance(), sectionname_, type_, and varname_.
bool orxonox::ConfigValueContainer::set | ( | unsigned int | index, | |
const MultiType & | input | |||
) |
Assigns a new value to the config-value of all objects and writes the change into the config-file.
index | The index in the vector | |
input | The new value |
References bIsVector_, COUT, orxonox::ConfigFileManager::getInstance(), orxonox::MultiType::isType(), sectionname_, orxonox::ConfigFileManager::setValue(), orxonox::MT_Type::String, tset(), type_, value_, and varname_.
bool orxonox::ConfigValueContainer::set | ( | const MultiType & | input | ) |
Assigns a new value to the config-value of all objects and writes the change into the config-file.
input | The new value |
References bIsVector_, callFunctionWithIndex(), orxonox::ConfigFileManager::getInstance(), orxonox::MultiType::isType(), sectionname_, orxonox::ConfigFileManager::setValue(), orxonox::MT_Type::String, tset(), type_, value_, and varname_.
std::string orxonox::ConfigValueContainer::toString | ( | ) | const [inline] |
Converts the config-value to a string.
bool orxonox::ConfigValueContainer::tset | ( | unsigned int | index, | |
const MultiType & | input | |||
) |
Assigns a new value to the config-value of all objects, but doesn't change the config-file (t stands for temporary).
index | The index in the vector | |
input | The new value |
References bIsVector_, COUT, identifier_, orxonox::MAX_VECTOR_INDEX, sectionname_, orxonox::Identifier::updateConfigValues(), valueVector_, and varname_.
bool orxonox::ConfigValueContainer::tset | ( | const MultiType & | input | ) |
Assigns a new value to the config-value of all objects, but doesn't change the config-file (t stands for temporary).
input | The new value. If bIsVector_ then write "index value" |
References bIsVector_, callFunctionWithIndex(), identifier_, orxonox::Identifier::updateConfigValues(), and value_.
Referenced by set().
void orxonox::ConfigValueContainer::update | ( | ) |
Retrieves the configured value from the currently loaded config-file.
References bIsVector_, defvalueString_, defvalueStringVector_, orxonox::ConfigFileManager::getInstance(), orxonox::ConfigFileManager::getValue(), orxonox::ConfigFileManager::getVectorSize(), orxonox::MultiType::isType(), sectionname_, orxonox::MT_Type::String, type_, value_, valueVector_, and varname_.
Referenced by initValue(), and initVector().
bool orxonox::ConfigValueContainer::bAddedDescription_ [private] |
bool orxonox::ConfigValueContainer::bContainerIsNew_ [private] |
bool orxonox::ConfigValueContainer::bDoInitialCallback_ [private] |
bool orxonox::ConfigValueContainer::bIsVector_ [private] |
True if the container contains a std::vector.
Referenced by add(), initValue(), initVector(), remove(), reset(), set(), tset(), and update().
A callback function to call after getValue if the value changed.
Referenced by init(), and ~ConfigValueContainer().
std::vector<std::string> orxonox::ConfigValueContainer::defvalueStringVector_ [private] |
A vector, containg the strings of the default-values in case we're storing a vector.
Referenced by initVector(), reset(), and update().
The name of the class the variable belongs to.
Referenced by add(), callFunctionWithIndex(), description(), init(), initVector(), remove(), reset(), set(), tset(), and update().
std::vector<MultiType> orxonox::ConfigValueContainer::valueVector_ [private] |
A vector, containg the values in case we're storing a vector.
Referenced by add(), initVector(), remove(), tset(), and update().
The name of the variable.
Referenced by add(), callFunctionWithIndex(), description(), init(), initVector(), remove(), reset(), set(), tset(), and update().