Orxonox
0.0.5 Codename: Arcturus
|
This class represents a config file, which is stored on the hard-disk and contains config values in different sections. More...
#include </home/jenkins/workspace/orxonox_doxygen_trunk/src/libraries/core/config/ConfigFile.h>
Public Member Functions | |
ConfigFile (const std::string &filename, bool bCopyFallbackFile=true) | |
Constructor: Initializes the config file. More... | |
virtual | ~ConfigFile () |
Destructor: Deletes all sections and entries. More... | |
virtual void | clear () |
Deletes all sections (which again delete all their values) and clears the list of sections. More... | |
void | deleteVectorEntries (const std::string §ion, const std::string &name, unsigned int startindex=0) |
Deletes all elements of a config vector if their index is greater or equal to startindex. More... | |
const std::string & | getFilename () |
Returns the file-name of this config file. More... | |
const std::string & | getOrCreateValue (const std::string §ion, const std::string &name, const std::string &fallback, bool bString) |
Returns the value of a given entry in the config file. More... | |
const std::string & | getOrCreateValue (const std::string §ion, const std::string &name, unsigned int index, const std::string &fallback, bool bString) |
Returns the value of a given element of a vector in the config file. More... | |
const std::string & | getValue (const std::string §ion, const std::string &name, bool bString) |
Returns the value of a given entry in the config file. More... | |
const std::string & | getValue (const std::string §ion, const std::string &name, unsigned int index, bool bString) |
Returns the value of a given element of a vector in the config file. More... | |
unsigned int | getVectorSize (const std::string §ion, const std::string &name) const |
Returns the size of a config vector. More... | |
virtual void | load () |
Loads the config file from the hard-disk and reads the sections and their values. More... | |
virtual void | save () const |
Writes the sections and values to the hard-disk. More... | |
virtual void | saveAs (const std::string &filename) const |
Writes the sections and values to a given file on the hard-disk. More... | |
void | setValue (const std::string §ion, const std::string &name, const std::string &value, bool bString) |
Stores a value in the config file. More... | |
void | setValue (const std::string §ion, const std::string &name, unsigned int index, const std::string &value, bool bString) |
Stores the value of an element of a vector in the config file. More... | |
Static Public Attributes | |
static const char * | DEFAULT_CONFIG_FOLDER = "defaultConfig" |
The folder where the default config files will be stored. More... | |
Protected Member Functions | |
ConfigFileSection * | getOrCreateSection (const std::string §ion) |
Returns a pointer to the section with given name. More... | |
ConfigFileSection * | getSection (const std::string §ion) const |
Returns a pointer to the section with given name (or nullptr if the section doesn't exist). More... | |
Protected Attributes | |
std::list< ConfigFileSection * > | sections_ |
A list of sections in this config file. More... | |
Private Member Functions | |
void | saveIfUpdated () |
Saves the config file if it was updated (or if any of its sections were updated). More... | |
Private Attributes | |
const bool | bCopyFallbackFile_ |
If true, the default config file is copied into the config-directory before loading the file. More... | |
bool | bUpdated_ |
Becomes true if a section is added. More... | |
const std::string | filename_ |
The filename of this config file. More... | |
This class represents a config file, which is stored on the hard-disk and contains config values in different sections.
It provides an interface to manipulate the sections and values.
orxonox::ConfigFile::ConfigFile | ( | const std::string & | filename, |
bool | bCopyFallbackFile = true |
||
) |
Constructor: Initializes the config file.
filename | The file-name of this config file |
bCopyFallbackFile | If true, the default config file is copied into the config-directory before loading the file |
|
virtual |
Destructor: Deletes all sections and entries.
|
virtual |
Deletes all sections (which again delete all their values) and clears the list of sections.
void orxonox::ConfigFile::deleteVectorEntries | ( | const std::string & | section, |
const std::string & | name, | ||
unsigned int | startindex = 0 |
||
) |
Deletes all elements of a config vector if their index is greater or equal to startindex.
section | The name of the section |
name | The name of the vector |
startindex | The index of the first element that will be deleted |
|
inline |
Returns the file-name of this config file.
|
protected |
Returns a pointer to the section with given name.
If it doesn't exist, the section is created.
|
inline |
Returns the value of a given entry in the config file.
If it doesn't exist, the entry is created using the fallback value.
section | The name of the section |
name | The name of the entry |
fallback | The value that will be used if the entry doesn't exist |
bString | If true, the value is treated as string which means some special treatment of special characters. |
|
inline |
Returns the value of a given element of a vector in the config file.
If it doesn't exist, the entry is created using the fallback value.
section | The name of the section |
name | The name of the vector |
index | The index of the element in the vector |
fallback | The value that will be used if the entry doesn't exist |
bString | If true, the value is treated as string which means some special treatment of special characters. |
|
protected |
Returns a pointer to the section with given name (or nullptr if the section doesn't exist).
|
inline |
Returns the value of a given entry in the config file.
Returns a blank string if the value doesn't exist.
section | The name of the section |
name | The name of the entry |
bString | If true, the value is treated as string which means some special treatment of special characters. |
|
inline |
Returns the value of a given element of a vector in the config file.
Returns a blank string if the value doesn't exist.
section | The name of the section |
name | The name of the vector |
index | The index of the element in the vector |
bString | If true, the value is treated as string which means some special treatment of special characters. |
|
inline |
Returns the size of a config vector.
section | The section of the vector |
name | The name of the vector |
|
virtual |
Loads the config file from the hard-disk and reads the sections and their values.
Reimplemented in orxonox::SettingsConfigFile.
|
virtual |
Writes the sections and values to the hard-disk.
|
virtual |
Writes the sections and values to a given file on the hard-disk.
|
private |
Saves the config file if it was updated (or if any of its sections were updated).
|
inline |
Stores a value in the config file.
If the entry or its section doesn't exist, it's created.
section | The name of the section |
name | The name of the entry |
value | The new value |
bString | If true, the value is treated as string which means some special treatment of special characters. |
|
inline |
Stores the value of an element of a vector in the config file.
If the entry or its section doesn't exist, it's created.
section | The name of the section |
name | The name of the vector |
index | The index of the element in the vector |
value | The new value |
bString | If true, the value is treated as string which means some special treatment of special characters. |
|
private |
If true, the default config file is copied into the config-directory before loading the file.
|
private |
Becomes true if a section is added.
|
static |
The folder where the default config files will be stored.
|
private |
The filename of this config file.
|
protected |
A list of sections in this config file.