Orxonox  0.0.5 Codename: Arcturus
Public Member Functions | Private Member Functions | Private Attributes | List of all members
orxonox::ConfigValueContainer Class Reference

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

#include </home/jenkins/workspace/orxonox_doxygen_trunk/src/libraries/core/config/ConfigValueContainer.h>

Public Member Functions

template<class D , class V >
 ConfigValueContainer (ConfigFileType::Value 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. More...
 
template<class D , class V >
 ConfigValueContainer (ConfigFileType::Value type, Identifier *identifier, const std::string &sectionname, const std::string &varname, const std::vector< D > &defvalue, const std::vector< V > &value)
 Constructor: Converts the default-value to a string, checks the config-file for a changed value, sets the intern value variable. More...
 
 ~ConfigValueContainer ()
 Destructor: Deletes the callback object if necessary. More...
 
bool add (const MultiType &input)
 Adds a new entry to the end of the vector. More...
 
template<class T >
ConfigValueContainercallback (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. More...
 
ConfigValueContainerdescription (const std::string &description)
 Adds a description to the config-value. More...
 
const std::string & getDescription () const
 Returns the description of the config-value. More...
 
IdentifiergetIdentifier () const
 Returns the associated identifier (can be nullptr). More...
 
const std::string & getName () const
 Returns the name of this container. More...
 
const std::string & getSectionName () const
 Returns the name of the section this config value is in. More...
 
std::string getTypename () const
 Returns the typename of the assigned config-value. More...
 
template<typename T , class C >
ConfigValueContainergetValue (T *value, C *object)
 Returns the configured value. More...
 
template<typename T , class C >
ConfigValueContainergetValue (std::vector< T > *value, C *object)
 Returns the configured vector. More...
 
unsigned int getVectorSize () const
 Returns the vectors size (or zero if it's not a vector). More...
 
bool isVector () const
 Returns true if this config-value is a vector. More...
 
bool remove (unsigned int index)
 Removes an existing entry from the vector. More...
 
bool reset ()
 Sets the value of the variable back to the default value and resets the config-file entry. More...
 
bool set (const MultiType &input)
 Assigns a new value to the config-value of all objects and writes the change into the config-file. More...
 
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. More...
 
std::string toString () const
 Converts the config-value to a string. More...
 
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). More...
 
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). More...
 
void update ()
 Retrieves the configured value from the currently loaded config-file. More...
 

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. More...
 
void init (ConfigFileType::Value type, Identifier *identifier, const std::string &sectionname, const std::string &varname)
 Initializes the ConfigValueContainer with default values. More...
 
void initValue (const MultiType &defvalue)
 Does some special initialization for single config-values. More...
 
void initVector ()
 Does some special initialization for vector config-values. More...
 

Private Attributes

bool bAddedDescription_
 True if a description was added. More...
 
bool bContainerIsNew_
 True if it's the first time getValue() gets called. More...
 
bool bDoInitialCallback_
 True if the callback should be called as soon as it gets created. More...
 
bool bIsVector_
 True if the container contains a std::vector. More...
 
ConfigValueCallbackBasecallback_
 A callback function to call after getValue if the value changed. More...
 
std::string defvalueString_
 The string of the default-value. More...
 
std::vector< std::string > defvalueStringVector_
 A vector, containg the strings of the default-values in case we're storing a vector. More...
 
LanguageEntryLabel description_
 The description. More...
 
Identifieridentifier_
 The identifier of the class. More...
 
std::string sectionname_
 The name of the class the variable belongs to. More...
 
ConfigFileType::Value type_
 The type of the corresponding config-file. More...
 
MultiType value_
 The value. More...
 
std::vector< MultiTypevalueVector_
 A vector, containg the values in case we're storing a vector. More...
 
std::string varname_
 The name of the variable. More...
 

Detailed Description

The ConfigValuecontainer contains all needed information about a configurable variable.

The ConfigValueContainer class contains all needed information 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.

Constructor & Destructor Documentation

template<class D , class V >
orxonox::ConfigValueContainer::ConfigValueContainer ( ConfigFileType::Value  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
typeThe type of the corresponding config-file
identifierThe identifier of the class the variable belongs to
sectionnameName of the section the configValue should be put in.
varnameThe name of the variable
defvalueThe default-value
valueOnly needed do determine the right type.
template<class D , class V >
orxonox::ConfigValueContainer::ConfigValueContainer ( ConfigFileType::Value  type,
Identifier identifier,
const std::string &  sectionname,
const std::string &  varname,
const std::vector< D > &  defvalue,
const std::vector< 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
typeThe type of the corresponding config-file
identifierThe identifier of the class the variable belongs to
sectionnameName of the section the configValue should be put in.
varnameThe name of the variable
defvalueThe default-value
valueOnly needed do determine the right type.
orxonox::ConfigValueContainer::~ConfigValueContainer ( )

Destructor: Deletes the callback object if necessary.

Member Function Documentation

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

Adds a new entry to the end of the vector.

Parameters
inputThe new entry
Returns
True if the new entry was successfully added
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
objectThe object to call the function
functionThe callback function
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
functionThe function to call
inputThe input string
Returns
The returnvalue of the functioncall
ConfigValueContainer & orxonox::ConfigValueContainer::description ( const std::string &  description)

Adds a description to the config-value.

Parameters
descriptionThe description
const std::string & orxonox::ConfigValueContainer::getDescription ( ) const

Returns the description of the config-value.

Returns
The description
Identifier* orxonox::ConfigValueContainer::getIdentifier ( ) const
inline

Returns the associated identifier (can be nullptr).

const std::string& orxonox::ConfigValueContainer::getName ( void  ) const
inline

Returns the name of this container.

const std::string& orxonox::ConfigValueContainer::getSectionName ( ) const
inline

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

template<typename T , class C >
ConfigValueContainer& orxonox::ConfigValueContainer::getValue ( T *  value,
C *  object 
)
inline

Returns the configured value.

Parameters
valueA pointer to the variable to store the value.
objectThe object calling this function
Returns
The ConfigValueContainer
template<typename T , class C >
ConfigValueContainer& orxonox::ConfigValueContainer::getValue ( std::vector< T > *  value,
C *  object 
)
inline

Returns the configured vector.

Parameters
valueA pointer to the vector to store the values.
objectThe object calling this function
Returns
The ConfigValueContainer
unsigned int orxonox::ConfigValueContainer::getVectorSize ( ) const
inline

Returns the vectors size (or zero if it's not a vector).

void orxonox::ConfigValueContainer::init ( ConfigFileType::Value  type,
Identifier identifier,
const std::string &  sectionname,
const std::string &  varname 
)
private

Initializes the ConfigValueContainer with default values.

void orxonox::ConfigValueContainer::initValue ( const MultiType defvalue)
private

Does some special initialization for single config-values.

void orxonox::ConfigValueContainer::initVector ( )
private

Does some special initialization for vector config-values.

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
indexThe index of the entry
Returns
True if the entry was removed
bool orxonox::ConfigValueContainer::reset ( )

Sets the value of the variable back to the default value and resets the config-file entry.

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
inputThe new value
Returns
True if the new value was successfully assigned
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
indexThe index in the vector
inputThe new value
Returns
True if the new value was successfully assigned
std::string orxonox::ConfigValueContainer::toString ( ) const
inline

Converts the config-value to a string.

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
inputThe new value. If bIsVector_ then write "index value"
Returns
True if the new value was successfully assigned
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
indexThe index in the vector
inputThe new value
Returns
True if the new value was successfully assigned
void orxonox::ConfigValueContainer::update ( )

Retrieves the configured value from the currently loaded config-file.

Member Data Documentation

bool orxonox::ConfigValueContainer::bAddedDescription_
private

True if a description was added.

bool orxonox::ConfigValueContainer::bContainerIsNew_
private

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

bool orxonox::ConfigValueContainer::bDoInitialCallback_
private

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

bool orxonox::ConfigValueContainer::bIsVector_
private

True if the container contains a std::vector.

ConfigValueCallbackBase* orxonox::ConfigValueContainer::callback_
private

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

std::string orxonox::ConfigValueContainer::defvalueString_
private

The string of the default-value.

std::vector<std::string> orxonox::ConfigValueContainer::defvalueStringVector_
private

A vector, containg the strings of the default-values in case we're storing a vector.

LanguageEntryLabel orxonox::ConfigValueContainer::description_
private

The description.

Identifier* orxonox::ConfigValueContainer::identifier_
private

The identifier of the class.

std::string orxonox::ConfigValueContainer::sectionname_
private

The name of the class the variable belongs to.

ConfigFileType::Value orxonox::ConfigValueContainer::type_
private

The type of the corresponding config-file.

MultiType orxonox::ConfigValueContainer::value_
private

The value.

std::vector<MultiType> orxonox::ConfigValueContainer::valueVector_
private

A vector, containg the values in case we're storing a vector.

std::string orxonox::ConfigValueContainer::varname_
private

The name of the variable.


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