Nemo  2.3.46
ParamsParser Class Referenceabstract

Provides interface to read input parameters from various sources and parses them. More...

#include <paramsparser.h>

+ Inheritance diagram for ParamsParser:
+ Collaboration diagram for ParamsParser:

Public Member Functions

 ParamsParser (const char *name)
 
virtual ~ParamsParser ()
 
void setName (const char *name)
 
map< string, string > get_inputParams ()
 
map< string, vector< string > > & getParsedParameters (const char *stream_name)
 
map< string, vector< string > > & getParsedParameters ()
 
map< string, string > & getParameters (const char *stream_name)
 
map< string, string > & getParameters ()
 
virtual bool read (const char *stream)=0
 Read/parse params & args from a file or a string or an R object. More...
 
void parse ()
 Builds the _parsedParams from the _inputParams. More...
 

Static Public Member Functions

static void getBlockArgument (istream &IN, char &c, string &arg)
 
static void getArguments (string &arg_str, vector< string > &arg_vect)
 

Protected Member Functions

void reset_inputParams ()
 
void add_inputParam (string &param, const string &arg)
 

Private Attributes

const char * _sname
 Attached file of stream name. More...
 
map< string, string > _inputParams
 The whole, unparsed set of input parameters. More...
 
map< string, vector< string > > _parsedParams
 The parsed set of simulation parameters after sequential parameters have been separated. More...
 

Detailed Description

Provides interface to read input parameters from various sources and parses them.

Constructor & Destructor Documentation

ParamsParser::ParamsParser ( const char *  name)
inline
44 {_sname = name;}
const char * _sname
Attached file of stream name.
Definition: paramsparser.h:71
virtual ParamsParser::~ParamsParser ( )
inlinevirtual
45 {}

Member Function Documentation

void ParamsParser::add_inputParam ( string &  param,
const string &  arg 
)
inlineprotected

Referenced by StreamParser::read().

67 {_inputParams[param] = arg;}
map< string, string > _inputParams
The whole, unparsed set of input parameters.
Definition: paramsparser.h:73
map< string, string > ParamsParser::get_inputParams ( )
inline
49 {return _inputParams;}
map< string, string > _inputParams
The whole, unparsed set of input parameters.
Definition: paramsparser.h:73
void ParamsParser::getArguments ( string &  arg_str,
vector< string > &  arg_vect 
)
static

References StreamParser::removeSpaceAndComment().

127 {
128  istringstream IN;
129  string arg;
130  int dummy_line = 0;
131  char c;
132 
133  IN.str(arg_str);
134 
135  while(IN.get(c) && IN.good() && !IN.eof()){
136 
137  if(isspace(c)) {
138  StreamParser::removeSpaceAndComment(IN, dummy_line);
139  continue;
140  }
141 
142  if(c == '{' || c == '(' || c == '['){
143  getBlockArgument(IN, c, arg);
144  arg_vect.push_back( arg );
145  }
146  else {
147  IN.putback(c);
148  IN>>arg;
149  arg_vect.push_back(arg);
150  }
151  }
152 }
static bool removeSpaceAndComment(istream &IN, int &l_count, bool keepLast=false)
Removes whitespace char on a line until a non-ws or EOL is reached.
Definition: paramsparser.cc:278
static void getBlockArgument(istream &IN, char &c, string &arg)
Definition: paramsparser.cc:156
void ParamsParser::getBlockArgument ( istream &  IN,
char &  c,
string &  arg 
)
static

References StreamParser::readUntilCharacter().

157 {
158  char e = 0;
159  int dummy_line = 0;
160 
161  switch (start_c) {
162  case '{': e = '}';
163  break;
164  case '(': e = ')';
165  break;
166  case '[': e = ']';
167  break;
168  default:
169  break;
170  }
171 
172  arg = StreamParser::readUntilCharacter(IN, dummy_line, start_c, (const char)e);
173 
174 // cout<<"added arg to vector: "<<out<<" next char='"<<IN.peek()<<"'\n";
175 }
static string readUntilCharacter(istream &IN, int &l_count, char &start_c, const char end_c)
Definition: paramsparser.cc:438
map< string, string > & ParamsParser::getParameters ( const char *  stream_name)

References fatal().

Referenced by BinaryDataLoader::extractPop().

