Parse option files.
More...
#include <IO.h>
|
void | Dump (ostream &out=cout) const |
| Dumps all options. More...
|
|
template<class T > |
bool | GetAllOpt (const char *aTag, const char *aKey, T &aValue) |
| Gets options iteratively. More...
|
|
template<class T > |
bool | GetAllOpt (const char *aTag, const char *aKey, vector< T > &aValues) |
| Gets a vector of all options. More...
|
|
string | GetLineData (const char *aTag, const char *aKey) const |
| Returns the option line defined by a tag and a keyword. More...
|
|
string | GetNextLineData (const char *aTag, const char *aKey) |
| Returns the next option line defined by a tag and a keyword. More...
|
|
bool | GetOpt (const char *aTag, const char *aKey, string &aValue) const |
| Gets an option of a string type. More...
|
|
template<class T > |
bool | GetOpt (const char *aTag, const char *aKey, T &aValue) const |
| Gets an option. More...
|
|
template<class T > |
bool | GetOpt (const char *aTag, const char *aKey, vector< T > &aValues) const |
| Gets an option vector. More...
|
|
bool | IsZombie (void) const |
| Flags the parsing sequence. More...
|
|
|
| IO (const string aFilePattern) |
| Constructor of the IO class. More...
|
|
virtual | ~IO (void) |
| Destructor of the IO class. More...
|
|
|
static const unsigned | sLinesize = 2048 |
| maximum number of characters in a line More...
|
|
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.
- Author
- Florent Robinet
◆ IO()
IO::IO |
( |
const string |
aFilePattern | ) |
|
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 '#'
- Parameters
-
[in] | aFilePattern | File pattern pointing to the option files to be parsed. |
◆ ~IO()
Destructor of the IO class.
◆ Dump()
void IO::Dump |
( |
ostream & |
out = cout | ) |
const |
Dumps all options.
By default it is dumped in the standard output.
- Parameters
-
◆ GetAllOpt() [1/2]
template<class T >
bool IO::GetAllOpt |
( |
const char * |
aTag, |
|
|
const char * |
aKey, |
|
|
T & |
aValue |
|
) |
| |
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.
- Returns
- false if the option is not found.
- Parameters
-
[in] | aTag | Tag name. |
[in] | aKey | Keyword. |
[out] | aValue | Value. |
◆ GetAllOpt() [2/2]
template<class T >
bool IO::GetAllOpt |
( |
const char * |
aTag, |
|
|
const char * |
aKey, |
|
|
vector< T > & |
aValues |
|
) |
| |
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.
- Returns
- false if the option is not found.
- Parameters
-
[in] | aTag | Tag name. |
[in] | aKey | Keyword. |
[out] | aValues | Value vector. |
◆ GetLineData()
string IO::GetLineData |
( |
const char * |
aTag, |
|
|
const char * |
aKey |
|
) |
| 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.
- Parameters
-
[in] | aTag | Tag name. |
[in] | aKey | Keyword. |
◆ GetNextLineData()
string IO::GetNextLineData |
( |
const char * |
aTag, |
|
|
const char * |
aKey |
|
) |
| |
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.
- Parameters
-
aTag | Tag name. |
aKey | Keyword. |
◆ GetOpt() [1/3]
bool IO::GetOpt |
( |
const char * |
aTag, |
|
|
const char * |
aKey, |
|
|
string & |
aValue |
|
) |
| const |
Gets an option of a string type.
This function gets an option string value defined by a tag and a keyword.
- Returns
- false if the option is not found.
- Parameters
-
[in] | aTag | Tag name. |
[in] | aKey | Keyword. |
[out] | aValue | Returned string value. |
◆ GetOpt() [2/3]
template<class T >
bool IO::GetOpt |
( |
const char * |
aTag, |
|
|
const char * |
aKey, |
|
|
T & |
aValue |
|
) |
| const |
Gets an option.
This template function gets an option value defined by a tag and a keyword.
- Returns
- false if the option is not found.
- Parameters
-
[in] | aTag | Tag name. |
[in] | aKey | Keyword. |
[out] | aValue | Returned value. |
◆ GetOpt() [3/3]
template<class T >
bool IO::GetOpt |
( |
const char * |
aTag, |
|
|
const char * |
aKey, |
|
|
vector< T > & |
aValues |
|
) |
| const |
Gets an option vector.
This template function fills a vector with values defined by a tag and a keyword.
- Returns
- false if the option is not found.
- Parameters
-
[in] | aTag | Tag name. |
[in] | aKey | Keyword. |
[out] | aValues | Returned vector. |
◆ IsZombie()
bool IO::IsZombie |
( |
void |
| ) |
const |
|
inline |
Flags the parsing sequence.
- Returns
- false if the option files could not be parsed correctly.
◆ ParseFile()
bool IO::ParseFile |
( |
const char * |
filename | ) |
|
|
private |
◆ operator<<
ostream& operator<< |
( |
ostream & |
out, |
|
|
IO & |
io |
|
) |
| |
|
friend |
◆ fAllLines
vector< pair<string,string> > IO::fAllLines |
|
private |
◆ fCurkey
◆ fCurline
◆ fCurtag
◆ sLinesize
const unsigned IO::sLinesize = 2048 |
|
staticprivate |
maximum number of characters in a line
The documentation for this class was generated from the following files: