Nemo  2.3.46
Param Class Reference

This structure stores one parameter, its definition and its string argument. More...

#include <param.h>

+ Collaboration diagram for Param:

Public Member Functions

 Param (string &Name, param_t Type, bool mandatory, bool bounded, double low_bnd, double up_bnd, SimComponent *owner, ParamUpdaterBase *updater)
 Constructor. More...
 
 Param (const Param &P)
 Copy cstor, provides shallow copy of the parameter definition, do not copy arguments. More...
 
virtual ~Param ()
 
void reset ()
 Clears the _isSet flag and the argument string. More...
 
void setName (string value)
 Sets the parameter's name. More...
 
void setArg (string value)
 Sets the parameter's argument. More...
 
void setType (param_t value)
 Sets the parameter's type (see types.h) More...
 
void setIsSet (bool value)
 Sets the _isSet flag. More...
 
void setIsBounded (bool value)
 Sets the _isBounded flag. More...
 
void setBounds (double low_bnd, double up_bnd)
 Sets the bounds. More...
 
void setOwner (SimComponent *owner)
 Sets the pointer to owner. More...
 
void setUpdater (ParamUpdaterBase *updater)
 Sets the pointer to the updater object. More...
 
void setAtGeneration (unsigned int generation)
 
string getName ()
 
string getArg ()
 
param_t getType ()
 
bool isSet ()
 
bool isBounded ()
 
bool isRequired ()
 
bool isTemporal ()
 
bool hasMultipleArgs ()
 
bool hasExternalFile ()
 
double getBound (unsigned int i)
 
SimComponentgetOwner ()
 
ParamUpdaterBasegetUpdater ()
 
deque< unsigned intgetUpdatingDates ()
 
deque< string > getTemporalArgs ()
 
vector< string > getMultiArgs ()
 
vector< string > getExternalFiles ()
 
bool set (string arg, string &errmsg)
 Sets the _isSet flag to true and _arg to arg if the arg is of the right type and whithin the bounds. More...
 
bool update (unsigned int generation)
 Updates the parameter value at a given generation during the simulation. More...
 
double getValue ()
 Returns the argument value according to its type. More...
 
bool isMatrix ()
 Checks if the argument is of matrix type. More...
 
void getMatrix (TMatrix *mat)
 Sets the matrix from the argument string if the parameter is set and of matrix type. More...
 
void getVariableMatrix (vector< vector< double > > *mat)
 
void parse_matrix (TMatrix *mat)
 Parses the matrix from the argument string. More...
 
void parse_variable_matrix (vector< vector< double > > *mat)
 
bool parseArgument (string &arg)
 
bool parseTemporalArgument (const string &arg)
 
bool parseAgeSpecArgument (const string &arg)
 
bool parseSubParamArgument (const string &arg)
 
string checkArgumentForExpansion (string arg)
 
string getArgumentFromFile (string file)
 
void show_up ()
 Print state to stdout. More...
 

Private Attributes

string _name
 The name of the parameter as read in the init file. More...
 
string _arg
 The argument string, set by the ParamsParser upon initialization. More...
 
string _input_arg
 The input argument string, kept untouched as a backup for logging. More...
 
param_t _type
 The type of the argument, must one of DBL, INT, BOOL, STR or MAT (see types.h). More...
 
bool _isSet
 Flag set once the parameter has recieved the right argument. More...
 
bool _isBounded
 Flag telling if the parameter has a bounded argument value. More...
 
bool _isRequired
 Flag telling if this parameter is mandatory. More...
 
double _bounds [2]
 The argument value boundaries. More...
 
unsigned int _setAtGeneration
 Generation at which the parameter has been set/updated. More...
 
SimComponent_myOwner
 Pointer to the component that declared this parameter. More...
 
ParamUpdaterBase_myUpdater
 Pointer to an ParamUpdater object. More...
 
vector< string > _externalFile
 External argument file. More...
 
bool _hasExternalFile
 
map< unsigned int, string > _temporalArgs
 The temporal arguments. More...
 
bool _isTemporal
 Flag telling if this parameter has temporal arguments. More...
 
vector< string > _multiArgs
 Multiple arguments. More...
 
bool _hasMultipleArgs
 

Detailed Description

This structure stores one parameter, its definition and its string argument.

Parameters are aggregated into a ParamSet.

Constructor & Destructor Documentation

Param::Param ( string &  Name,
param_t  Type,
bool  mandatory,
bool  bounded,
double  low_bnd,
double  up_bnd,
SimComponent owner,
ParamUpdaterBase updater 
)

Constructor.

Parameters
Namethe name of the parameter as read in the init file
Typethe type of the parameter argument (see types.h), used to convert the argument string into a value
mandatoryspecifies whether this parameter is mandatory for the ParamSet owning it
boundedspecifies whether the values this parameter can take are bounded
low_bndthe lower bound of the parameter value
up_bndthe upper bound
ownerpointer to the SimComponents that owns this parameter
updaterthe param updater object used to update the parameter's state during a simulation

References _bounds.

44 : _name(Name),_arg(""),_type(Type),_isSet(0),_isBounded(bounded),_isRequired(mandatory),
47 
48 {
49  _bounds[0] = low_bnd;
50  _bounds[1] = up_bnd;
51 }
unsigned int _setAtGeneration
Generation at which the parameter has been set/updated.
Definition: param.h:73
bool _isTemporal
Flag telling if this parameter has temporal arguments.
Definition: param.h:86
bool _hasMultipleArgs
Definition: param.h:90
string _arg
The argument string, set by the ParamsParser upon initialization.
Definition: param.h:58
bool _isRequired
Flag telling if this parameter is mandatory.
Definition: param.h:69
SimComponent * _myOwner
Pointer to the component that declared this parameter.
Definition: param.h:75
bool _isBounded
Flag telling if the parameter has a bounded argument value.
Definition: param.h:66
ParamUpdaterBase * _myUpdater
Pointer to an ParamUpdater object.
Definition: param.h:77
bool _isSet
Flag set once the parameter has recieved the right argument.
Definition: param.h:64
bool _hasExternalFile
Definition: param.h:81
string _name
The name of the parameter as read in the init file.
Definition: param.h:56
param_t _type
The type of the argument, must one of DBL, INT, BOOL, STR or MAT (see types.h).
Definition: param.h:62
double _bounds[2]
The argument value boundaries.
Definition: param.h:71
Param::Param ( const Param P)

Copy cstor, provides shallow copy of the parameter definition, do not copy arguments.

References _bounds.

59 {
60  _bounds[0] = P._bounds[0];
61  _bounds[1] = P._bounds[1];
62 }
unsigned int _setAtGeneration
Generation at which the parameter has been set/updated.
Definition: param.h:73
bool _hasMultipleArgs
Definition: param.h:90
string _arg
The argument string, set by the ParamsParser upon initialization.
Definition: param.h:58
bool _isRequired
Flag telling if this parameter is mandatory.
Definition: param.h:69
SimComponent * _myOwner
Pointer to the component that declared this parameter.
Definition: param.h:75
bool _isBounded
Flag telling if the parameter has a bounded argument value.
Definition: param.h:66
ParamUpdaterBase * _myUpdater
Pointer to an ParamUpdater object.
Definition: param.h:77
bool _isSet
Flag set once the parameter has recieved the right argument.
Definition: param.h:64
bool _hasExternalFile
Definition: param.h:81
string _name
The name of the parameter as read in the init file.
Definition: param.h:56
param_t _type
The type of the argument, must one of DBL, INT, BOOL, STR or MAT (see types.h).
Definition: param.h:62
double _bounds[2]
The argument value boundaries.
Definition: param.h:71
Param::~Param ( )
virtual

References _myUpdater.

67 {
68  if(_myUpdater) delete _myUpdater;
69 }
ParamUpdaterBase * _myUpdater
Pointer to an ParamUpdater object.
Definition: param.h:77

Member Function Documentation

string Param::checkArgumentForExpansion ( string  arg)

References getArgumentFromFile().

Referenced by parseArgument(), parseTemporalArgument(), and set().

286 {
287  string expanded;
288 
289  if (arg[0] == '&') { //this is the char indicating an external argument file
290  expanded = getArgumentFromFile(arg);
291  } else
292  expanded = arg;
293 
294  return expanded;
295 }
string getArgumentFromFile(string file)
Definition: param.cc:299
string Param::getArgumentFromFile ( string  file)

References _externalFile, _hasExternalFile, fatal(), StreamParser::readArguments(), and tstring::removeFirstCharOf().

Referenced by checkArgumentForExpansion().

300 {
301  StreamParser Parser(tstring::removeFirstCharOf(file, '&').c_str());
302  int dummyCnt;
303  string arg;
304 
305  ifstream EXT(tstring::removeFirstCharOf(file, '&').c_str());
306  if(!EXT) fatal("External parameter file '%s' could not be found!\n", file.c_str());
307  while(Parser.readArguments(EXT, dummyCnt, arg));
308  EXT.close();
309 
310  //add the external file name to the list
311  _externalFile.push_back(file);
312  _hasExternalFile = true;
313 
314  return arg;
315 }
Read parameters from a text buffer.
Definition: paramsparser.h:80
void fatal(const char *str,...)
Definition: output.cc:90
vector< string > _externalFile
External argument file.
Definition: param.h:80
static string removeFirstCharOf(const string &str, const char c)
Removes the first of a character found in a string.
Definition: tstring.h:319
bool _hasExternalFile
Definition: param.h:81
double Param::getBound ( unsigned int  i)
inline
144 {return _bounds[i];}
double _bounds[2]
The argument value boundaries.
Definition: param.h:71
vector< string > Param::getExternalFiles ( )
inline
154 {return _externalFile;}
vector< string > _externalFile
External argument file.
Definition: param.h:80
void Param::getMatrix ( TMatrix mat)

