Nemo  2.3.46
ParamSet Class Reference

Parameters container, implemented in each SimComponent. More...

#include <param.h>

+ Collaboration diagram for ParamSet:

Public Member Functions

 ParamSet ()
 
 ParamSet (const ParamSet &PS)
 
 ~ParamSet ()
 
void reset ()
 Put the container in the unset state, reset each Param it contains. More...
 
void clear ()
 Empties the parameter containers (no delete). More...
 
bool check_consistency ()
 Checks for the status of the required parameters. More...
 
void show_up ()
 print info to stdout. More...
 
void print (ofstream &FILE)
 print all set parameters to the outpout file stream More...
 
int size ()
 Returns the number of parameters contained. More...
 
map< string, Param * > & getAllParams ()
 Returns the complete list of parameters. More...
 
ParamSetoperator= (const ParamSet &PS)
 
Accessors to Param members.
void add_param (Param *param)
 Adds the param argument to the list. More...
 
void add_param (string Name, param_t Type, bool mandatory, bool isBounded, double low_bnd, double up_bnd)
 Adds a new param specified by arguments to the list. More...
 
void add_param (string Name, param_t Type, bool mandatory, bool isBounded, double low_bnd, double up_bnd, ParamUpdaterBase *updater)
 
bool set_param (string Name, string Arg)
 Look for a param named "Name" and try to set it with the "Arg" argument string. More...
 
Paramget_param (string name)
 Look for a param "name" in its parameters list. More...
 
bool update_param (string Name, unsigned int generation)
 Calls the updating procedure of each of its Param. More...
 
void setName (string value)
 Sets the container's name. More...
 
void setIsRequired (bool value)
 Sets the _isRequired flag meaning this container is mandatory and must be set in order to run a simulation. More...
 
void setOwner (SimComponent *owner)
 Sets the pointer to the SimComponents that owns this set. More...
 
bool isSet ()
 Accessor to the status flag. More...
 
string getName ()
 Name accessor. More...
 
bool isRequired ()
 Accessor to the mandatory flag. More...
 
bool isSet (string name)
 Accessor to the parameters status flag. More...
 
bool isMatrix (string name)
 Check if the parameter "name" is of matrix type. More...
 
bool isTemporal (string name)
 Check if the parameter "name" has temporal arguments. More...
 
string getArg (string name)
 Accessor to the parameters argument string. More...
 
double getValue (string name)
 Accessor the parameters value. More...
 
void getMatrix (string name, TMatrix *mat)
 Accessor to the parameters matrix. More...
 
list< ParamUpdaterBase * > getUpdaters ()
 Collects the parameter updaters from the set of parameters. More...
 

Private Attributes

string _name
 
bool _isSet
 
bool _isRequired
 
map< string, Param * > _params
 
SimComponent_myOwner
 Pointer to the component that declared this parameter. More...
 

Detailed Description

Parameters container, implemented in each SimComponent.

A SimComponent is added to the set of active components of a simulation only if all its required parameters are set (isSet = true).

Constructor & Destructor Documentation

ParamSet::ParamSet ( )
inline
215 : _isSet(0), _isRequired(0) { }
bool _isRequired
Definition: param.h:208
bool _isSet
Definition: param.h:207
ParamSet::ParamSet ( const ParamSet PS)

References _params.

507 {
508  map<string, Param*>::iterator param;
509 
510  if( _params.size() ) {
511  param = _params.begin();
512  while(param != _params.end()) {
513  delete param->second;
514  param++;
515  }
516  _params.clear();
517  }
518  map<string, Param*> PS_params = PS._params;
519  param = PS_params.begin();
520  while(param != PS_params.end()) {
521  _params[param->first] = new Param( *param->second );
522  param++;
523  }
524 
525 }
bool _isRequired
Definition: param.h:208
bool _isSet
Definition: param.h:207
This structure stores one parameter, its definition and its string argument.
Definition: param.h:53
map< string, Param * > _params
Definition: param.h:209
string _name
Definition: param.h:206
ParamSet::~ParamSet ( )

References _params.

531 {
532  map<string, Param*>::iterator param = _params.begin();
533  while(param != _params.end()) {
534  delete param->second;
535  param++;
536  }
537 }
map< string, Param * > _params
Definition: param.h:209

