Nemo  2.4.0b
Simulate forward-in-time genetic evolution in a spatially explicit, individual-based stochastic simulator
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 setIsRequired (bool value)
 Sets the isRequired 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 int > getUpdatingDates ()
 
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() [1/2]

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
45 : _name(Name),_arg(""),_type(Type),_isSet(0),_isBounded(bounded),_isRequired(mandatory),
48 
49 {
50  _bounds[0] = low_bnd;
51  _bounds[1] = up_bnd;
52 }
bool _hasMultipleArgs
Definition: param.h:90
unsigned int _setAtGeneration
Generation at which the parameter has been set/updated.
Definition: param.h:73
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 _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
string _arg
The argument string, set by the ParamsParser upon initialization.
Definition: param.h:58
double _bounds[2]
The argument value boundaries.
Definition: param.h:71
ParamUpdaterBase * _myUpdater
Pointer to an ParamUpdater object.
Definition: param.h:77
bool _hasExternalFile
Definition: param.h:81
string _name
The name of the parameter as read in the init file.
Definition: param.h:56
bool _isTemporal
Flag telling if this parameter has temporal arguments.
Definition: param.h:86

References _bounds.

◆ Param() [2/2]

Param::Param ( const Param P)

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

References _bounds.

◆ ~Param()

Param::~Param ( )
virtual
68 {
69  if(_myUpdater) delete _myUpdater;
70 }

References _myUpdater.

Member Function Documentation

◆ checkArgumentForExpansion()

string Param::checkArgumentForExpansion ( string  arg)
335 {
336  string expanded;
337 
338  if (arg[0] == '&') { //this is the char indicating an external argument file
339  expanded = getArgumentFromFile(arg);
340  } else
341  expanded = arg;
342 
343  return expanded;
344 }
string getArgumentFromFile(string file)
Definition: param.cc:348

References getArgumentFromFile().

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

◆ getArg()

◆ getArgumentFromFile()

string Param::getArgumentFromFile ( string  file)
349 {
350  StreamParser Parser(tstring::removeFirstCharOf(file, '&').c_str());
351  int dummyCnt;
352  string arg;
353 
354  ifstream EXT(tstring::removeFirstCharOf(file, '&').c_str());
355  if(!EXT) fatal("External parameter file '%s' could not be found!\n", file.c_str());
356  while(Parser.readArguments(EXT, dummyCnt, arg));
357  EXT.close();
358 
359  //add the external file name to the list
360  _externalFile.push_back(file);
361  _hasExternalFile = true;
362 
363  return arg;
364 }
vector< string > _externalFile
External argument file.
Definition: param.h:80
Read parameters from a text buffer.
Definition: paramsparser.h:120
static string removeFirstCharOf(const string &str, const char c)
Removes the first of a character found in a string.
Definition: tstring.h:323
void fatal(const char *str,...)
Definition: output.cc:96

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

Referenced by checkArgumentForExpansion().

◆ getBound()

double Param::getBound ( unsigned int  i)
inline
146 {return _bounds[i];}

◆ getExternalFiles()

vector< string > Param::getExternalFiles ( )
inline
156 {return _externalFile;}

◆ getMatrix()

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.
379 {
380  if( isMatrix() && _isSet ){
381 
382  parse_matrix(mat);
383 
384  } else
385  warning("param \"%s\" is not a matrix!\n",_name.c_str());
386 }
void parse_matrix(TMatrix *mat)
Parses the matrix from the argument string.
Definition: param.cc:391
bool isMatrix()
Checks if the argument is of matrix type.
Definition: param.h:172
void warning(const char *str,...)
Definition: output.cc:58

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