Sets the matrix from the argument string if the parameter is set and of matrix type.

Passes the param 'mat' to function Param::parse_matrix.

Parameters
mata TMatrix ptr, mat dimensions and values will be reset to the values read in the init file.

References _isSet, _name, isMatrix(), parse_matrix(), and warning().

Referenced by TProtoBDMI::loadFileServices(), TProtoQuanti::loadFileServices(), TProtoNeutralGenes::loadFileServices(), TProtoDeletMutations_bitstring::loadFileServices(), Metapop::loadFileServices(), LCE_Selection_base::loadFileServices(), LCE_Patch_Extinction::set_matrix_param(), LCE_Selection_base::set_param_rate_of_change(), LCE_Selection_base::set_sel_model(), LCE_Selection_base::set_std_rate_of_change(), TProtoQuanti::setContinuousMutationModel(), TProtoQuanti::setDiallelicMutationModel(), LCE_Breed_base::setFecundity(), TTProtoWithMap::setGeneticMapParameters(), TTProtoWithMap::setNumLociPerChromosome(), LCE_StatServiceNotifier::setOccurence(), TProtoBDMI::setParameters(), TProtoQuanti::setParameters(), and LCE_Breed_Wolbachia::setParameters().

330 {
331  if( isMatrix() && _isSet ){
332 
333  parse_matrix(mat);
334 
335  } else
336  warning("param \"%s\" is not a matrix!\n",_name.c_str());
337 }
bool isMatrix()
Checks if the argument is of matrix type.
Definition: param.h:170
void parse_matrix(TMatrix *mat)
Parses the matrix from the argument string.
Definition: param.cc:342
void warning(const char *str,...)
Definition: output.cc:56
bool _isSet
Flag set once the parameter has recieved the right argument.
Definition: param.h:64
string _name
The name of the parameter as read in the init file.
Definition: param.h:56
vector< string > Param::getMultiArgs ( )

References _arg, _hasMultipleArgs, and _multiArgs.

Referenced by LCE_Selection_base::set_sel_model(), and LCE_Selection_base::setParameters().

111 {
112  if (!_hasMultipleArgs) {
113  _multiArgs.clear();
114  _multiArgs.push_back(_arg);
115  }
116  return _multiArgs;
117 }
vector< string > _multiArgs
Multiple arguments.
Definition: param.h:89
bool _hasMultipleArgs
Definition: param.h:90
string _arg
The argument string, set by the ParamsParser upon initialization.
Definition: param.h:58
string Param::getName ( )
inline

Referenced by ParamSet::add_param(), and ParamSet::print().

135 {return _name;}
string _name
The name of the parameter as read in the init file.
Definition: param.h:56
SimComponent* Param::getOwner ( )
inline
145 {return _myOwner;}
SimComponent * _myOwner
Pointer to the component that declared this parameter.
Definition: param.h:75
deque< string > Param::getTemporalArgs ( )

References _temporalArgs.

Referenced by LCE_StatServiceNotifier::setOccurence().

98 {
99  deque< string > args;
100 
101  for(map< unsigned int, string >::iterator tmp_it = _temporalArgs.begin();
102  tmp_it != _temporalArgs.end(); tmp_it++)
103  args.push_back( tmp_it->second );
104 
105  return args;
106 }
map< unsigned int, string > _temporalArgs
The temporal arguments.
Definition: param.h:84
param_t Param::getType ( )
inline
137 {return _type;}
param_t _type
The type of the argument, must one of DBL, INT, BOOL, STR or MAT (see types.h).
Definition: param.h:62
ParamUpdaterBase* Param::getUpdater ( )
inline
146 {return _myUpdater;}
ParamUpdaterBase * _myUpdater
Pointer to an ParamUpdater object.
Definition: param.h:77
deque< unsigned int > Param::getUpdatingDates ( )

References _temporalArgs.

Referenced by LCE_StatServiceNotifier::setOccurence().

85 {
86  deque< unsigned int > dates;
87 
88  for(map< unsigned int, string >::iterator tmp_it = _temporalArgs.begin();
89  tmp_it != _temporalArgs.end(); tmp_it++)
90  dates.push_back( tmp_it->first );
91 
92  return dates;
93 }
map< unsigned int, string > _temporalArgs
The temporal arguments.
Definition: param.h:84
double Param::getValue ( )

Returns the argument value according to its type.

Returns
-1 if the parameter is not set or not of a the right type