Member Function Documentation

void ParamSet::add_param ( Param param)
inline

Adds the param argument to the list.

References Param::getName().

Referenced by SimComponent::add_parameter(), and ParamManager::ParamManager().

238 {_params[param->getName()] = param;}
string getName()
Definition: param.h:135
map< string, Param * > _params
Definition: param.h:209
void ParamSet::add_param ( string  Name,
param_t  Type,
bool  mandatory,
bool  isBounded,
double  low_bnd,
double  up_bnd 
)
inline

Adds a new param specified by arguments to the list.

Parameters
Namethe name of the parameter
Typethe type of the parameter
mandatoryspecifies if this parameter is required and must be set for the container to gain the "set" status
isBoundedspecified whether this parameter is bounded
low_bndthe lower value the parameter can take, used if isBounded is true
up_bndthe upper value the parameter can take, used if isBounded is true
249  {add_param(Name, Type, mandatory, isBounded, low_bnd, up_bnd, 0);}
void add_param(Param *param)
Adds the param argument to the list.
Definition: param.h:238
void ParamSet::add_param ( string  Name,
param_t  Type,
bool  mandatory,
bool  isBounded,
double  low_bnd,
double  up_bnd,
ParamUpdaterBase updater 
)

References _myOwner, _params, and ParamUpdaterBase::addParam().

555 {
556  // if(!_name.empty()) Name = _name + "_" + Name; //not yet...
557  Param* param = new Param(Name, Type, mandatory, isBounded, low_bnd, up_bnd, _myOwner, updater);
558  if(updater) updater->addParam(param);
559  _params[Name] = param;
560 }
virtual void addParam(Param *param)
Adds a parameter to the stack.
Definition: param.h:328
This structure stores one parameter, its definition and its string argument.
Definition: param.h:53
map< string, Param * > _params
Definition: param.h:209
SimComponent * _myOwner
Pointer to the component that declared this parameter.
Definition: param.h:211
bool ParamSet::check_consistency ( )

Checks for the status of the required parameters.

Returns
TRUE if all required parameters are or if nothing is set and the container is not required

References _isRequired, _isSet, and _params.

621 {
622  map<string, Param*>::iterator param = _params.begin();
623  bool isOK = true;
624  bool touched = false;
625 
626  while(param != _params.end()) {
627  //check if all required field have been set properly
628  if(param->second->isRequired())
629  isOK &= param->second->isSet();
630  //else we don't care..
631  //check if at least one param has been set
632  touched |= param->second->isSet();
633  param++;
634  }
635  _isSet = isOK;
636  //return isOk or check if _isRequired in case no params are set (untouched params)
637  return ( isOK | (!_isRequired));// & !touched) );
638 }
bool _isRequired
Definition: param.h:208
bool _isSet
Definition: param.h:207
map< string, Param * > _params
Definition: param.h:209
void ParamSet::clear ( )
inline

Empties the parameter containers (no delete).

222 {_params.clear();}
map< string, Param * > _params
Definition: param.h:209
Param * ParamSet::get_param ( string  name)

Look for a param "name" in its parameters list.

Returns
NULL if no Param with _name = name exists

References _name, _params, and fatal().

Referenced by SimComponent::get_parameter(), LCE_StatServiceNotifier::setOccurence(), and update_param().

598 {
599  map<string, Param*>::iterator param = _params.find(Name);
600 
601  if(param != _params.end())
602  return param->second;
603  else
604  fatal("parameter \"%s\" is not a member of \"%s\".\n", Name.c_str(), _name.c_str());
605  //return NULL;
606  return NULL;
607 }
void fatal(const char *str,...)
Definition: output.cc:90
map< string, Param * > _params
Definition: param.h:209
string _name
Definition: param.h:206
map<string, Param*>& ParamSet::getAllParams ( )
inline

Returns the complete list of parameters.

234 {return _params;}
map< string, Param * > _params
Definition: param.h:209
string ParamSet::getArg ( string  name)
inline
void ParamSet::getMatrix ( string  name,
TMatrix mat 
)
inline
string ParamSet::getName ( )
inline

Name accessor.

