Nemo  2.2.0
Public Member Functions | Private Attributes
ParamSet Class Reference

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

#include <param.h>

+ Collaboration diagram for ParamSet:

List of all members.

Public Member Functions

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

Private Attributes

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

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

Definition at line 180 of file param.h.


Constructor & Destructor Documentation

ParamSet::ParamSet ( ) [inline]

Definition at line 192 of file param.h.

: _isSet(0), _isRequired(0) { }
ParamSet::ParamSet ( const ParamSet PS)

Definition at line 367 of file param.cc.

: _name(PS._name), _isSet(PS._isSet), _isRequired(PS._isRequired)
{
  map<string, Param*>::iterator param;

  if( _params.size() ) {
    param =  _params.begin();
    while(param != _params.end()) {
      delete param->second;
      param++;
    }
    _params.clear();
  }
  map<string, Param*> PS_params = PS._params;
  param =  PS_params.begin();
  while(param != PS_params.end()) {
    _params[param->first] = new Param( *param->second );
    param++;
  }
  
}
ParamSet::~ParamSet ( )

Definition at line 392 of file param.cc.

{
  map<string, Param*>::iterator param =  _params.begin();
  while(param != _params.end()) {
        delete param->second;
        param++;
  }
}

Member Function Documentation

void ParamSet::add_param ( Param param) [inline]

Adds the param argument to the list.

Definition at line 215 of file param.h.

References Param::getName().

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

{_params[param->getName()] = param;}
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

Definition at line 224 of file param.h.

References add_param().

Referenced by add_param().

    {add_param(Name, Type, mandatory, isBounded, low_bnd, up_bnd, 0);}
void ParamSet::add_param ( string  Name,
param_t  Type,
bool  mandatory,
bool  isBounded,
double  low_bnd,
double  up_bnd,
ParamUpdaterBase updater 
)

Definition at line 415 of file param.cc.

{
//  if(!_name.empty()) Name = _name + "_" + Name; //not yet...
  Param* param = new Param(Name, Type, mandatory, isBounded, low_bnd, up_bnd, _myOwner, updater);
  if(updater) updater->addParam(param);
  _params[Name] = param;
}
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

Definition at line 482 of file param.cc.

{
  map<string, Param*>::iterator param = _params.begin();
  bool isOK = true;
  bool touched = false;
  
  while(param != _params.end()) {
    //check if all required field have been set properly
        if(param->second->isRequired())
          isOK &= param->second->isSet();
        //else we don't care..
    //check if at least one param has been set
    touched |= param->second->isSet();
        param++;
  }
  _isSet = isOK;
  //return isOk or check if _isRequired in case no params are set (untouched params)
  return ( isOK | (!_isRequired));// & !touched) );
}
void ParamSet::clear ( ) [inline]

Empties the parameter containers (no delete).

Definition at line 199 of file param.h.

{_params.clear();}
Param * ParamSet::get_param ( string  name)

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

Returns:
NULL if no Param with _name = name exists

Definition at line 459 of file param.cc.

Referenced by SimComponent::get_parameter().

{
  map<string, Param*>::iterator param = _params.find(Name);
  
  if(param != _params.end())
        return param->second;
  else
    fatal("parameter \"%s\" is not a member of \"%s\".\n", Name.c_str(), _name.c_str());
        //return NULL;
  return NULL;
}
map<string, Param*>& ParamSet::getAllParams ( ) [inline]

Returns the complete list of parameters.

Definition at line 211 of file param.h.

{return _params;}
string ParamSet::getArg ( string  name) [inline]
void ParamSet::getMatrix ( string  name,
TMatrix mat 
) [inline]
string ParamSet::getName ( ) [inline]

Name accessor.

Definition at line 252 of file param.h.

Referenced by SimComponent::get_name().

{return _name;}
list< ParamUpdaterBase * > ParamSet::getUpdaters ( )

Collects the parameter updaters from the set of parameters.

Definition at line 426 of file param.cc.

Referenced by SimComponent::loadUpdaters().

{
  list<ParamUpdaterBase*> updaters;
  map<string, Param*>::iterator param = _params.begin();
  for(;param != _params.end(); param++) {
    if(param->second->getUpdater() != 0)
      updaters.push_back(param->second->getUpdater());
  }
  return updaters;
}
double ParamSet::getValue ( string  name) [inline]
bool ParamSet::isMatrix ( string  name) [inline]

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

Definition at line 258 of file param.h.

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

{return (get_param(name))->isMatrix();}
bool ParamSet::isRequired ( ) [inline]

Accessor to the mandatory flag.

Definition at line 254 of file param.h.

{return _isRequired;}
bool ParamSet::isSet ( ) [inline]
bool ParamSet::isSet ( string  name) [inline]

Accessor to the parameters status flag.

Definition at line 256 of file param.h.

{return (get_param(name))->isSet();}
ParamSet & ParamSet::operator= ( const ParamSet PS)

Definition at line 504 of file param.cc.

{
  if(this != &PS) {
    _name = PS._name;
    _isSet = PS._isSet;
    _isRequired = PS._isRequired;
    
    map<string, Param*>::iterator param;
    
    if( _params.size() ) {
      param =  _params.begin();
      while(param != _params.end()) {
        delete param->second;
        param++;
      }
      _params.clear();
    }
    map<string, Param*> PS_params = PS._params;
    param =  PS_params.begin();
    while(param != PS_params.end()) {
      _params[param->first] = new Param( *param->second );
      param++;
    }
  }
  return *this;
}
void ParamSet::print ( ofstream &  FILE)

print all set parameters to the outpout file stream

Definition at line 545 of file param.cc.

{
//  FILE<<_name<<endl;
  map<string, Param*>::iterator param = _params.begin();
  while(param != _params.end()) {
        if(param->second->isSet()){
//        FILE.width(20);
//        FILE.setf(ios::left,ios::adjustfield);
          FILE<<param->second->getName()<<" "<<param->second->getArg()<<endl;
        }
        param++;
  }
}
void ParamSet::reset ( )

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

Definition at line 403 of file param.cc.

{
  _isSet = 0;
  map<string, Param*>::iterator param =  _params.begin();
  while(param != _params.end()) {
        param->second->reset();
        param++;
  }
}
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

Definition at line 439 of file param.cc.

Referenced by LCE_Resize::execute().

{
  map<string, Param*>::iterator param = _params.find(Name);
  string error_msg;
  
  if(param == _params.end()) {
//    error("could not set \"%s\": parameter not found.\n",Name.c_str());
    //exist silently
    return false;
  }
  
  if( !param->second->set(Arg, error_msg) ) {
    error("could not set \"%s\": %s.\n", Name.c_str(), error_msg.c_str());
    return false;
  } else
    return true;
}
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.

Definition at line 246 of file param.h.

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

{_isRequired = value;}
void ParamSet::setName ( string  value) [inline]

Sets the container's name.

Definition at line 244 of file param.h.

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

{_name = value;}
void ParamSet::setOwner ( SimComponent owner) [inline]

Sets the pointer to the SimComponents that owns this set.

Definition at line 248 of file param.h.

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

{_myOwner = owner;}
void ParamSet::show_up ( )

print info to stdout.

Definition at line 533 of file param.cc.

{
  message("%s\n",_name.c_str());
  map<string, Param*>::iterator param = _params.begin();
  while(param != _params.end()) {
        param->second->show_up();
        param++;
  }
}
int ParamSet::size ( ) [inline]

Returns the number of parameters contained.

Definition at line 209 of file param.h.

{return _params.size();}
bool ParamSet::update_param ( string  Name,
unsigned int  generation 
)

Calls the updating procedure of each of its Param.

Definition at line 473 of file param.cc.

{
  Param* param = get_param(Name);
  if(param) return param->update( generation );
  return false;
}

Member Data Documentation

bool ParamSet::_isRequired [private]

Definition at line 185 of file param.h.

bool ParamSet::_isSet [private]

Definition at line 184 of file param.h.

Pointer to the component that declared this parameter.

Definition at line 188 of file param.h.

string ParamSet::_name [private]

Definition at line 183 of file param.h.

map<string, Param*> ParamSet::_params [private]

Definition at line 186 of file param.h.


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

Generated for Nemo v2.2.0 by  doxygen 1.7.5.1 -- Nemo is hosted by  SourceForge.net Logo