47 {
48 #ifdef _DEBUG_
49  cout<<"ParamsParser::getParameters:"<<endl;
50 #endif
51  if(stream_name == NULL) {
52  if(_sname == NULL)
53  fatal("ParamsParser::getParameters::no stream attached to the parser!\n");
54  else if( !(read(_sname)) )
55  fatal("ParamsParser::getParameters::failed from file \"%s\"\n",_sname);
56  } else if( !(read(stream_name)) )
57  fatal("ParamsParser::getParameters::failed from file \"%s\"\n",stream_name);
58 
59  if(stream_name != NULL) _sname = stream_name;
60 
61  return _inputParams;
62 }
const char * _sname
Attached file of stream name.
Definition: paramsparser.h:71
map< string, string > _inputParams
The whole, unparsed set of input parameters.
Definition: paramsparser.h:73
void fatal(const char *str,...)
Definition: output.cc:90
virtual bool read(const char *stream)=0
Read/parse params & args from a file or a string or an R object.
map< string, string >& ParamsParser::getParameters ( )
inline
53 {return _inputParams;}
map< string, string > _inputParams
The whole, unparsed set of input parameters.
Definition: paramsparser.h:73
map< string, vector< string > > & ParamsParser::getParsedParameters ( const char *  stream_name)

Referenced by SimRunner::run().

67 {
68 #ifdef _DEBUG_
69  cout<<"ParamsParser::getParsedParameters:"<<endl;
70 #endif
71  getParameters(stream_name);
72 
73  parse();
74 
75  return _parsedParams;
76 }
map< string, vector< string > > _parsedParams
The parsed set of simulation parameters after sequential parameters have been separated.
Definition: paramsparser.h:75
map< string, string > & getParameters()
Definition: paramsparser.h:53
void parse()
Builds the _parsedParams from the _inputParams.
Definition: paramsparser.cc:80
map< string, vector< string > >& ParamsParser::getParsedParameters ( )
inline
51 {return _parsedParams;}
map< string, vector< string > > _parsedParams
The parsed set of simulation parameters after sequential parameters have been separated.
Definition: paramsparser.h:75
void ParamsParser::parse ( )

Builds the _parsedParams from the _inputParams.

This defines rules of sequential, matricial params, etc.

References message().

81 {
82 #ifdef _DEBUG_
83  cout<<"ParamsParser::parse:"<<endl;
84 #endif
85  _parsedParams.clear();
86 
87  vector< string > argvect;
88  string arg;
89 
90  map<string, string>::iterator param = _inputParams.begin();
91 
92  while(param != _inputParams.end()) {
93 
94  argvect.clear();
95 
96  if((param->first == "stats") || (param->first == "stat") )
97 
98  argvect.push_back(param->second); //this one cannot be a sequential parameter
99 
100  else { //other params:
101 
102  getArguments(param->second, argvect);
103 
104  }
105 
106  _parsedParams[param->first] = argvect;
107 
108 #ifdef _DEBUG_
109  message(" %s (", param->first.c_str());
110  unsigned int nb=argvect.size() ;
111  for(unsigned int i=0 ;i<nb; ++i){
112  cout<<argvect[i]<<" ";
113  }
114  message("| %i args)\n", nb);
115 #endif
116 
117  param++;
118  }
119 
120  //scanForModifiers();
121 }
map< string, vector< string > > _parsedParams
The parsed set of simulation parameters after sequential parameters have been separated.
Definition: paramsparser.h:75
void message(const char *message,...)
Definition: output.cc:40
map< string, string > _inputParams
The whole, unparsed set of input parameters.
Definition: paramsparser.h:73
static void getArguments(string &arg_str, vector< string > &arg_vect)
Definition: paramsparser.cc:126
virtual bool ParamsParser::read ( const char *  stream)
pure virtual

Read/parse params & args from a file or a string or an R object.

Params and their args are put in the _inputParams.

Implemented in StreamParser, BinaryFileParser, and FileParser.

void ParamsParser::reset_inputParams ( )
inlineprotected

Referenced by StreamParser::read().

66 {_inputParams.clear();}
map< string, string > _inputParams
The whole, unparsed set of input parameters.
Definition: paramsparser.h:73
void ParamsParser::setName ( const char *  name)
inline

Referenced by BinaryDataLoader::extractPop().

47 {_sname = name;}
const char * _sname
Attached file of stream name.
Definition: paramsparser.h:71

Member Data Documentation

map< string, string > ParamsParser::_inputParams
private

The whole, unparsed set of input parameters.

map< string, vector< string > > ParamsParser::_parsedParams
private

The parsed set of simulation parameters after sequential parameters have been separated.

const char* ParamsParser::_sname
private

Attached file of stream name.


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

Generated for Nemo v2.3.0 by  doxygen 1.8.8 --
Catalogued on GSR