References _arg, _isSet, _type, isMatrix(), and STR.

Referenced by TProtoBDMI::loadFileServices(), TProtoQuanti::loadFileServices(), TProtoNeutralGenes::loadFileServices(), TProtoDeletMutations_bitstring::loadFileServices(), Metapop::loadFileServices(), LCE_Selection_base::loadFileServices(), LCE_Patch_Extinction::set_matrix_param(), and LCE_StatServiceNotifier::setOccurence().

320 {
321  if( !(isMatrix() || _type == STR) && _isSet)
322  return atof(_arg.c_str());
323  else
324  return -1.0;
325 }
bool isMatrix()
Checks if the argument is of matrix type.
Definition: param.h:170
string _arg
The argument string, set by the ParamsParser upon initialization.
Definition: param.h:58
bool _isSet
Flag set once the parameter has recieved the right argument.
Definition: param.h:64
param_t _type
The type of the argument, must one of DBL, INT, BOOL, STR or MAT (see types.h).
Definition: param.h:62
Definition: types.h:78
void Param::getVariableMatrix ( vector< vector< double > > *  mat)

References _isSet, _name, isMatrix(), parse_variable_matrix(), and warning().

Referenced by LCE_Disperse_base::setBaseParameters(), and TTProtoWithMap::setGeneticMapParameters().

412 {
413  if( isMatrix() && _isSet ){
414 
416 
417  } else
418  warning("param \"%s\" is not a (variable) matrix!\n",_name.c_str());
419 }
bool isMatrix()
Checks if the argument is of matrix type.
Definition: param.h:170
void warning(const char *str,...)
Definition: output.cc:56
void parse_variable_matrix(vector< vector< double > > *mat)
Definition: param.cc:423
bool _isSet
Flag set once the parameter has recieved the right argument.
Definition: param.h:64
string _name
The name of the parameter as read in the init file.
Definition: param.h:56
bool Param::hasExternalFile ( )
inline
143 {return _hasExternalFile;}
bool _hasExternalFile
Definition: param.h:81
bool Param::hasMultipleArgs ( )
inline
142 {return _hasMultipleArgs;}
bool _hasMultipleArgs
Definition: param.h:90
bool Param::isBounded ( )
inline
139 {return _isBounded;}
bool _isBounded
Flag telling if the parameter has a bounded argument value.
Definition: param.h:66
bool Param::isMatrix ( )
inline

Checks if the argument is of matrix type.

References MAT.

Referenced by getMatrix(), getValue(), getVariableMatrix(), TProtoBDMI::loadFileServices(), TProtoQuanti::loadFileServices(), TProtoNeutralGenes::loadFileServices(), TProtoDeletMutations_bitstring::loadFileServices(), Metapop::loadFileServices(), LCE_Selection_base::loadFileServices(), LCE_Patch_Extinction::set_matrix_param(), LCE_Selection_base::set_std_rate_of_change(), LCE_StatServiceNotifier::setOccurence(), and LCE_QuantiInit::setParameters().

171  { return (_type == MAT || (_arg.size() != 0 ? _arg[0] == '{' : false) ); }
Definition: types.h:78
string _arg
The argument string, set by the ParamsParser upon initialization.
Definition: param.h:58
param_t _type
The type of the argument, must one of DBL, INT, BOOL, STR or MAT (see types.h).
Definition: param.h:62
bool Param::isRequired ( )
inline
140 {return _isRequired;}
bool _isRequired
Flag telling if this parameter is mandatory.
Definition: param.h:69
bool Param::isTemporal ( )
inline

Referenced by LCE_StatServiceNotifier::setOccurence().

141 {return _isTemporal;}
bool _isTemporal
Flag telling if this parameter has temporal arguments.
Definition: param.h:86
void Param::parse_matrix ( TMatrix mat)

Parses the matrix from the argument string.

Parameters
mata TMatrix ptr, mat dimensions and values will be reset to the values read in the init file.

References _arg, _name, fatal(), TMatrix::reset(), and TMatrix::set().

Referenced by getMatrix().

343 {
344  std::vector< std::vector<double> > tmpMat;
345  std::istringstream IN;
346 
347  IN.str(_arg);
348 
349  unsigned int cols = 0;
350  double elmnt;
351  char c;
352 
353 
354  int rows = -1, pos = -1;
355  //we count the number of rows
356  do {
357  pos = _arg.find("{", pos + 1);
358  //message("pos %i, arg %s\n",pos,_arg.c_str());
359  rows++;
360  }while(pos != (int)string::npos);
361  //decrement by 1, the first doesn't count for a row
362  rows--;
363 
364  for(int i = 0; i < rows; i++)
365  tmpMat.push_back( vector<double>() );
366 
367  //remove the first enclosing bracket
368  IN>>c;
369  //then read the rows
370  for(unsigned int i = 0; i < tmpMat.size(); i++) {
371 
372  cols = 0;
373 
374  //read a row enclosed by {...}:
375  while(IN) {
376 
377  //first character:
378  IN>>c;
379 
380  if(c == '{' || c == ',' || c == ';') {
381  //read a row element:
382  IN>>elmnt;
383  cols++;
384  tmpMat[i].push_back(elmnt);
385 
386  } else if(c == '}')
387  //go to next row
388  break;
389 
390  }
391  }
392  //check for matrix coherence:
393  for(unsigned int i = 0; i < tmpMat.size(); i++) {
394  if(tmpMat[i].size() != cols)
395  fatal("%s: not same number of elements in all rows of matrix! (%i, cols %i)\n",_name.c_str(),tmpMat[i].size(),cols);
396  cols = tmpMat[i].size();
397  }
398 
399  //copy to input TMatrix:
400  mat->reset(rows, cols);
401  for(int i = 0; i < rows; ++i)
402  for(unsigned int j = 0; j < cols; ++j)
403  mat->set(i,j,tmpMat[i][j]);
404 
405 
406  tmpMat.clear();
407 }
void fatal(const char *str,...)
Definition: output.cc:90
string _arg
The argument string, set by the ParamsParser upon initialization.
Definition: param.h:58
void set(unsigned int i, unsigned int j, double val)
Sets element at row i and column j to value val.
Definition: tmatrix.h:85
void reset(unsigned int rows, unsigned int cols)
Re-allocate the existing matrix with assigned rows and cols dimensions.
Definition: tmatrix.h:97
string _name
The name of the parameter as read in the init file.
Definition: param.h:56
void Param::parse_variable_matrix ( vector< vector< double > > *  mat)

References _arg.

Referenced by getVariableMatrix().

424 {
425  // std::vector< std::vector<double> > tmpMat;
426  std::istringstream IN;
427 
428  IN.str(_arg);
429 
430  double elmnt;
431  char c;
432 
433  //purge the input matrix:
434  mat->clear();
435 
436  int rows = -1, pos = -1;
437  //we count the number of rows
438  do {
439  pos = _arg.find("{", pos + 1);
440  //message("pos %i, arg %s\n",pos,_arg.c_str());
441  rows++;
442  }while(pos != (int)string::npos);
443  //decrement by 1, the first doesn't count for a row
444  rows--;
445 
446  for(int i = 0; i < rows; i++)
447  mat->push_back( vector<double>() );
448 
449  //remove the first enclosing bracket
450  IN>>c;
451  //then read the rows
452  for(unsigned int i = 0; i < mat->size(); i++) {
453 
454  //read a row enclosed by {...}:
455  while(IN) {
456 
457  //first character:
458  IN>>c;
459 
460  if(c == '{' || c == ',' || c == ';') {
461  //read a row element:
462  IN>>elmnt;
463  (*mat)[i].push_back(elmnt);
464 
465  } else if(c == '}')
466  //go to next row
467  break;
468  }
469  }
470 }
string _arg
The argument string, set by the ParamsParser upon initialization.
Definition: param.h:58
bool Param::parseAgeSpecArgument ( const string &  arg)

Referenced by parseArgument().

272 {
273  return true;
274 }
bool Param::parseArgument ( string &  arg)

Parse an argument string enclosed in '( )', might hold temporal or multiple values.

References _hasMultipleArgs, _isTemporal, _multiArgs, _myUpdater, _name, _temporalArgs, checkArgumentForExpansion(), error(), parseAgeSpecArgument(), parseTemporalArgument(), tstring::removeEnclosingChar(), tstring::splitExcludeEnclosedDelimiters(), and warning().

Referenced by set().

187 {
189  arg = tstring::removeEnclosingChar(arg, '(', ')');
190 
191  vector< string > args = tstring::splitExcludeEnclosedDelimiters(arg);
192 
193  _temporalArgs.clear();
194  _multiArgs.clear();
195 
196 // cout<< "Param::parseArgument: " << endl;
197 
198 
199  for(unsigned int i = 0; i < args.size(); ++i) {
200 // cout << args[i] << endl;
201  if(args[i][0] == '@') {
202  if(args[i][1] == 'g') {if(!parseTemporalArgument(args[i])) return false;}
203  else if(args[i][1] == 'a') {if(!parseAgeSpecArgument(args[i])) return false;}
204  else {
205  error("parameter \"%s\" has unrecognized specifier in its argument string \"%s\".\n", _name.c_str(), args[i].c_str());
206  return false;
207  }
208  } else { // (arg1, arg2, arg3, ...)
209  //values might still be in external files
210  _multiArgs.push_back( checkArgumentForExpansion(args[i]) );
211  }
212  }
213 
214  if(_multiArgs.size() != 0) _hasMultipleArgs = true;
215  else _hasMultipleArgs = false;
216 
217  if(_temporalArgs.size() != 0) {
218 
219  //cout << "temporal arg values:\n";
220  // for(map< unsigned int , string >::iterator iter = _temporalArgs.begin();
221  // iter != _temporalArgs.end();
222  // iter++)
223  // cout << iter->first <<" "<< iter->second << endl;
224 
225  if(_myUpdater != 0) {
226 
227  if(_temporalArgs.find(0) != _temporalArgs.end()) {
228  _isTemporal = true;
229  //set the value for the first generation
230  arg = _temporalArgs.find(0)->second;
231  }
232  else {
233  error("first generation argument value for temporal parameter \"%s\" is missing; no \"@g0\".\n", _name.c_str());
234  return false;
235  }
236 
237  } else {
238  warning("trying to pass a temporal argument to a non temporal parameter (\"%s\").\n", _name.c_str());
239  _isTemporal = false;
240  _temporalArgs.clear();
241  }
242 
243  } else _isTemporal = false;
244 
245 
246  return true;
247 }
bool parseAgeSpecArgument(const string &arg)
Definition: param.cc:271
bool _isTemporal
Flag telling if this parameter has temporal arguments.
Definition: param.h:86
vector< string > _multiArgs
Multiple arguments.
Definition: param.h:89
bool _hasMultipleArgs
Definition: param.h:90
string checkArgumentForExpansion(string arg)
Definition: param.cc:285
int error(const char *str,...)
Definition: output.cc:73
bool parseTemporalArgument(const string &arg)
Definition: param.cc:251
void warning(const char *str,...)
Definition: output.cc:56
static string removeEnclosingChar(const string &str, const char o, const char c, bool allowMissing=false)
Removes characters enclosing a string.
Definition: tstring.h:352
map< unsigned int, string > _temporalArgs
The temporal arguments.
Definition: param.h:84
ParamUpdaterBase * _myUpdater
Pointer to an ParamUpdater object.
Definition: param.h:77
static vector< string > splitExcludeEnclosedDelimiters(const string &str, const char delim= ',', const string &encloser="([{\"")
Splits a string into substrings (tokens) delimited by a single character.
Definition: tstring.h:155
string _name
The name of the parameter as read in the init file.
Definition: param.h:56
bool Param::parseSubParamArgument ( const string &  arg)
279 {
280  return true;
281 }
bool Param::parseTemporalArgument ( const string &  arg)

References _name, _temporalArgs, checkArgumentForExpansion(), error(), tstring::removeFirstCharOf(), tstring::split(), and tstring::str2uint().

Referenced by parseArgument().

252 {
253  vector< string > args = tstring::split(arg, ' ', true);
254 
255  if(args.size() != 2) {
256  error("Param::parseTemporalArgument:: missing argument value in \"%s %s\".\n", _name.c_str(), arg.c_str());
257  return false;
258  }
259 
260  unsigned int gen = tstring::str2uint(tstring::removeFirstCharOf(tstring::removeFirstCharOf(args[0], '@'), 'g'));
261 
262  args[1] = checkArgumentForExpansion(args[1]);
263 
264  _temporalArgs[gen] = args[1]; //still need to process the argument string for replacements!!
265 
266  return true;
267 }
static unsigned int str2uint(const string &str)
Converts a string into an unsigned integer.
Definition: tstring.h:51
string checkArgumentForExpansion(string arg)
Definition: param.cc:285
int error(const char *str,...)
Definition: output.cc:73
static string removeFirstCharOf(const string &str, const char c)
Removes the first of a character found in a string.
Definition: tstring.h:319
map< unsigned int, string > _temporalArgs
The temporal arguments.
Definition: param.h:84
static vector< string > split(const string &str, const char delim, bool splitOnce=false)
splits a string into substrings (tokens) delimited by a single character.
Definition: tstring.h:128
string _name
The name of the parameter as read in the init file.
Definition: param.h:56
void Param::reset ( )

Clears the _isSet flag and the argument string.

References _arg, _externalFile, _isSet, _multiArgs, and _setAtGeneration.

74 {
75  _arg = "";
76  _isSet = 0;
77  _setAtGeneration = 0;
78  _multiArgs.clear();
79  _externalFile.clear();
80 }
unsigned int _setAtGeneration
Generation at which the parameter has been set/updated.
Definition: param.h:73
vector< string > _multiArgs
Multiple arguments.
Definition: param.h:89
string _arg
The argument string, set by the ParamsParser upon initialization.
Definition: param.h:58
vector< string > _externalFile
External argument file.
Definition: param.h:80
bool _isSet
Flag set once the parameter has recieved the right argument.
Definition: param.h:64
bool Param::set ( string  arg,
string &  errmsg 
)