Referenced by SimComponent::get_name().

275 {return _name;}
string _name
Definition: param.h:206
list< ParamUpdaterBase * > ParamSet::getUpdaters ( )

Collects the parameter updaters from the set of parameters.

References _params.

Referenced by SimComponent::loadUpdaters().

565 {
566  list<ParamUpdaterBase*> updaters;
567  map<string, Param*>::iterator param = _params.begin();
568  for(;param != _params.end(); param++) {
569  if(param->second->getUpdater() != 0)
570  updaters.push_back(param->second->getUpdater());
571  }
572  return updaters;
573 }
map< string, Param * > _params
Definition: param.h:209
double ParamSet::getValue ( string  name)
inline
bool ParamSet::isMatrix ( string  name)
inline

Check if the parameter "name" is of matrix type.

Referenced by LCE_Breed_Disperse::setParameters(), LCE_Resize::setParameters(), and Metapop::setPopulationParameters().

281 {return (get_param(name))->isMatrix();}
Param * get_param(string name)
Look for a param "name" in its parameters list.
Definition: param.cc:597
bool ParamSet::isRequired ( )
inline

Accessor to the mandatory flag.

277 {return _isRequired;}
bool _isRequired
Definition: param.h:208
bool ParamSet::isSet ( string  name)
inline

Accessor to the parameters status flag.

279 {return (get_param(name))->isSet();}
Param * get_param(string name)
Look for a param "name" in its parameters list.
Definition: param.cc:597
bool ParamSet::isTemporal ( string  name)
inline

Check if the parameter "name" has temporal arguments.

283 {return (get_param(name))->isTemporal();}
Param * get_param(string name)
Look for a param "name" in its parameters list.
Definition: param.cc:597
ParamSet & ParamSet::operator= ( const ParamSet PS)

References _isRequired, _isSet, _name, and _params.

643 {
644  if(this != &PS) {
645  _name = PS._name;
646  _isSet = PS._isSet;
648 
649  map<string, Param*>::iterator param;
650 
651  if( _params.size() ) {
652  param = _params.begin();
653  while(param != _params.end()) {
654  delete param->second;
655  param++;
656  }
657  _params.clear();
658  }
659  map<string, Param*> PS_params = PS._params;
660  param = PS_params.begin();
661  while(param != PS_params.end()) {
662  _params[param->first] = new Param( *param->second );
663  param++;
664  }
665  }
666  return *this;
667 }
bool _isRequired
Definition: param.h:208
bool _isSet
Definition: param.h:207
This structure stores one parameter, its definition and its string argument.
Definition: param.h:53
map< string, Param * > _params
Definition: param.h:209
string _name
Definition: param.h:206
void ParamSet::print ( ofstream &  FILE)

print all set parameters to the outpout file stream

References _params, Param::getArg(), Param::getName(), and Param::isSet().

684 {
685  map<string, Param*>::iterator paramRec = _params.begin();
686  Param* param;
687 
688  while(paramRec != _params.end()) {
689 
690  param = paramRec->second;
691 
692  if(param->isSet()){
693  // FILE.width(20);
694  // FILE.setf(ios::left,ios::adjustfield);
695 
696  FILE<<param->getName()<<" ";
697 
698 // if (param->isTemporal()) {
699 //
700 // deque< unsigned int > gen = param->getUpdatingDates();
701 // deque< string > args = param->getTemporalArgs();
702 //
703 // FILE<<"(";
704 //
705 // for (unsigned int i = 0, size = gen.size(); i < size; i++) {
706 //
707 // FILE<<"@g"<<gen[i]<<" "<<args[i];
708 //
709 // if (i < size-1) {
710 // FILE << ", ";
711 // }
712 // else FILE << ")";
713 // }
714 //
715 // } else if (param->hasExternalFile()) {
716 //
717 // vector<string> ext_files = param->getExternalFiles();
718 //
719 // if(ext_files.size() == 1) {
720 //
721 // FILE<<ext_files[0];
722 //
723 // } else {
724 //
725 // FILE<<"(";
726 // for (unsigned int i = 0; i < ext_files.size() -1; ++i) {
727 // FILE<<ext_files[i]<<", ";
728 // }
729 // FILE<<ext_files[ ext_files.size() -1 ]<<")";
730 // }
731 //
732 // } else
733  FILE<<param->getArg();
734 
735  FILE<<endl;
736  }
737 
738  paramRec++;
739  }
740 }
string getName()
Definition: param.h:135
This structure stores one parameter, its definition and its string argument.
Definition: param.h:53
string getArg()
Definition: param.h:136
map< string, Param * > _params
Definition: param.h:209
bool isSet()
Definition: param.h:138
void ParamSet::reset ( )

