SatAndLight  2.2.2-hubble
Simulation toolkit for space telescopes
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 *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...
 
Constructors and destructors
 IO (const string aFilePattern)
 Constructor of the IO class. More...
 
virtual ~IO (void)
 Destructor of the IO class. More...
 

Private Member Functions

bool ParseFile (const char *filename)
 parse one file More...
 

Private Attributes

vector< pair< string, string > > fAllLines
 option lines More...
 
string fCurkey
 current key More...
 
int fCurline
 line counter More...
 
string fCurtag
 current tag More...
 

Static Private Attributes

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

Friends

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

Detailed Description

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

Constructor & Destructor Documentation

◆ 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]aFilePatternFile pattern pointing to the option files to be parsed.

◆ ~IO()

virtual IO::~IO ( void  )
inlinevirtual

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 *  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]aTagTag name.
[in]aKeyKeyword.
[out]aValueValue.

◆ 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]aTagTag name.
[in]aKeyKeyword.
[out]aValuesValue 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]aTagTag name.
[in]aKeyKeyword.

◆ 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
aTagTag name.
aKeyKeyword.

◆ 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]aTagTag name.
[in]aKeyKeyword.
[out]aValueReturned 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]aTagTag name.
[in]aKeyKeyword.
[out]aValueReturned 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]aTagTag name.
[in]aKeyKeyword.
[out]aValuesReturned 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

parse one file

Friends And Related Function Documentation

◆ operator<<

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

Member Data Documentation

◆ fAllLines

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

option lines

◆ fCurkey

string IO::fCurkey
private

current key

◆ fCurline

int IO::fCurline
private

line counter

◆ fCurtag

string IO::fCurtag
private

current tag

◆ 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: