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

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>

Inheritance diagram for orxonox::ConfigFile:
orxonox::SettingsConfigFile

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 &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. More...
 
const std::string & getFilename ()
 Returns the file-name of this config file. More...
 
const std::string & getOrCreateValue (const std::string &section, 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 &section, 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 &section, 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 &section, 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 &section, 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 &section, const std::string &name, const std::string &value, bool bString)
 Stores a value in the config file. More...
 
void setValue (const std::string &section, 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

ConfigFileSectiongetOrCreateSection (const std::string &section)
 Returns a pointer to the section with given name. More...
 
ConfigFileSectiongetSection (const std::string &section) 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...
 

Detailed Description

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.

Constructor & Destructor Documentation

orxonox::ConfigFile::ConfigFile ( const std::string &  filename,
bool  bCopyFallbackFile = true 
)

Constructor: Initializes the config file.

Parameters
filenameThe file-name of this config file
bCopyFallbackFileIf true, the default config file is copied into the config-directory before loading the file
orxonox::ConfigFile::~ConfigFile ( )
virtual

Destructor: Deletes all sections and entries.

Member Function Documentation

void orxonox::ConfigFile::clear ( )
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.

Parameters
sectionThe name of the section
nameThe name of the vector
startindexThe index of the first element that will be deleted
const std::string& orxonox::ConfigFile::getFilename ( )
inline

Returns the file-name of this config file.

ConfigFileSection * orxonox::ConfigFile::getOrCreateSection ( const std::string &  sectionName)
protected

Returns a pointer to the section with given name.

If it doesn't exist, the section is created.

const std::string& orxonox::ConfigFile::getOrCreateValue ( const std::string &  section,
const std::string &  name,
const std::string &  fallback,
bool  bString 
)
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.

Parameters
sectionThe name of the section
nameThe name of the entry
fallbackThe value that will be used if the entry doesn't exist
bStringIf true, the value is treated as string which means some special treatment of special characters.
const std::string& orxonox::ConfigFile::getOrCreateValue ( const std::string &  section,
const std::string &  name,
unsigned int  index,
const std::string &  fallback,
bool  bString 
)
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.

Parameters
sectionThe name of the section
nameThe name of the vector
indexThe index of the element in the vector
fallbackThe value that will be used if the entry doesn't exist
bStringIf true, the value is treated as string which means some special treatment of special characters.
ConfigFileSection * orxonox::ConfigFile::getSection ( const std::string &  section) const
protected

Returns a pointer to the section with given name (or nullptr if the section doesn't exist).

const std::string& orxonox::ConfigFile::getValue ( const std::string &  section,
const std::string &  name,
bool  bString 
)
inline

Returns the value of a given entry in the config file.

Returns a blank string if the value doesn't exist.

Parameters
sectionThe name of the section
nameThe name of the entry
bStringIf true, the value is treated as string which means some special treatment of special characters.
const std::string& orxonox::ConfigFile::getValue ( const std::string &  section,
const std::string &  name,
unsigned int  index,
bool  bString 
)
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.

Parameters
sectionThe name of the section
nameThe name of the vector
indexThe index of the element in the vector
bStringIf true, the value is treated as string which means some special treatment of special characters.
unsigned int orxonox::ConfigFile::getVectorSize ( const std::string &  section,
const std::string &  name 
) const
inline

Returns the size of a config vector.

Parameters
sectionThe section of the vector
nameThe name of the vector
void orxonox::ConfigFile::load ( )
virtual

Loads the config file from the hard-disk and reads the sections and their values.

Reimplemented in orxonox::SettingsConfigFile.

void orxonox::ConfigFile::save ( ) const
virtual

Writes the sections and values to the hard-disk.

void orxonox::ConfigFile::saveAs ( const std::string &  filename) const
virtual

Writes the sections and values to a given file on the hard-disk.

void orxonox::ConfigFile::saveIfUpdated ( )
private

Saves the config file if it was updated (or if any of its sections were updated).

void orxonox::ConfigFile::setValue ( const std::string &  section,
const std::string &  name,
const std::string &  value,
bool  bString 
)
inline

Stores a value in the config file.

If the entry or its section doesn't exist, it's created.

Parameters
sectionThe name of the section
nameThe name of the entry
valueThe new value
bStringIf true, the value is treated as string which means some special treatment of special characters.
void orxonox::ConfigFile::setValue ( const std::string &  section,
const std::string &  name,
unsigned int  index,
const std::string &  value,
bool  bString 
)
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.

Parameters
sectionThe name of the section
nameThe name of the vector
indexThe index of the element in the vector
valueThe new value
bStringIf true, the value is treated as string which means some special treatment of special characters.

Member Data Documentation

const bool orxonox::ConfigFile::bCopyFallbackFile_
private

If true, the default config file is copied into the config-directory before loading the file.

bool orxonox::ConfigFile::bUpdated_
private

Becomes true if a section is added.

const char * orxonox::ConfigFile::DEFAULT_CONFIG_FOLDER = "defaultConfig"
static

The folder where the default config files will be stored.

const std::string orxonox::ConfigFile::filename_
private

The filename of this config file.

std::list<ConfigFileSection*> orxonox::ConfigFile::sections_
protected

A list of sections in this config file.


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