Put the container in the unset state, reset each Param it contains.

References _isSet, and _params.

542 {
543  _isSet = 0;
544  map<string, Param*>::iterator param = _params.begin();
545  while(param != _params.end()) {
546  param->second->reset();
547  param++;
548  }
549 }
bool _isSet
Definition: param.h:207
map< string, Param * > _params
Definition: param.h:209
bool ParamSet::set_param ( string  Name,
string  Arg 
)

Look for a param named "Name" and try to set it with the "Arg" argument string.

Returns
TRUE if param Name has been found and set with Arg
FALSE otherwise
Parameters
Namethe name of the parameter to find in the list
Argthe argument string as found in the init params

References _params, and error().

Referenced by LCE_Resize::execute().

578 {
579  map<string, Param*>::iterator param = _params.find(Name);
580  string error_msg;
581 
582  if(param == _params.end()) {
583  // error("could not set \"%s\": parameter not found.\n",Name.c_str());
584  //exist silently
585  return false;
586  }
587 
588  if( !param->second->set(Arg, error_msg) ) {
589  error("could not set \"%s\": %s.\n", Name.c_str(), error_msg.c_str());
590  return false;
591  } else
592  return true;
593 }
int error(const char *str,...)
Definition: output.cc:73
map< string, Param * > _params
Definition: param.h:209
void ParamSet::setIsRequired ( bool  value)
inline

Sets the _isRequired flag meaning this container is mandatory and must be set in order to run a simulation.

Referenced by ParamManager::ParamManager(), and SimComponent::set_paramset().

269 {_isRequired = value;}
bool _isRequired
Definition: param.h:208
void ParamSet::setName ( string  value)
inline

Sets the container's name.

Referenced by ParamManager::ParamManager(), and SimComponent::set_paramset().

267 {_name = value;}
string _name
Definition: param.h:206
void ParamSet::setOwner ( SimComponent owner)
inline

Sets the pointer to the SimComponents that owns this set.

Referenced by ParamManager::ParamManager(), and SimComponent::set_paramset().

271 {_myOwner = owner;}
SimComponent * _myOwner
Pointer to the component that declared this parameter.
Definition: param.h:211
void ParamSet::show_up ( )

print info to stdout.

References _name, _params, and message().

672 {
673  message("%s\n",_name.c_str());
674  map<string, Param*>::iterator param = _params.begin();
675  while(param != _params.end()) {
676  param->second->show_up();
677  param++;
678  }
679 }
void message(const char *message,...)
Definition: output.cc:40
map< string, Param * > _params
Definition: param.h:209
string _name
Definition: param.h:206
int ParamSet::size ( )
inline

Returns the number of parameters contained.

232 {return _params.size();}
map< string, Param * > _params
Definition: param.h:209
bool ParamSet::update_param ( string  Name,
unsigned int  generation 
)

Calls the updating procedure of each of its Param.

References get_param(), and Param::update().

612 {
613  Param* param = get_param(Name);
614  if(param) return param->update( generation );
615  return false;
616 }
This structure stores one parameter, its definition and its string argument.
Definition: param.h:53
bool update(unsigned int generation)
Updates the parameter value at a given generation during the simulation.
Definition: param.cc:474
Param * get_param(string name)
Look for a param "name" in its parameters list.
Definition: param.cc:597

Member Data Documentation

bool ParamSet::_isRequired
private

Referenced by check_consistency(), and operator=().

bool ParamSet::_isSet
private

Referenced by check_consistency(), operator=(), and reset().

SimComponent* ParamSet::_myOwner
private

Pointer to the component that declared this parameter.

Referenced by add_param().

string ParamSet::_name
private

Referenced by get_param(), operator=(), and show_up().


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