![]() |
Gowdy solver
|
Contains key = value
pairs that are obtained from a configuration file.
More...
#include <paramsHolder.h>
Public Member Functions | |
bool | exists (const std::string &key) const |
Checks wether the given key already exists. | |
Parameters (const std::string &fileName) | |
Loads the configuration parameters from file. | |
void | get (const std::string &key, Real &var, const Real defaultValue) |
void | get (const std::string &key, Int &var, const Int defaultValue) |
void | get (const std::string &key, std::string &var, const char *defaultValue) |
void | get (const std::string &key, bool &var, const bool defaultValue) |
std::string | get (const std::string &key, Int &var, const Int defaultValue, std::map< std::string, int > &enumMap) |
void | dump () |
Dumps all the keys that were loaded. |
Contains key = value
pairs that are obtained from a configuration file.
Definition at line 12 of file paramsHolder.h.
Parameters::Parameters | ( | const std::string & | fileName | ) | [inline] |
Loads the configuration parameters from file.
The expected format is key = value
(where value can be empty).
Definition at line 26 of file paramsHolder.h.
References exists().
{ FILE* inf = fileName == "stdin" ? stdin : fopen( fileName.c_str(), "r" ); if( ! inf ) { std::cerr << "Error: Could not open " << fileName << std::endl; return; } char line[ 1024 ] = {0}; while( fgets( line, sizeof(line)-1, inf ) ) { char key[ 64 ] = {0}; int eqpos = -1, value = -1; if ( 1 != sscanf( line, " %s %n= %n", key, &eqpos, &value ) ) { // empty line } else if ( eqpos < 0 || line[eqpos] != '=' ) { std::cerr << "Error: Not 'key = value' pair:" << std::endl << line; } else { char* chp = line + value; while( *chp ) ++chp; while( isspace( chp[-1] ) ) { *--chp = 0; } if ( exists( key ) ) { std::cerr << "Warning: Redefining " << key << std::endl; } operator[]( key ) = std::string( line + value ); } }; fclose( inf ); }
void Parameters::dump | ( | ) | [inline] |
Dumps all the keys that were loaded.
Definition at line 97 of file paramsHolder.h.
{ for ( Parameters::iterator i = begin(); i != end(); ++i ) { std::cout << "(" << i->first << ")=(" << i->second << ")" << std::endl; } }
bool Parameters::exists | ( | const std::string & | key | ) | const [inline] |
Checks wether the given key already exists.
Definition at line 19 of file paramsHolder.h.
Referenced by get(), and Parameters().
{
return count( key ) > 0;
}
void Parameters::get | ( | const std::string & | key, |
Real & | var, | ||
const Real | defaultValue | ||
) | [inline] |
Definition at line 60 of file paramsHolder.h.
References exists(), and strToReal.
Referenced by BimetricModel::BimetricModel(), GridInitialData::GridInitialData(), GridOutputWriter::GridOutputWriter(), MoLIntegrator::MoLIntegrator(), and UniformGrid::UniformGrid().
void Parameters::get | ( | const std::string & | key, |
Int & | var, | ||
const Int | defaultValue | ||
) | [inline] |
Definition at line 66 of file paramsHolder.h.
References exists().
{ var = !exists( key ) ? defaultValue : std::atoi( operator[]( key ).c_str() ); }
void Parameters::get | ( | const std::string & | key, |
std::string & | var, | ||
const char * | defaultValue | ||
) | [inline] |
Definition at line 72 of file paramsHolder.h.
References exists().
{ var = !exists( key ) ? defaultValue : operator[]( key ); }
void Parameters::get | ( | const std::string & | key, |
bool & | var, | ||
const bool | defaultValue | ||
) | [inline] |
Definition at line 77 of file paramsHolder.h.
References exists().
{ var = !exists( key ) ? defaultValue : std::atoi( operator[]( key ).c_str() ) != 0; }
std::string Parameters::get | ( | const std::string & | key, |
Int & | var, | ||
const Int | defaultValue, | ||
std::map< std::string, int > & | enumMap | ||
) | [inline] |
Definition at line 83 of file paramsHolder.h.
References exists().
{ if( !exists( key ) || enumMap.count( operator[]( key ) ) == 0 ) { var = defaultValue; return "(unknown)"; } std::string verboseName = operator[]( key ); var = enumMap[ verboseName ]; return verboseName; }