Nemo  2.2.0
Public Member Functions | Private Attributes
UpdaterServices Class Reference

Class to update the simulation components' state during a simulation. More...

#include <updaterservices.h>

+ Inheritance diagram for UpdaterServices:
+ Collaboration diagram for UpdaterServices:

List of all members.

Public Member Functions

 UpdaterServices ()
virtual ~UpdaterServices ()
virtual bool init ()
 Inits internals.
virtual void notify ()
 Notifies all observers to update their state.
virtual void notify (unsigned int generation)
 The generation time is passed to the updaters.
virtual void load (SimComponent *sc)
 Loads the updaters in case a component's parameter has temporal arguments.
virtual void attach (ParamUpdaterBase *h)
 Attach the updater to the stack.
virtual void reset ()
 Clears the containers.
void update_params (unsigned int generation)
 Calls the parameters updating procedure.
void update_components (unsigned int generation)
 Update the components using the functions stored in the updaters.
bool hasTemporals ()
 Checks if any updater has been uploaded.

Private Attributes

map< unsigned int, list< Param * > > _paramUpdater
map< unsigned int, list
< ParamUpdaterBase * > > 
_componentUpdater
list< ParamUpdaterBase * > _updaters

Detailed Description

Class to update the simulation components' state during a simulation.

It stores the ParamUpdater objects. Each ParamUpdater stores a list of parameters from a SimComponent that use a single updating function from that component. That updating function is called to update the state of the SimComponent that declares it at a given generation during a simulation. When attaching an updater to the UpdaterServices, it is added to the _componentUpdater map and the list of its parameters is stored to the _paramUpdater map. Each map has the generation number at which the parameter/component must be updated as a key. The updaters are attached during the simulation setup (SimRunner::register_component). Each parameter set/simulation component is scanned for the presence of temporal parameters and is asked to add its updaters to the stack. The updaters will appear only once in the _updaters list as they store a single updating function although several parameters may upload the same updater. This allows several parameters to be attached to a single updater and use a single updating function from their simulation component.

The updating procedure is as follows: the parameters are first updated with their temporal argument value at the right generation. The components are then updated by using the function pointers stored in the updaters that will fetch the parameters values and update its state. Those updating functions must be implemented seperately for each component and set of parameters. The default SimComponent::setParameters function may suffice most of the time. That function is called only once and thus will update the component's state at the generations given in input by by the user.

Definition at line 64 of file updaterservices.h.


Constructor & Destructor Documentation

UpdaterServices::UpdaterServices ( ) [inline]

Definition at line 74 of file updaterservices.h.

{ }
virtual UpdaterServices::~UpdaterServices ( ) [inline, virtual]

Definition at line 75 of file updaterservices.h.

{reset();}

Member Function Documentation

void UpdaterServices::attach ( ParamUpdaterBase h) [virtual]

Attach the updater to the stack.

Definition at line 89 of file updaterservices.cc.

References _componentUpdater, _paramUpdater, _updaters, and ParamUpdaterBase::getParams().

Referenced by SimComponent::loadUpdaters().

{
  if(!PU) return;
    
  list< Param* > params = PU->getParams();
  
  deque< unsigned int > dates;
    
  for(list<Param*>::const_iterator pit = params.begin();
      pit != params.end(); pit++) {
    
    dates = (*pit)->getUpdatingDates();
    
    for(unsigned int i = 0; i < dates.size(); i++) {
      _paramUpdater[ dates[i] ].push_back((*pit));
      _componentUpdater[ dates[i] ].push_back(PU);
    }
  }
  
  _updaters.push_back(PU);
}
bool UpdaterServices::hasTemporals ( ) [inline]

Checks if any updater has been uploaded.

Definition at line 92 of file updaterservices.h.

Referenced by SimRunner::init_components().

{return !_paramUpdater.empty();}
bool UpdaterServices::init ( ) [virtual]

Inits internals.

Implements Service.

Definition at line 39 of file updaterservices.cc.

References _componentUpdater, _paramUpdater, and _updaters.