Referenced by LCE_Selection_base::loadFileServices(), Metapop::loadFileServices(), LCE_FileServicesNotifier::loadFileServices(), TProtoBDMI::loadFileServices(), TProtoDeletMutations_bitstring::loadFileServices(), TProtoNeutralGenes::loadFileServices(), TProtoQuanti::loadFileServices(), LCE_PhenotypeExpression::set_g_value_matrix(), 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_full_pleio(), TProtoQuanti::setDiallelicMutationModel(), TProtoQuanti::setDominanceParameters(), TProtoDeletMutations_bitstring::setEffectsFromInput(), TProtoQuanti::setEpistasisParameters(), LCE_Breed_base::setFecundity(), TTProtoWithMap::setGeneticMapParameters(), TProtoQuanti::setHeritabilityParams(), TProtoQuanti::setInitialValuesParams(), TProtoQuanti::setMutationCorrelation(), TProtoQuanti::setMutationModel_no_pleio(), TProtoQuanti::setMutationModel_var_pleio(), TProtoQuanti::setMutationSigmaFromQuantiMutationVariance(), TProtoQuanti::setMutationSigmaFromQuantiMutationVariance_no_pleio(), TTProtoWithMap::setNumLociPerChromosome(), LCE_StatServiceNotifier::setOccurence(), LCE_QuantiModifier::setParameters(), TProtoBDMI::setParameters(), LCE_Breed_Wolbachia::setParameters(), and TProtoDispersal::setRandom().

◆ getMultiArgs()

vector< string > Param::getMultiArgs ( )
121 {
122  if (!_hasMultipleArgs) {
123  _multiArgs.clear();
124  _multiArgs.push_back(_arg);
125  }
126  return _multiArgs;
127 }
vector< string > _multiArgs
Multiple arguments.
Definition: param.h:89

References _arg, _hasMultipleArgs, and _multiArgs.

Referenced by LCE_FileServicesNotifier::loadFileServices(), LCE_Selection_base::set_sel_model(), LCE_Selection_base::setParameters(), and Metapop::setSourceParameters().

◆ getName()

◆ getOwner()

SimComponent* Param::getOwner ( )
inline
147 {return _myOwner;}

◆ getTemporalArgs()

deque< string > Param::getTemporalArgs ( )
108 {
109  deque< string > args;
110 
111  for(map< unsigned int, string >::iterator tmp_it = _temporalArgs.begin();
112  tmp_it != _temporalArgs.end(); tmp_it++)
113  args.push_back( tmp_it->second );
114 
115  return args;
116 }
map< unsigned int, string > _temporalArgs
The temporal arguments.
Definition: param.h:84

References _temporalArgs.

Referenced by LCE_StatServiceNotifier::setOccurence().

◆ getType()

param_t Param::getType ( )
inline
139 {return _type;}

◆ getUpdater()

ParamUpdaterBase* Param::getUpdater ( )
inline
148 {return _myUpdater;}

◆ getUpdatingDates()

deque< unsigned int > Param::getUpdatingDates ( )
95 {
96  deque< unsigned int > dates;
97 
98  for(map< unsigned int, string >::iterator tmp_it = _temporalArgs.begin();
99  tmp_it != _temporalArgs.end(); tmp_it++)
100  dates.push_back( tmp_it->first );
101 
102  return dates;
103 }

References _temporalArgs.

Referenced by LCE_StatServiceNotifier::setOccurence().

◆ getValue()

double Param::getValue ( )

◆ getVariableMatrix()

void Param::getVariableMatrix ( vector< vector< double > > *  mat)
461 {
462  if( isMatrix() && _isSet ){
463 
465 
466  } else
467  warning("param \"%s\" is not a (variable) matrix!\n",_name.c_str());
468 }
void parse_variable_matrix(vector< vector< double > > *mat)
Definition: param.cc:472

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

Referenced by TProtoQuanti::readMatrixFromQuantiMutationMatrix(), TTProtoWithMap::setGeneticMapParameters(), LCE_Disperse_EvolDisp::setParameters(), and LCE_Disperse_base::setReducedMatricesBySex().

◆ hasExternalFile()

bool Param::hasExternalFile ( )
inline
145 {return _hasExternalFile;}

◆ hasMultipleArgs()

bool Param::hasMultipleArgs ( )
inline
144 {return _hasMultipleArgs;}

Referenced by Metapop::setSourceParameters().

◆ isBounded()

bool Param::isBounded ( )
inline
141 {return _isBounded;}

◆ isMatrix()

◆ isRequired()

bool Param::isRequired ( )
inline
142 {return _isRequired;}

◆ isSet()

◆ isTemporal()

bool Param::isTemporal ( )
inline

◆ parse_matrix()

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.
392 {
393  std::vector< std::vector<double> > tmpMat;
394  std::istringstream IN;
395 
396  IN.str(_arg);
397 
398  unsigned int cols = 0;
399  double elmnt;
400  char c;
401 
402 
403  int rows = -1, pos = -1;
404  //we count the number of rows
405  do {
406  pos = _arg.find("{", pos + 1);
407  //message("pos %i, arg %s\n",pos,_arg.c_str());
408  rows++;
409  }while(pos != (int)string::npos);
410  //decrement by 1, the first doesn't count for a row
411  rows--;
412 
413  for(int i = 0; i < rows; i++)
414  tmpMat.push_back( vector<double>() );
415 
416  //remove the first enclosing bracket
417  IN>>c;
418  //then read the rows
419  for(unsigned int i = 0; i < tmpMat.size(); i++) {
420 
421  cols = 0;
422 
423  //read a row enclosed by {...}:
424  while(IN) {
425 
426  //first character:
427  IN>>c;
428 
429  if(c == '{' || c == ',' || c == ';') {
430  //read a row element:
431  IN>>elmnt;
432  cols++;
433  tmpMat[i].push_back(elmnt);
434 
435  } else if(c == '}')
436  //go to next row
437  break;
438 
439  }
440  }
441  //check for matrix coherence:
442  for(unsigned int i = 0; i < tmpMat.size(); i++) {
443  if(tmpMat[i].size() != cols)
444  fatal("%s: not same number of elements in all rows of matrix! (%i, cols %i)\n",_name.c_str(),tmpMat[i].size(),cols);
445  cols = tmpMat[i].size();
446  }
447 
448  //copy to input TMatrix:
449  mat->reset(rows, cols);
450  for(int i = 0; i < rows; ++i)
451  for(unsigned int j = 0; j < cols; ++j)
452  mat->set(i,j,tmpMat[i][j]);
453 
454 
455  tmpMat.clear();
456 }
void reset(unsigned int rows, unsigned int cols)
Re-allocate the existing matrix with assigned rows and cols dimensions and all elements to 0.
Definition: tmatrix.h:161
void set(unsigned int i, unsigned int j, double val)
Sets element at row i and column j to value val.
Definition: tmatrix.h:103

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

Referenced by getMatrix().

◆ parse_variable_matrix()

void Param::parse_variable_matrix ( vector< vector< double > > *  mat)
473 {
474  // std::vector< std::vector<double> > tmpMat;
475  std::istringstream IN;
476 
477  IN.str(_arg);
478 
479  double elmnt;
480  char c;
481 
482  //purge the input matrix:
483  mat->clear();
484 
485  int rows = -1, pos = -1;
486  //we count the number of rows
487  do {
488  pos = _arg.find("{", pos + 1);
489  //message("pos %i, arg %s\n",pos,_arg.c_str());
490  rows++;
491  }while(pos != (int)string::npos);
492  //decrement by 1, the first doesn't count for a row
493  rows--;
494 
495  for(int i = 0; i < rows; i++)
496  mat->push_back( vector<double>() );
497 
498  //remove the first enclosing bracket
499  IN>>c;
500  //then read the rows
501  for(unsigned int i = 0; i < mat->size(); i++) {
502 
503  //read a row enclosed by {...}:
504  while(IN) {
505 
506  //first character:
507  IN>>c;
508 
509  if(c == '{' || c == ',' || c == ';') {
510  //read a row element:
511  IN>>elmnt;
512  (*mat)[i].push_back(elmnt);
513 
514  } else if(c == '}')
515  //go to next row
516  break;
517  }
518  }
519 }

References _arg.

Referenced by getVariableMatrix().

◆ parseAgeSpecArgument()

bool Param::parseAgeSpecArgument ( const string &  arg)
321 {
322  return true;
323 }

Referenced by parseArgument().

◆ parseArgument()

bool Param::parseArgument ( string &  arg)

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

206 {
208  // do some string clean-up:
209  arg = tstring::replaceChar(arg, '\t', ' ');
210  arg = tstring::replaceChar(arg, '\n', ' ');
211  // remove the enclosing parentheses:
212  arg = tstring::removeEnclosingChar(arg, '(', ')');
213 
214  vector< string > args = tstring::splitExcludeEnclosedDelimiters(arg); //split with default delimiter = ','
215 
216  _temporalArgs.clear();
217  _multiArgs.clear();
218 
219 // cout<< "Param::parseArgument: " << endl;
220 //
221 // cout<<" argument string: "<<arg<<endl;
222 
223  for(unsigned int i = 0; i < args.size(); ++i) {
224 
225  // removing any leading white spaces (' ', '\t')
226  args[i] = tstring::removeLeadingWhiteSpace(args[i]);
227 
228 // cout << args[i] << endl;
229 
230  // check for specifiers:
231  if(args[i][0] == '@') {
232 
233  // temporal argument
234  if(args[i][1] == 'g')
235  {
236  if(!parseTemporalArgument(args[i])) return false;
237  }
238 
239  // age-specific argument
240  else if(args[i][1] == 'a')
241  {
242  if(!parseAgeSpecArgument(args[i])) return false;
243  }
244 
245  // error
246  else
247  {
248  return error("parameter \"%s\" has unrecognized specifier in its argument string \"%s\".\n", _name.c_str(), args[i].c_str());
249  }
250 
251  // multiple arguments?
252  } else { // (arg1, arg2, arg3, ...)
253  //values might still be in external files
254  _multiArgs.push_back( checkArgumentForExpansion(args[i]) );
255  }
256  }
257 
258  if(_multiArgs.size() != 0)
259  _hasMultipleArgs = true;
260  else
261  _hasMultipleArgs = false;
262 
263 
264  // deal with temporal arguments:
265  if(_temporalArgs.size() != 0) {
266 
267 // cout << "temporal arg values:\n";
268 // for(map< unsigned int , string >::iterator iter = _temporalArgs.begin();
269 // iter != _temporalArgs.end();
270 // iter++)
271 // cout << iter->first <<" "<< iter->second << endl;
272 
273  if(_myUpdater != 0) {
274 
275  if(_temporalArgs.find(0) != _temporalArgs.end()) {
276  _isTemporal = true;
277  //set the value for the first generation
278  arg = _temporalArgs.find(0)->second;
279  }
280  else {
281  return error("first generation argument value for temporal parameter \"%s\" is missing; no \"@g0\".\n", _name.c_str());
282  }
283 
284  } else {
285  warning("trying to pass a temporal argument to a non temporal parameter (\"%s\").\n", _name.c_str());
286  _isTemporal = false;
287  _temporalArgs.clear();
288  }
289 
290  } else _isTemporal = false;
291 
292 
293  return true;
294 }
bool parseAgeSpecArgument(const string &arg)
Definition: param.cc:320
string checkArgumentForExpansion(string arg)
Definition: param.cc:334
bool parseTemporalArgument(const string &arg)
Definition: param.cc:298
static string removeEnclosingChar(const string &str, const char o, const char c, bool allowMissing=false)
Removes characters enclosing a string.
Definition: tstring.h:356
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
static string removeLeadingWhiteSpace(const string &str)
Definition: tstring.h:384
static string replaceChar(const string &str, const char target, const char replacement)
Definition: tstring.h:394
int error(const char *str,...)
Definition: output.cc:77

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

Referenced by set().

◆ parseSubParamArgument()

bool Param::parseSubParamArgument ( const string &  arg)
328 {
329  return true;
330 }

