![]() |
GWOLLUM 4.2.0
Tools for gravitational-wave analyses
|
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. | |
Private Member Functions | |
bool | ParseFile (const char *filename) |
File parser. | |
Private Attributes | |
vector< pair< string, string > > | fAllLines |
List of lines. | |
string | fCurkey |
Current key. | |
unsigned int | fCurline |
Current line number. | |
string | fCurtag |
Current tag. | |
Monitor * | mon |
Class monitor. | |
Static Private Attributes | |
static const unsigned int | sLinesize = 2048 |
Maximum number of characters in a line. | |
Friends | |
ostream & | operator<< (ostream &out, IO &io) |
Flux operator wrapper. | |
Parse option files.
This class is designed to read an option file and to extract parameters. Options are uniquely defined by a tag and a keyword.
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 '#'
IO::IO | ( | const char * | filepattern | ) |
Constructor of the IO class.
It loads and reads the option files listed in filepattern.
[in] | filepattern | File pattern pointing to the option files to be parsed. |
|
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.
[in] | out | Ouput stream. |
bool IO::GetAllOpt | ( | const char * | tag, |
const char * | key, | ||
T & | value | ||
) |
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.
[in] | tag | tag name. |
[in] | key | keyword. |
[out] | value | option value. |
bool IO::GetAllOpt | ( | const char * | tag, |
const char * | key, | ||
vector< T > & | values | ||
) |
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.
[in] | tag | tag name. |
[in] | key | keyword. |
[out] | values | 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.
[in] | tag | tag name. |
[in] | 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.
[in] | tag | tag name. |
[in] | 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.
[in] | tag | tag name. |
[in] | key | keyword. |
[out] | value | returned string value. |
bool IO::GetOpt | ( | const char * | tag, |
const char * | key, | ||
T & | value | ||
) | const |
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.
[in] | tag | tag name. |
[in] | key | keyword. |
[out] | value | returned value. |
bool IO::GetOpt | ( | const char * | tag, |
const char * | key, | ||
vector< T > & | values | ||
) | const |
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.
[in] | tag | tag name. |
[in] | key | keyword. |
[out] | values | returned vector. |
|
inline |
Flags the parsing sequence.
This function returns false if the option files could not be parsed correctly.
|
private |
File parser.
|
friend |
Flux operator wrapper.
[in] | out | Ouput stream. |
[in] | io | IO object. |
|
private |
List of lines.
|
private |
Current key.
|
private |
Current line number.
|
private |
Current tag.
|
private |
Class monitor.
|
staticprivate |
Maximum number of characters in a line.