latest version v1.9 - last update 10 Apr 2010 |
Write and read config files, similar to windows ini files. More...
#include <ltiConfigFileHandler.h>
Classes | |
class | parameters |
the parameters for the class configFileHandler More... | |
Public Member Functions | |
configFileHandler () | |
configFileHandler (const configFileHandler &other) | |
virtual | ~configFileHandler () |
virtual const char * | getTypeName () const |
configFileHandler & | copy (const configFileHandler &other) |
configFileHandler & | operator= (const configFileHandler &other) |
virtual functor * | clone () const |
const parameters & | getParameters () const |
bool | apply () |
bool | loadFile () |
bool | loadFile (const std::string &fileName) |
bool | saveFile () const |
bool | saveFile (const std::string &fileName) const |
Reading Values | |
bool | getValue (const std::string §ion, const std::string &key, std::string &value, std::string &comment) const |
bool | getValue (const std::string §ion, const std::string &key, std::string &value) const |
bool | getValue (const std::string §ion, const std::string &key, bool &value, std::string &comment) const |
bool | getValue (const std::string §ion, const std::string &key, bool &value) const |
bool | getValue (const std::string §ion, const std::string &key, double &value, std::string &comment) const |
bool | getValue (const std::string §ion, const std::string &key, double &value) const |
bool | getValue (const std::string §ion, const std::string &key, float &value, std::string &comment) const |
bool | getValue (const std::string §ion, const std::string &key, float &value) const |
bool | getValue (const std::string §ion, const std::string &key, int &value, std::string &comment) const |
bool | getValue (const std::string §ion, const std::string &key, int &value) const |
bool | getValue (const std::string §ion, const std::string &key, unsigned int &value, std::string &comment) const |
bool | getValue (const std::string §ion, const std::string &key, unsigned int &value) const |
std::list< std::string > | getKeys (std::string section) const |
Setting Values | |
Use one of these methods to set entries (section,key,value,comment). You can also use these to set comments:
In case of errors the status string is set and false returned. | |
bool | setValue (const std::string §ion, const std::string &key="", const std::string &value="", const std::string &comment="") |
bool | setValue (const std::string §ion, const std::string &key="", const char *value="", const std::string &comment="") |
bool | setValue (const std::string §ion, const std::string &key="", const bool &value=false, const std::string &comment="") |
bool | setValue (const std::string §ion, const std::string &key="", const double &value=0.0, const std::string &comment="") |
bool | setValue (const std::string §ion, const std::string &key="", const float &value=0.0f, const std::string &comment="") |
bool | setValue (const std::string §ion, const std::string &key="", const int &value=0, const std::string &comment="") |
bool | setValue (const std::string §ion, const std::string &key="", const unsigned int &value=0, const std::string &comment="") |
Manipulation | |
void | sortSections () |
bool | deleteSection (const std::string §ion="") |
bool | deleteKey (const std::string §ion, const std::string &key="") |
void | clear () |
Protected Member Functions | |
std::string | splitLine (const std::string &inputLine, std::string &prolog, std::string §ion, std::string &key, std::string &value, std::string &comment) const |
void | composeLine (const std::string &prolog, const std::string §ion, const std::string &key, const std::string &value, const std::string &comment, bool secDef, int keyLength, std::string &outputLine) const |
int | getMaxKeyLengths (std::map< std::string, int > &maxKeyLengths) const |
Protected Attributes | |
std::map< std::string, std::map< std::string, configEntry > > | dictionary |
std::list< std::string > | orderSections |
std::map< std::string, std::list< std::string > > | orderKeys |
std::map< std::string, std::list< std::string > > | sectionComments |
std::map< std::string, std::string > | sectionOrig |
std::map< std::string, std::map< std::string, std::string > > | keyOrig |
Write and read config files, similar to windows ini files.
These contain:
All entries will be written as specified, however searching keys or values is case insensitive!
Example config file:
# a global comment * * comments in cvs style are alowed too * [a section] # a section comment key = value ; a key comment [another section] ;more comments key = value
Comments can be global, for sections or for single keys. A section comment must be positioned before the first key of this section. Comments for keys start with ';'
lti::configFileHandler::configFileHandler | ( | ) |
default constructor
lti::configFileHandler::configFileHandler | ( | const configFileHandler & | other | ) |
copy constructor
other | the object to be copied |
virtual lti::configFileHandler::~configFileHandler | ( | ) | [virtual] |
destructor
bool lti::configFileHandler::apply | ( | ) |
This is an alias for loadFile().
void lti::configFileHandler::clear | ( | ) |
Delete every comment, section and key of the internal structure of the config file.
If you write after this to disk you get an empty file.
virtual functor* lti::configFileHandler::clone | ( | ) | const [virtual] |
returns a pointer to a clone of this functor.
Implements lti::functor.
void lti::configFileHandler::composeLine | ( | const std::string & | prolog, | |
const std::string & | section, | |||
const std::string & | key, | |||
const std::string & | value, | |||
const std::string & | comment, | |||
bool | secDef, | |||
int | keyLength, | |||
std::string & | outputLine | |||
) | const [protected] |
Creates a line of the configFile based on the given values.
configFileHandler& lti::configFileHandler::copy | ( | const configFileHandler & | other | ) |
copy data of "other" functor.
other | the functor to be copied |
Reimplemented from lti::functor.
bool lti::configFileHandler::deleteKey | ( | const std::string & | section, | |
const std::string & | key = "" | |||
) |
Delete a key in an section.
The return value is false if no key of this name exists. If you set the name of the section only you remove all comments of this section.
bool lti::configFileHandler::deleteSection | ( | const std::string & | section = "" |
) |
Remove alle elements of the section 'section'.
If section is not set all comments above the first section are removed. The return value is false if no section of this name exists.
std::list<std::string> lti::configFileHandler::getKeys | ( | std::string | section | ) | const |
Returns a list of all keys in the specified section.
int lti::configFileHandler::getMaxKeyLengths | ( | std::map< std::string, int > & | maxKeyLengths | ) | const [protected] |
Creates a map containing section|->maxKeyLength for formatted saving.
Additionally returns the overall maximum length of a key name
const parameters& lti::configFileHandler::getParameters | ( | ) | const |
returns used parameters
Reimplemented from lti::ioFunctor.
virtual const char* lti::configFileHandler::getTypeName | ( | ) | const [virtual] |
returns the name of this type ("configFileHandler")
Reimplemented from lti::ioFunctor.
bool lti::configFileHandler::getValue | ( | const std::string & | section, | |
const std::string & | key, | |||
unsigned int & | value | |||
) | const [inline] |
unsigned int
References getValue().
bool lti::configFileHandler::getValue | ( | const std::string & | section, | |
const std::string & | key, | |||
unsigned int & | value, | |||
std::string & | comment | |||
) | const |
unsigned int
bool lti::configFileHandler::getValue | ( | const std::string & | section, | |
const std::string & | key, | |||
int & | value | |||
) | const [inline] |
int
References getValue().
bool lti::configFileHandler::getValue | ( | const std::string & | section, | |
const std::string & | key, | |||
int & | value, | |||
std::string & | comment | |||
) | const |
int
bool lti::configFileHandler::getValue | ( | const std::string & | section, | |
const std::string & | key, | |||
float & | value | |||
) | const [inline] |
float
References getValue().
bool lti::configFileHandler::getValue | ( | const std::string & | section, | |
const std::string & | key, | |||
float & | value, | |||
std::string & | comment | |||
) | const |
float
bool lti::configFileHandler::getValue | ( | const std::string & | section, | |
const std::string & | key, | |||
double & | value | |||
) | const [inline] |
double
References getValue().
bool lti::configFileHandler::getValue | ( | const std::string & | section, | |
const std::string & | key, | |||
double & | value, | |||
std::string & | comment | |||
) | const |
double
bool lti::configFileHandler::getValue | ( | const std::string & | section, | |
const std::string & | key, | |||
bool & | value | |||
) | const [inline] |
bool
References getValue().
bool lti::configFileHandler::getValue | ( | const std::string & | section, | |
const std::string & | key, | |||
bool & | value, | |||
std::string & | comment | |||
) | const |
bool
bool lti::configFileHandler::getValue | ( | const std::string & | section, | |
const std::string & | key, | |||
std::string & | value | |||
) | const [inline] |
string
References getValue().
bool lti::configFileHandler::getValue | ( | const std::string & | section, | |
const std::string & | key, | |||
std::string & | value, | |||
std::string & | comment | |||
) | const |
string
Referenced by getValue().
bool lti::configFileHandler::loadFile | ( | const std::string & | fileName | ) |
Same as loadFile(), but given fileName overrides parameters.
bool lti::configFileHandler::loadFile | ( | ) |
Loads the specified config file into the dictionary.
If the file is not valid, does not exist, or in case of parse errors 'false' will be returned and the statusString will be set.
configFileHandler& lti::configFileHandler::operator= | ( | const configFileHandler & | other | ) |
bool lti::configFileHandler::saveFile | ( | const std::string & | fileName | ) | const |
Same as saveFile(), but given fileName overrides parameters.
bool lti::configFileHandler::saveFile | ( | ) | const |
Saves the dictionary in the file specified in the parameters (replaces existing).
On error the status string is set and false is returned.
bool lti::configFileHandler::setValue | ( | const std::string & | section, | |
const std::string & | key = "" , |
|||
const unsigned int & | value = 0 , |
|||
const std::string & | comment = "" | |||
) |
unsigned int
bool lti::configFileHandler::setValue | ( | const std::string & | section, | |
const std::string & | key = "" , |
|||
const int & | value = 0 , |
|||
const std::string & | comment = "" | |||
) |
int
bool lti::configFileHandler::setValue | ( | const std::string & | section, | |
const std::string & | key = "" , |
|||
const float & | value = 0.0f , |
|||
const std::string & | comment = "" | |||
) |
float
bool lti::configFileHandler::setValue | ( | const std::string & | section, | |
const std::string & | key = "" , |
|||
const double & | value = 0.0 , |
|||
const std::string & | comment = "" | |||
) |
double
bool lti::configFileHandler::setValue | ( | const std::string & | section, | |
const std::string & | key = "" , |
|||
const bool & | value = false , |
|||
const std::string & | comment = "" | |||
) |
bool
bool lti::configFileHandler::setValue | ( | const std::string & | section, | |
const std::string & | key = "" , |
|||
const char * | value = "" , |
|||
const std::string & | comment = "" | |||
) | [inline] |
const char*
References setValue().
bool lti::configFileHandler::setValue | ( | const std::string & | section, | |
const std::string & | key = "" , |
|||
const std::string & | value = "" , |
|||
const std::string & | comment = "" | |||
) |
string
Referenced by setValue().
void lti::configFileHandler::sortSections | ( | ) |
Sort the sections of the dictionary.
The sections are sorted in ascending order. The order of the keys in a section in not changed!
std::string lti::configFileHandler::splitLine | ( | const std::string & | inputLine, | |
std::string & | prolog, | |||
std::string & | section, | |||
std::string & | key, | |||
std::string & | value, | |||
std::string & | comment | |||
) | const [protected] |
This function splits a line into the tokens key, section.
..
std::map<std::string, std::map<std::string, configEntry> > lti::configFileHandler::dictionary [protected] |
Map with section name as key, and map of section's keys as value.
std::map<std::string, std::map<std::string, std::string> > lti::configFileHandler::keyOrig [protected] |
Stores capitalization of keys.
std::map<std::string, std::list<std::string> > lti::configFileHandler::orderKeys [protected] |
Stores the order of the keys in each section.
std::list<std::string> lti::configFileHandler::orderSections [protected] |
Stores the order of the sections.
std::map<std::string, std::list<std::string> > lti::configFileHandler::sectionComments [protected] |
Stores pure comments without a key.
std::map<std::string, std::string> lti::configFileHandler::sectionOrig [protected] |
Stores capitalization of sections.