◆ parseTemporalArgument()

bool Param::parseTemporalArgument ( const string &  arg)
299 {
300  vector< string > args = tstring::split(arg, ' ', true);
301 
302  if(args.size() != 2) {
303  error("Param::parseTemporalArgument:: missing argument value in \"%s %s\".\n", _name.c_str(), arg.c_str());
304  return false;
305  }
306 
307  unsigned int gen = tstring::str2uint(tstring::removeFirstCharOf(tstring::removeFirstCharOf(args[0], '@'), 'g'));
308 
309  // remove extra white space characters introduced between delimiter and argument value:
310  args[1] = tstring::removeLeadingWhiteSpace(args[1]);
311  args[1] = checkArgumentForExpansion(args[1]);
312 
313  _temporalArgs[gen] = args[1];
314 
315  return true;
316 }
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
static unsigned int str2uint(const string &str)
Converts a string into an unsigned integer.
Definition: tstring.h:51

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

Referenced by parseArgument().

◆ reset()

void Param::reset ( )

Clears the _isSet flag and the argument string.

75 {
76  _input_arg = "",
77  _arg = "";
78  _isSet = 0;
79  _setAtGeneration = 0;
80 
81  _multiArgs.clear();
82  _hasMultipleArgs = false;
83 
84  _externalFile.clear();
85  _hasExternalFile = false;
86 
87  _temporalArgs.clear();
88  _isTemporal = false;
89 
90 }

References _arg, _externalFile, _hasExternalFile, _hasMultipleArgs, _input_arg, _isSet, _isTemporal, _multiArgs, _setAtGeneration, and _temporalArgs.

Referenced by LCE_Breed_Selection_Disperse::setParameters().

◆ set()

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

132 {
133 // cout << "Param::set ("<<arg<<")\n";
134 
135  _input_arg = arg; //backup the input parameter argument string
136 
137  //remove any remaining leading white-space character
138  while(isspace(arg[0])) {
139  arg.erase(0);
140  }
141 
142  if(arg.size() == 0){
143  errmsg = "argument is empty";
144  return false;
145  }
146  _externalFile.clear(); //ext. file names will be pushed here
147  //check if argument is in an external file, and read it from that file
148  if (arg[0] == '&') {
149  //read the argument from an external file, file name is stored within the call.
150  string expanded = checkArgumentForExpansion(arg);
151  arg = expanded;
152  }
153 
154  if( arg[0] == '(' ) {
155  if( !parseArgument( arg ) ) {
156  errmsg = "could not parse the argument string";
157  return false;
158  }
159  }
160 
161  //integer or decimal:
162  if(_type == INT || _type == DBL) {
164  if(arg[0] != '{') {
165 
166  if(!tstring::isanumber(arg)) {
167  errmsg = "argument is not a number";
168  return false;
169  }
170 
171  double val = tstring::str2dble(arg);
172 
173  if(_isBounded && (val < _bounds[0] || val > _bounds[1]) ){
174  errmsg = "argument is out of bounds";
175  return false;
176  }
177  }
178 
179  //boolean:
180  } else if(_type == BOOL) {
181 
182  if( !tstring::isanumber(arg) ){
183  errmsg = "argument is not a boolean";
184  return false;
185  }
186 
187  } else if(_type == MAT) {
188  if(arg[0] != '{'){
189  errmsg = "argument is not a matrix";
190  return false;
191  }
192  }
193  // else if(_type == P || _type == S): no conditions to check
194 
195  _isSet = (_type == BOOL && tstring::str2int(arg) == 0 ? false : true);
196 
197  //now we set the value of the parameter to the value of the argument read in the file
198  _arg = arg;
199 
200  return true;
201 }
bool parseArgument(string &arg)
Definition: param.cc:205
static double str2dble(const string &str)
Converts a string into a double.
Definition: tstring.h:84
static int str2int(const string &str)
Converts a string into an integer.
Definition: tstring.h:73
static bool isanumber(const string &str)
Check whether the string is a number.
Definition: tstring.h:410
@ DBL
Definition: types.h:78
@ BOOL
Definition: types.h:78
@ INT
Definition: types.h:78

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().

