Orxonox: orxonox::ConfigValueContainer Class Reference

# orxonox::ConfigValueContainer Class Reference

The ConfigValuecontainer contains all needed informations about a configurable variable. More...

`#include <src/core/ConfigValueContainer.h>`

List of all members.

## 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 &sectionname, 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 &sectionname, 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 &sectionname, 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.

## Detailed Description

The ConfigValuecontainer contains all needed informations about a configurable variable.

The ConfigValueContainer class contains all needed informations about a configurable variable:

- the name of the variable
- the name of the class the variable belongs to
- the default value
- the user-specified value
- a pointer to the entry in the config-file

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.

## Constructor & Destructor Documentation

template<class D, class V>

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.

Parameters:

  | 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.

template<class V>

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.

Parameters:

  | 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 | ( |  | ) |

Destructor: Deletes the callback object if necessary.

References callback_.

## Member Function Documentation

bool orxonox::ConfigValueContainer::add | ( | const MultiType & | input | ) |

Adds a new entry to the end of the vector.

Parameters:

  | input | The new entry

Returns:
  True if the new entry was successfully added

References bIsVector_, COUT, sectionname_, valueVector_, and varname_.

template<class T>

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.

Parameters:

  | 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.

Parameters:

  | function | The function to call
  | input | The input string

Returns:
  The returnvalue of the functioncall

References orxonox::convertValue(), COUT, orxonox::SubString::join(), orxonox::MAX_VECTOR_INDEX, sectionname_, orxonox::SubString::size(), orxonox::SubString::subSet(), varname_, and orxonox::SubString::WhiteSpaces.

Referenced by set(), and tset().

ConfigValueContainer & orxonox::ConfigValueContainer::description | ( | const std::string & | description | ) |

Adds a description to the config-value.

Parameters:

  | description | The description

References AddLanguageEntry, bAddedDescription_, description_, sectionname_, and varname_.

const std::string & orxonox::ConfigValueContainer::getDescription | ( |  | ) | const

Returns the description of the config-value.

Returns:
  The description

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.

Returns:
  The typename

template<typename T, class C>

ConfigValueContainer& orxonox::ConfigValueContainer::getValue | ( | std::vector< T > * | value,
|  | C * | object |
| ) |  |  | `[inline]`

Returns the configured vector.

Parameters:

  | value | A pointer to the vector to store the values.
  | object | The object calling this function

Returns:
  The ConfigValueContainer

template<typename T, class C>

ConfigValueContainer& orxonox::ConfigValueContainer::getValue | ( | T * | value,
|  | C * | object |
| ) |  |  | `[inline]`

Returns the configured value.

Parameters:

  | value | A pointer to the variable to store the value.
  | object | The object calling this function

Returns:
  The ConfigValueContainer

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.

Parameters:

  | index | The index of the entry

Returns:
  True if the entry was removed

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.

Parameters:

  | index | The index in the vector
  | input | The new value

Returns:
  True if the new value was successfully assigned

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.

Parameters:

  | input | The new value

Returns:
  True if the new value was successfully assigned

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.

Returns:
  The 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).

Parameters:

  | index | The index in the vector
  | input | The new value

Returns:
  True if the new value was successfully assigned

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).

Parameters:

  | input | The new value. If bIsVector_ then write "index value"

Returns:
  True if the new value was successfully assigned

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().

## Member Data Documentation

bool orxonox::ConfigValueContainer::bAddedDescription_`[private]`

True if a description was added.

Referenced by description(), and init().

bool orxonox::ConfigValueContainer::bContainerIsNew_`[private]`

True if it's the first time getValue() gets called.

Referenced by init().

bool orxonox::ConfigValueContainer::bDoInitialCallback_`[private]`

True if the callback should be called as soon as it gets created.

Referenced by init().

bool orxonox::ConfigValueContainer::bIsVector_`[private]`

True if the container contains a std::vector.

Referenced by add(), initValue(), initVector(), remove(), reset(), set(), tset(), and update().

ConfigValueCallbackBase* orxonox::ConfigValueContainer::callback_`[private]`

A callback function to call after getValue if the value changed.

Referenced by init(), and ~ConfigValueContainer().

std::string orxonox::ConfigValueContainer::defvalueString_`[private]`

The string of the default-value.

Referenced by initValue(), reset(), and update().

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().

LanguageEntryLabel orxonox::ConfigValueContainer::description_`[private]`

The description.

Referenced by description(), and getDescription().

Identifier* orxonox::ConfigValueContainer::identifier_`[private]`

The identifier of the class.

Referenced by init(), and tset().

std::string orxonox::ConfigValueContainer::sectionname_`[private]`

The name of the class the variable belongs to.

Referenced by add(), callFunctionWithIndex(), description(), init(), initVector(), remove(), reset(), set(), tset(), and update().

ConfigFileType orxonox::ConfigValueContainer::type_`[private]`

The type of the corresponding config-file.

Referenced by init(), initVector(), remove(), reset(), set(), and update().

MultiType orxonox::ConfigValueContainer::value_`[private]`

The value.

Referenced by initValue(), initVector(), remove(), 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().

std::string orxonox::ConfigValueContainer::varname_`[private]`

The name of the variable.

Referenced by add(), callFunctionWithIndex(), description(), init(), initVector(), remove(), reset(), set(), tset(), and update().

The documentation for this class was generated from the following files:

- src/core/ConfigValueContainer.h
- src/core/ConfigValueContainer.cc