Sets the _isSet flag to true and _arg to arg if the arg is of the right type and whithin the bounds.

Called at simulation setup (i.e. generation 0). For parameter update during the simulation, check the Param::update member function.

!a matrix may also be specified!! in that case, we don't check values here

References _arg, _bounds, _externalFile, _input_arg, _isBounded, _isSet, _type, BOOL, checkArgumentForExpansion(), DBL, INT, tstring::isanumber(), MAT, parseArgument(), tstring::str2dble(), and tstring::str2int().

Referenced by update().

122 {
123 // cout << "Param::set ("<<arg<<")\n";
124 
125  _input_arg = arg; //backup the input parameter argument string
126 
127  _externalFile.clear(); //ext. file names will be pushed here
128  //check if argument is in an external file, and read it from that file
129  if (arg[0] == '&') {
130  //read the argument from an external file, file name is stored within the call.
131  string expanded = checkArgumentForExpansion(arg);
132  arg = expanded;
133  }
134 
135  if( arg[0] == '(' ) {
136  if( !parseArgument( arg ) ) {
137  errmsg = "could not parse the argument string";
138  return false;
139  }
140  }
141 
142  //integer or decimal:
143  if(_type == INT || _type == DBL) {
145  if(arg[0] != '{') {
146 
147  if(!tstring::isanumber(arg)) {
148  errmsg = "argument is not a number";
149  return false;
150  }
151 
152  double val = tstring::str2dble(arg);
153 
154  if(_isBounded && (val < _bounds[0] || val > _bounds[1]) ){
155  errmsg = "argument is out of bounds";
156  return false;
157  }
158  }
159 
160  //boolean:
161  } else if(_type == BOOL) {
162 
163  if( !tstring::isanumber(arg) ){
164  errmsg = "argument is not a boolean";
165  return false;
166  }
167 
168  } else if(_type == MAT) {
169  if(arg[0] != '{'){
170  errmsg = "argument is not a matrix";
171  return false;
172  }
173  }
174  // else if(_type == P || _type == S): no conditions to check
175 
176  _isSet = (_type == BOOL && tstring::str2int(arg) == 0 ? false : true);
177 
178  //now we set the value of the parameter to the value of the argument read in the file
179  _arg = arg;
180 
181  return true;
182 }
static int str2int(const string &str)
Converts a string into an integer.
Definition: tstring.h:73
static double str2dble(const string &str)
Converts a string into a double.
Definition: tstring.h:84
static bool isanumber(const string &str)
Check whether the string is a number.
Definition: tstring.h:381
string _input_arg
The input argument string, kept untouched as a backup for logging.
Definition: param.h:60
Definition: types.h:78
string checkArgumentForExpansion(string arg)
Definition: param.cc:285
string _arg
The argument string, set by the ParamsParser upon initialization.
Definition: param.h:58
Definition: types.h:78
vector< string > _externalFile
External argument file.
Definition: param.h:80
bool _isBounded
Flag telling if the parameter has a bounded argument value.
Definition: param.h:66
Definition: types.h:78
Definition: types.h:78
bool _isSet
Flag set once the parameter has recieved the right argument.
Definition: param.h:64
param_t _type
The type of the argument, must one of DBL, INT, BOOL, STR or MAT (see types.h).
Definition: param.h:62
bool parseArgument(string &arg)
Definition: param.cc:186
double _bounds[2]
The argument value boundaries.
Definition: param.h:71
void Param::setArg ( string  value)
inline

Sets the parameter's argument.

Referenced by TTProtoWithMap::setRecombinationMapRandom().

118 {_arg = value; _input_arg = value;}
string _input_arg
The input argument string, kept untouched as a backup for logging.
Definition: param.h:60
string _arg
The argument string, set by the ParamsParser upon initialization.
Definition: param.h:58
void Param::setAtGeneration ( unsigned int  generation)
inline
132 {_setAtGeneration = generation;}
unsigned int _setAtGeneration
Generation at which the parameter has been set/updated.
Definition: param.h:73
void Param::setBounds ( double  low_bnd,
double  up_bnd 
)
inline

Sets the bounds.

126 {_bounds[0]=low_bnd; _bounds[1]=up_bnd;}
double _bounds[2]
The argument value boundaries.
Definition: param.h:71
void Param::setIsBounded ( bool  value)
inline

Sets the _isBounded flag.

124 {_isBounded = value;}
bool _isBounded
Flag telling if the parameter has a bounded argument value.
Definition: param.h:66
void Param::setIsSet ( bool  value)
inline

Sets the _isSet flag.

Referenced by TTProtoWithMap::setRecombinationMapRandom().

122 {_isSet = value;}
bool _isSet
Flag set once the parameter has recieved the right argument.
Definition: param.h:64
void Param::setName ( string  value)
inline

Sets the parameter's name.

116 {_name = value;}
string _name
The name of the parameter as read in the init file.
Definition: param.h:56
void Param::setOwner ( SimComponent owner)
inline

Sets the pointer to owner.

128 {_myOwner = owner;}
SimComponent * _myOwner
Pointer to the component that declared this parameter.
Definition: param.h:75
void Param::setType ( param_t  value)
inline

Sets the parameter's type (see types.h)

120 {_type = value;}
param_t _type
The type of the argument, must one of DBL, INT, BOOL, STR or MAT (see types.h).
Definition: param.h:62
void Param::setUpdater ( ParamUpdaterBase updater)
inline

Sets the pointer to the updater object.

130 {_myUpdater = updater;}
ParamUpdaterBase * _myUpdater
Pointer to an ParamUpdater object.
Definition: param.h:77
void Param::show_up ( )

Print state to stdout.

References _arg, _isSet, _name, _setAtGeneration, and message().

491 {
492  message("%s = %s",_name.c_str(),_arg.c_str());
493  if(_isSet)
494  message(" (set at gen %i)\n",_setAtGeneration);
495  else
496  message(" (not set)\n");
497 }
void message(const char *message,...)
Definition: output.cc:40
unsigned int _setAtGeneration
Generation at which the parameter has been set/updated.
Definition: param.h:73
string _arg
The argument string, set by the ParamsParser upon initialization.
Definition: param.h:58
bool _isSet
Flag set once the parameter has recieved the right argument.
Definition: param.h:64
string _name
The name of the parameter as read in the init file.
Definition: param.h:56
bool Param::update ( unsigned int  generation)

Updates the parameter value at a given generation during the simulation.

References _name, _temporalArgs, error(), and set().

Referenced by ParamSet::update_param().

475 {
476  string error_msg;
477  if(_temporalArgs.find( generation ) != _temporalArgs.end()) {
478  if( !set( _temporalArgs[generation], error_msg ) ){
479  error("could not set \"%s\": %s", _name.c_str(), error_msg.c_str());
480  return false;
481  } else
482  return true;
483  } else
484  error("parameter \"%s\" does not have an argument value for generation %i.\n", _name.c_str(), generation);
485  return false;
486 }
int error(const char *str,...)
Definition: output.cc:73
map< unsigned int, string > _temporalArgs
The temporal arguments.
Definition: param.h:84
bool set(string arg, string &errmsg)
Sets the _isSet flag to true and _arg to arg if the arg is of the right type and whithin the bounds...
Definition: param.cc:121
string _name
The name of the parameter as read in the init file.
Definition: param.h:56

Member Data Documentation

string Param::_arg
private

The argument string, set by the ParamsParser upon initialization.

Referenced by getMultiArgs(), getValue(), parse_matrix(), parse_variable_matrix(), reset(), set(), and show_up().

double Param::_bounds[2]
private

The argument value boundaries.

Referenced by Param(), and set().

vector< string > Param::_externalFile
private

External argument file.

Referenced by getArgumentFromFile(), reset(), and set().

bool Param::_hasExternalFile
private

Referenced by getArgumentFromFile().

bool Param::_hasMultipleArgs
private

Referenced by getMultiArgs(), and parseArgument().

string Param::_input_arg
private

The input argument string, kept untouched as a backup for logging.

Referenced by set().

bool Param::_isBounded
private

Flag telling if the parameter has a bounded argument value.

Referenced by set().

bool Param::_isRequired
private

Flag telling if this parameter is mandatory.

A SimComponent with a mandatory parameter in the 'unset' state will not be selected to be part of a running simulation component.

bool Param::_isSet
private

Flag set once the parameter has recieved the right argument.

Referenced by getMatrix(), getValue(), getVariableMatrix(), reset(), set(), and show_up().

bool Param::_isTemporal
private

Flag telling if this parameter has temporal arguments.

Referenced by parseArgument().

vector< string > Param::_multiArgs
private

Multiple arguments.

Referenced by getMultiArgs(), parseArgument(), and reset().

SimComponent* Param::_myOwner
private

Pointer to the component that declared this parameter.

ParamUpdaterBase* Param::_myUpdater
private

Pointer to an ParamUpdater object.

Referenced by parseArgument(), and ~Param().

string Param::_name
private

The name of the parameter as read in the init file.

Referenced by getMatrix(), getVariableMatrix(), parse_matrix(), parseArgument(), parseTemporalArgument(), show_up(), and update().

unsigned int Param::_setAtGeneration
private

Generation at which the parameter has been set/updated.

Referenced by reset(), and show_up().

map< unsigned int, string > Param::_temporalArgs
private
param_t Param::_type
private

The type of the argument, must one of DBL, INT, BOOL, STR or MAT (see types.h).

Referenced by getValue(), and set().


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