◆ setArg()

void Param::setArg ( string  value)
inline

◆ setAtGeneration()

void Param::setAtGeneration ( unsigned int  generation)
inline
134 {_setAtGeneration = generation;}

◆ setBounds()

void Param::setBounds ( double  low_bnd,
double  up_bnd 
)
inline

Sets the bounds.

128 {_bounds[0]=low_bnd; _bounds[1]=up_bnd;}

◆ setIsBounded()

void Param::setIsBounded ( bool  value)
inline

Sets the _isBounded flag.

124 {_isBounded = value;}

◆ setIsRequired()

void Param::setIsRequired ( bool  value)
inline

Sets the isRequired flag.

126 {_isRequired = value;}

◆ setIsSet()

◆ setName()

void Param::setName ( string  value)
inline

Sets the parameter's name.

116 {_name = value;}

◆ setOwner()

void Param::setOwner ( SimComponent owner)
inline

Sets the pointer to owner.

130 {_myOwner = owner;}

◆ setType()

void Param::setType ( param_t  value)
inline

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

120 {_type = value;}

◆ setUpdater()

void Param::setUpdater ( ParamUpdaterBase updater)
inline

Sets the pointer to the updater object.

132 {_myUpdater = updater;}

◆ show_up()

void Param::show_up ( )

Print state to stdout.

540 {
541  message("%s = %s",_name.c_str(),_arg.c_str());
542  if(_isSet)
543  message(" (set at gen %i)\n",_setAtGeneration);
544  else
545  message(" (not set)\n");
546 }
void message(const char *message,...)
Definition: output.cc:40

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

◆ update()

bool Param::update ( unsigned int  generation)

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

524 {
525  string error_msg;
526  if(_temporalArgs.find( generation ) != _temporalArgs.end()) {
527  if( !set( _temporalArgs[generation], error_msg ) ){
528  error("could not set \"%s\": %s", _name.c_str(), error_msg.c_str());
529  return false;
530  } else
531  return true;
532  } else
533  error("parameter \"%s\" does not have an argument value for generation %i.\n", _name.c_str(), generation);
534  return false;
535 }
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:131

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

Referenced by ParamSet::update_param().

Member Data Documentation

◆ _arg

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().

◆ _bounds

double Param::_bounds[2]
private

The argument value boundaries.

Referenced by Param(), and set().

◆ _externalFile

vector< string > Param::_externalFile
private

External argument file.

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

◆ _hasExternalFile

bool Param::_hasExternalFile
private

Referenced by getArgumentFromFile(), and reset().

◆ _hasMultipleArgs

bool Param::_hasMultipleArgs
private

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

◆ _input_arg

string Param::_input_arg
private

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

Referenced by reset(), and set().

◆ _isBounded

bool Param::_isBounded
private

Flag telling if the parameter has a bounded argument value.

Referenced by set().

◆ _isRequired

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.

◆ _isSet

bool Param::_isSet
private

Flag set once the parameter has recieved the right argument.

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

◆ _isTemporal

bool Param::_isTemporal
private

Flag telling if this parameter has temporal arguments.

Referenced by parseArgument(), and reset().

◆ _multiArgs

vector< string > Param::_multiArgs
private

Multiple arguments.

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

◆ _myOwner

SimComponent* Param::_myOwner
private

Pointer to the component that declared this parameter.

◆ _myUpdater

ParamUpdaterBase* Param::_myUpdater
private

Pointer to an ParamUpdater object.

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

◆ _name

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().

◆ _setAtGeneration

unsigned int Param::_setAtGeneration
private

Generation at which the parameter has been set/updated.

Referenced by reset(), and show_up().

◆ _temporalArgs

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

◆ _type

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.4.0b by  doxygen 1.9.1 -- Nemo is hosted on  Download Nemo

Locations of visitors to this page
Catalogued on GSR