Parse option files. More...
#include <IO.h>
Public Member Functions | |
void | Dump (ostream &out=cout) const |
Dumps all options. | |
template<class T > | |
bool | GetAllOpt (const char *tag, const char *key, T &value) |
Gets options iteratively. | |
template<class T > | |
bool | GetAllOpt (const char *tag, const char *key, vector< T > &values) |
Gets a vector of all options. | |
string | GetLineData (const char *tag, const char *key) const |
Returns the option line defined by a tag and a keyword. | |
string | GetNextLineData (const char *tag, const char *key) |
Returns the next option line defined by a tag and a keyword. | |
bool | GetOpt (const char *tag, const char *key, string &value) const |
Gets an option of a string type. | |
template<class T > | |
bool | GetOpt (const char *tag, const char *key, T &value) const |
Gets an option. | |
template<class T > | |
bool | GetOpt (const char *tag, const char *key, vector< T > &values) const |
Gets an option vector. | |
bool | IsZombie (void) const |
Flags the parsing sequence. | |
Constructors and destructors | |
IO (const char *filepattern) | |
Constructor of the IO class. | |
virtual | ~IO (void) |
Destructor of the IO class. | |
Friends | |
ostream & | operator<< (ostream &out, IO &io) |
Parse option files.
This class was designed to read an option file and to extract parameters. Options are defined by a tag and a keyword.
IO::IO | ( | const char * | filepattern | ) |
Constructor of the IO class.
It loads and reads the option files listed in filepattern
An option is defined by a single line:
TAG KEY [value]
The [value] can be of any C++ type (string, integer...)
It is also possible to have more than one value:
TAG KEY [value1] [value2] [value3] [value4]
In that case, values are stored in a vector container.
Option lines can be commented out when lines start with the following characters: '//', '' or '#'
filepattern | file pattern pointing to the option files to be parsed. |
virtual IO::~IO | ( | void | ) | [inline, virtual] |
Destructor of the IO class.
void IO::Dump | ( | ostream & | out = cout |
) | const |
Dumps all options.
By default it is dumped in the standard output.
out | ouput stream |
bool IO::GetAllOpt | ( | const char * | tag, | |
const char * | key, | |||
T & | value | |||
) | [inline] |
Gets options iteratively.
This function gets options matching a tag and a keyword. This function is useful when a combination of tag/keyword is repeated over several lines. At each call of this function, the next option value is returned. false is returned if the option is not found.
tag | tag name | |
key | keyword | |
option | value |
bool IO::GetAllOpt | ( | const char * | tag, | |
const char * | key, | |||
vector< T > & | values | |||
) | [inline] |
Gets a vector of all options.
This template function fills a vector with values defined by a tag and a keyword. This function gets all options matching a tag and a keyword. The combination of tag/keyword can be used over several lines. false is returned if the option is not found.
tag | tag name | |
key | keyword | |
option | value vector |
string IO::GetLineData | ( | const char * | tag, | |
const char * | key | |||
) | const |
Returns the option line defined by a tag and a keyword.
If several lines match the tag and keyword, only the last line is retained.
tag | tag name | |
key | keyword |
string IO::GetNextLineData | ( | const char * | tag, | |
const char * | key | |||
) |
Returns the next option line defined by a tag and a keyword.
This function can be called many times (in a row!) to read several lines defined by the same tag/keyword.
tag | tag name | |
key | keyword |
bool IO::GetOpt | ( | const char * | tag, | |
const char * | key, | |||
string & | value | |||
) | const |
Gets an option of a string type.
This function gets an option string value defined by a tag and a keyword. false is returned if the option is not found.
tag | tag name. | |
key | keyword. | |
value | returned string value. |
bool IO::GetOpt | ( | const char * | tag, | |
const char * | key, | |||
T & | value | |||
) | const [inline] |
Gets an option.
This template function gets an option value defined by a tag and a keyword. false is returned if the option is not found.
tag | tag name. | |
key | keyword. | |
value | returned value. |
bool IO::GetOpt | ( | const char * | tag, | |
const char * | key, | |||
vector< T > & | values | |||
) | const [inline] |
Gets an option vector.
This template function fills a vector with values defined by a tag and a keyword. false is returned if the option is not found.
tag | tag name. | |
key | keyword. | |
values | returned vector. |
bool IO::IsZombie | ( | void | ) | const [inline] |
Flags the parsing sequence.
This function returns false if the option files could not be parsed correctly.
ostream& operator<< | ( | ostream & | out, | |
IO & | io | |||
) | [friend] |