Referenced by SimRunner::init_components().

{
  //consolidate the lists of updaters by removing the duplicates (if they exist)
  for(map<unsigned int, list<ParamUpdaterBase*> >::iterator it = _componentUpdater.begin();
      it != _componentUpdater.end(); it++)
    it->second.unique();
  
  for(map<unsigned int, list<Param*> >::iterator it = _paramUpdater.begin();
      it != _paramUpdater.end(); it++)
    it->second.unique();
    
  _updaters.unique();
  
  for(list<ParamUpdaterBase*>::iterator it = _updaters.begin();
      it != _updaters.end(); it++)
    (*it)->init();
  
  return true;
}
void UpdaterServices::load ( SimComponent sc) [virtual]

Loads the updaters in case a component's parameter has temporal arguments.

Implements Service.

Definition at line 82 of file updaterservices.cc.

References SimComponent::loadUpdaters().

Referenced by SimRunner::register_component().

{
  sc->loadUpdaters(this);
}
virtual void UpdaterServices::notify ( ) [inline, virtual]

Notifies all observers to update their state.

Reimplemented from Service.

Definition at line 78 of file updaterservices.h.

Referenced by LCE_ParamUpdaterNotifier::execute(), and SimRunner::Replicate_LOOP().

{}
void UpdaterServices::notify ( unsigned int  generation) [virtual]

The generation time is passed to the updaters.

Definition at line 113 of file updaterservices.cc.

References update_components(), and update_params().

{
  update_params(generation);
  update_components(generation);
}
void UpdaterServices::reset ( ) [virtual]

Clears the containers.

Reimplemented from Service.

Definition at line 61 of file updaterservices.cc.

References _componentUpdater, _paramUpdater, and _updaters.

Referenced by SimRunner::reset_services().

{
  map<unsigned int, list<Param*> >::iterator pit = _paramUpdater.begin();
  
  for(;pit != _paramUpdater.end(); pit++) {
    pit->second.clear();
  }
  _paramUpdater.clear();
  
  map<unsigned int, list<ParamUpdaterBase*> >::iterator scit = _componentUpdater.begin();
  
  for(;scit != _componentUpdater.end(); scit++) {
    scit->second.clear();
  }
  _componentUpdater.clear();
  
  _updaters.clear();
}
void UpdaterServices::update_components ( unsigned int  generation)

Update the components using the functions stored in the updaters.

Definition at line 135 of file updaterservices.cc.

References _componentUpdater, and warning().

Referenced by notify().

{
  map<unsigned int, list<ParamUpdaterBase*> >::iterator mit = _componentUpdater.find(generation);
  
  if(mit == _componentUpdater.end()) return;
  
  for(list<ParamUpdaterBase*>::iterator pit = mit->second.begin(); 
      pit != mit->second.end(); pit++) 
  {
    if( !(*pit)->update(generation) )
      warning("could not update component %s at generation %i.\n", 
              (*pit)->getComponent()->get_name().c_str(), generation);
    }
}
void UpdaterServices::update_params ( unsigned int  generation)

Calls the parameters updating procedure.

The map is searched for the occurence of the generation.

Definition at line 121 of file updaterservices.cc.

References _paramUpdater.

Referenced by notify().

{
  map<unsigned int, list<Param*> >::iterator mit = _paramUpdater.find(generation);
  
  if(mit == _paramUpdater.end()) return;
  
  for(list<Param*>::iterator pit = mit->second.begin(); 
      pit != mit->second.end(); pit++)
    (*pit)->update(generation);
  
}

Member Data Documentation

map< unsigned int, list< ParamUpdaterBase* > > UpdaterServices::_componentUpdater [private]

Definition at line 69 of file updaterservices.h.

Referenced by attach(), init(), reset(), and update_components().

map< unsigned int, list< Param* > > UpdaterServices::_paramUpdater [private]

Definition at line 68 of file updaterservices.h.

Referenced by attach(), init(), reset(), and update_params().

Definition at line 70 of file updaterservices.h.

Referenced by attach(), init(), and reset().


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