GWOLLUM  4.2.0
Tools for gravitational-wave analyses
IO Class Reference

Parse option files. More...

#include <IO.h>

Public Member Functions

void Dump (ostream &out=cout) const
 Dumps all options. More...
 
template<class T >
bool GetAllOpt (const char *tag, const char *key, T &value)
 Gets options iteratively. More...
 
template<class T >
bool GetAllOpt (const char *tag, const char *key, vector< T > &values)
 Gets a vector of all options. More...
 
string GetLineData (const char *tag, const char *key) const
 Returns the option line defined by a tag and a keyword. More...
 
string GetNextLineData (const char *tag, const char *key)
 Returns the next option line defined by a tag and a keyword. More...
 
bool GetOpt (const char *tag, const char *key, string &value) const
 Gets an option of a string type. More...
 
template<class T >
bool GetOpt (const char *tag, const char *key, T &value) const
 Gets an option. More...
 
template<class T >
bool GetOpt (const char *tag, const char *key, vector< T > &values) const
 Gets an option vector. More...
 
bool IsZombie (void) const
 Flags the parsing sequence. More...
 
Constructors and destructors
 IO (const char *filepattern)
 Constructor of the IO class. More...
 
virtual ~IO (void)
 Destructor of the IO class. More...
 

Private Member Functions

bool ParseFile (const char *filename)
 File parser. More...
 

Private Attributes

vector< pair< string, string > > fAllLines
 List of lines. More...
 
string fCurkey
 Current key. More...
 
unsigned int fCurline
 Current line number. More...
 
string fCurtag
 Current tag. More...
 

Static Private Attributes

static const unsigned int sLinesize = 2048
 Maximum number of characters in a line. More...
 

Friends

ostream & operator<< (ostream &out, IO &io)
 Flux operator wrapper. More...
 

Detailed Description

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 '#'

Author
Florent Robinet

Constructor & Destructor Documentation

◆ IO()

IO::IO ( const char *  filepattern)

Constructor of the IO class.

It loads and reads the option files listed in filepattern.

Parameters
[in]filepatternFile pattern pointing to the option files to be parsed.

◆ ~IO()

IO::~IO ( void  )
virtual

Destructor of the IO class.

Member Function Documentation

◆ Dump()

void IO::Dump ( ostream &  out = cout) const

Dumps all options.

By default it is dumped in the standard output.

Parameters
[in]outOuput stream.

◆ GetAllOpt() [1/2]

template<class T >
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.

Parameters
[in]tagtag name.
[in]keykeyword.
[out]valueoption value.

◆ GetAllOpt() [2/2]

template<class T >
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.

Parameters
[in]tagtag name.
[in]keykeyword.
[out]valuesoption value vector.

◆ GetLineData()

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.

Parameters
[in]tagtag name.
[in]keykeyword.

◆ GetNextLineData()

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.

Parameters
[in]tagtag name.
[in]keykeyword.

◆ GetOpt() [1/3]

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.

Parameters
[in]tagtag name.
[in]keykeyword.
[out]valuereturned string value.

◆ GetOpt() [2/3]

template<class T >
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.

Parameters
[in]tagtag name.
[in]keykeyword.
[out]valuereturned value.

◆ GetOpt() [3/3]

template<class T >
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.

Parameters
[in]tagtag name.
[in]keykeyword.
[out]valuesreturned vector.

◆ IsZombie()

bool IO::IsZombie ( void  ) const
inline

Flags the parsing sequence.

This function returns false if the option files could not be parsed correctly.

◆ ParseFile()

bool IO::ParseFile ( const char *  filename)
private

File parser.

Friends And Related Function Documentation

◆ operator<<

ostream& operator<< ( ostream &  out,
IO io 
)
friend

Flux operator wrapper.

Parameters
[in]outOuput stream.
[in]ioIO object.

Member Data Documentation

◆ fAllLines

vector< pair<string,string> > IO::fAllLines
private

List of lines.

◆ fCurkey

string IO::fCurkey
private

Current key.

◆ fCurline

unsigned int IO::fCurline
private

Current line number.

◆ fCurtag

string IO::fCurtag
private

Current tag.

◆ sLinesize

const unsigned int IO::sLinesize = 2048
staticprivate

Maximum number of characters in a line.


The documentation for this class was generated from the following files: