Nemo  2.2.0
Public Member Functions | Protected Types | Protected Attributes
SimBuilder Class Reference

Provides methods to build the user's selected set of life cycle events and traits from the parameters. More...

#include <basicsimulation.h>

+ Inheritance diagram for SimBuilder:
+ Collaboration diagram for SimBuilder:

List of all members.

Public Member Functions

 SimBuilder ()
 SimBuilder (const SimBuilder &SB)
 copy cstor.
 ~SimBuilder ()
bool build_currentParams (map< string, string > &simparams)
 Builds the list of parameters from user's defined input parameters.
map< trait_t, TraitPrototype * > & build_currentTraits ()
 Selects the trait prototypes that have their parameters set.
void build_LifeCycle ()
 Selects the life cycle events that have their parameters set.
TraitPrototypeget_current_trait (trait_t type)
 Accessor to the list of current trait prototypes.
LifeCycleEventget_current_event (string &name)
 Accessor to the list of current LCEs.
list< ParamSet * > & get_currentParams ()
 Accessor to the list of the selected parameter sets.
age_t getFirstRequiredAgeInLifeCycle ()

Protected Types

typedef map< int,
LifeCycleEvent * >
::const_iterator 
LCE_ITER
typedef map< trait_t,
TraitPrototype * >
::const_iterator 
TRAIT_ITER

Protected Attributes

list< ParamSet * > _currentParams
 List of the selected simulation components from the user defined input parameters.
map< trait_t, TraitPrototype * > _currentTraits
 List of the selected trait prototypes from the user defined input parameters.
map< int, LifeCycleEvent * > _LifeCycle
 List of the selected life cycle events from the user defined input parameters.

Detailed Description

Provides methods to build the user's selected set of life cycle events and traits from the parameters.

This class implements methods to build the lists of selected traits and life cycle events from the user's defined parameters. Each simulation component that has its ParamSet in the "set" state is elligible to be part of the current simulation. Accessors to these components are provided. This class does however not provide a runnable simulation object.

Definition at line 162 of file basicsimulation.h.


Member Typedef Documentation

typedef map< int, LifeCycleEvent* >::const_iterator SimBuilder::LCE_ITER [protected]

Definition at line 206 of file basicsimulation.h.

typedef map< trait_t, TraitPrototype* >::const_iterator SimBuilder::TRAIT_ITER [protected]

Definition at line 207 of file basicsimulation.h.


Constructor & Destructor Documentation

SimBuilder::SimBuilder ( ) [inline]

Definition at line 164 of file basicsimulation.h.

{ }
SimBuilder::SimBuilder ( const SimBuilder SB)

copy cstor.

Definition at line 510 of file basicsimulation.cc.

References ComponentManager::_LCE_Templates, ParamManager::_paramSet, ComponentManager::_TTrait_Templates, ComponentManager::add_LCE(), ComponentManager::add_trait(), and ParamManager::build_allParams().

{  
  list< TraitPrototype* >::const_iterator TT = SB._TTrait_Templates.begin();
  
  for(;TT != SB._TTrait_Templates.end(); TT++)  add_trait( (*TT)->clone() );
  
  list< LifeCycleEvent* >::const_iterator LCE = SB._LCE_Templates.begin();
  
  for(;LCE != SB._LCE_Templates.end(); LCE++)   add_LCE( (*LCE)->clone() );
    
  
  _paramSet = SB._paramSet;
  
  build_allParams();
}
SimBuilder::~SimBuilder ( ) [inline]

Definition at line 167 of file basicsimulation.h.

{/*message("SimBuilder::~SimBuilder\n");*/}

Member Function Documentation

bool SimBuilder::build_currentParams ( map< string, string > &  simparams)

Builds the list of parameters from user's defined input parameters.

Parameters:
simparamsHashtable of the parsed input parameters
Returns:
TRUE if parameters are consitently set

Definition at line 555 of file basicsimulation.cc.

References ParamManager::_allParams, _currentParams, message(), and ParamManager::set_parameters().

Referenced by BinaryDataLoader::extractPop(), and SimRunner::init_components().

{
  if(! this->set_parameters(simparams, false) ) return false;
  
  //empty the current parameters container:
  _currentParams.clear();
  
  list<ParamSet*>::iterator current_paramset = this->_allParams.begin();
  
  //add all set parameters to the list of the current params:
  while(current_paramset != this->_allParams.end()){
    if((*current_paramset)->isSet()) {
#ifdef _DEBUG_
      message("SimBuilder::build_currentParams:adding paramset %s\n",
              (*current_paramset)->getName().c_str());
#endif
      _currentParams.push_back(*current_paramset);
    }
    current_paramset++;
  }
  
  return true;
}
map< trait_t, TraitPrototype * > & SimBuilder::build_currentTraits ( )

Selects the trait prototypes that have their parameters set.

Returns:
Hashtable of the trait prototypes

Definition at line 581 of file basicsimulation.cc.

References _currentTraits, and ComponentManager::_TTrait_Templates.

Referenced by BinaryDataLoader::extractPop(), and SimRunner::init_components().

{
  //build the list of Traits for this simulation:
  list< TraitPrototype* >::iterator trait = this->_TTrait_Templates.begin();
  
  _currentTraits.clear();
  
  while(trait != this->_TTrait_Templates.end()) {
    
    if( (*trait)->get_paramset()->isSet() ){
      _currentTraits[(*trait)->get_type()] = (*trait);
    }
    
    trait++;
  }
  
  return _currentTraits;
}
void SimBuilder::build_LifeCycle ( )

Selects the life cycle events that have their parameters set.

Definition at line 602 of file basicsimulation.cc.

References ComponentManager::_LCE_Templates, and _LifeCycle.

Referenced by SimRunner::setLifeCycle().

{
  //build the list of the life cycle events for this simulation:
  list< LifeCycleEvent* >::iterator LCE = this->_LCE_Templates.begin();
  
  _LifeCycle.clear();
  
  
  while(LCE != this->_LCE_Templates.end()) {
    if( (*LCE)->get_paramset()->isSet() ){
#ifdef _DEBUG_
    cout <<"adding LCE "<< (*LCE)->get_event_name() <<" : "<< (*LCE)->get_rank() << endl;
#endif
      _LifeCycle[(int)(*LCE)->get_rank()] = (*LCE);
    }
    LCE++;
  }

}
LifeCycleEvent * SimBuilder::get_current_event ( string &  name)

Accessor to the list of current LCEs.

Parameters:
namethe name of the LCE
Returns:
ptr to the LCE

Definition at line 540 of file basicsimulation.cc.

References _LifeCycle.

Referenced by SimRunner::run_event().

{
  LCE_ITER LCE = _LifeCycle.begin();
  
  while(LCE != _LifeCycle.end()) {
    if( LCE->second->get_event_name().compare(name) == 0)
      return LCE->second;
    LCE++;
  }
  
  return NULL;
}
TraitPrototype * SimBuilder::get_current_trait ( trait_t  type)

Accessor to the list of current trait prototypes.

Parameters:
typethe trait type
Returns:
ptr to the prototype

Definition at line 528 of file basicsimulation.cc.

References _currentTraits.

{
  TRAIT_ITER trait = _currentTraits.find(type);
  
  if(trait != _currentTraits.end())
    return trait->second;
  else
    return NULL;
}
list<ParamSet*>& SimBuilder::get_currentParams ( ) [inline]

Accessor to the list of the selected parameter sets.

Returns:
list of ParamSet

Definition at line 194 of file basicsimulation.h.

{return _currentParams;}
age_t SimBuilder::getFirstRequiredAgeInLifeCycle ( )

Definition at line 624 of file basicsimulation.cc.

References _LifeCycle, and NONE.

Referenced by Metapop::setPopulation().

{
  age_t requiredAgeClass = NONE;

  for(LCE_ITER IT = _LifeCycle.begin();
      IT != _LifeCycle.end() && requiredAgeClass == NONE;
      IT++)
    requiredAgeClass = IT->second->requiredAgeClass();
  
  return requiredAgeClass;
}

Member Data Documentation

list< ParamSet* > SimBuilder::_currentParams [protected]

List of the selected simulation components from the user defined input parameters.

Definition at line 200 of file basicsimulation.h.

Referenced by build_currentParams().

List of the selected trait prototypes from the user defined input parameters.

Definition at line 202 of file basicsimulation.h.

Referenced by build_currentTraits(), get_current_trait(), SimRunner::register_component_handlers(), and SimRunner::run().

map< int, LifeCycleEvent* > SimBuilder::_LifeCycle [protected]

List of the selected life cycle events from the user defined input parameters.

Definition at line 204 of file basicsimulation.h.

Referenced by build_LifeCycle(), get_current_event(), getFirstRequiredAgeInLifeCycle(), SimRunner::init_components(), SimRunner::register_component_handlers(), SimRunner::run(), SimRunner::setLifeCycle(), and SimRunner::step().


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