Loads a configuration file. More...
#include <Application/ConfigFile.h>
Classes | |
class | ConfigValue |
Holds a single config value. More... | |
Public Types | |
enum | ValueType { TYPE_UNKNOWN = -1, TYPE_FLOAT = 0, TYPE_INTEGER, TYPE_STRING, TYPE_BOOL, TYPE_VECTOR2, TYPE_COLOR4, TYPE_COUNT } |
Defins the diffeant types a value can have. More... | |
Public Member Functions | |
ConfigFile () | |
Constructs an empty config file. | |
ConfigFile (const char *file) | |
Constructs and loads a config file. | |
~ConfigFile () | |
Deconstructor. | |
bool | Load (const char *file) |
Loads a config file. | |
bool | Save (const char *name) |
Writes a config file. | |
const ConfigValue * | FindValueByName (const char *name) const |
Searches for the existance of a value by name. | |
const ConfigValue & | operator[] (const char *name) const |
Retrieves a value. | |
bool | SetValue (const char *name, const char *value) |
Creates or sets a value. | |
bool | SetValue (const std::string &name, const std::string &value) |
Creates or sets a value. |
Loads a configuration file.
Each line of the config defines a key value pair in the following format:
key = value
Where key is a case-sensitve single string of charachters without spaces or newlines. Value is the data value associated with the key. To define a color use the color operator Color(r, g, b, a) where r, g, b, and a are in the range [0,1]. To define a vector use the Vector operator Vector(x, y). All other data types will be auto detected. If the type cannot be deduced, it is assumed to be a string.
Line comments are started with the ';' symbole. All characters in a line following a semi-colon are ignored.
Duplicate occurances of a single key will overwrite the previous value. The file is read from the top down.
Defins the diffeant types a value can have.
ConfigFile::ConfigFile | ( | const char * | file | ) |
Constructs and loads a config file.
[in] | file | the name of the config file to load. |
const ConfigFile::ConfigValue * ConfigFile::FindValueByName | ( | const char * | name | ) | const |
Searches for the existance of a value by name.
[in] | name | the name of the value to search for. |
bool ConfigFile::Load | ( | const char * | file | ) |
Loads a config file.
[in] | file | the name of the config file to load. |
const ConfigFile::ConfigValue & ConfigFile::operator[] | ( | const char * | name | ) | const |
Retrieves a value.
[in] | name | the name of the value. |
bool ConfigFile::Save | ( | const char * | name | ) |
Writes a config file.
[in] | name | the name of the config file to write to. |
bool ConfigFile::SetValue | ( | const std::string & | name, | |
const std::string & | value | |||
) |
Creates or sets a value.
[in] | name | the name of the value. |
[in] | value | the value to associate with the value. |
bool ConfigFile::SetValue | ( | const char * | name, | |
const char * | value | |||
) |
Creates or sets a value.
[in] | name | the name of the value. |
[in] | value | the value to associate with the value. |