UpdaterServices Class Reference

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

#include <updaterservices.h>

Inheritance diagram for UpdaterServices:

Inheritance graph
[legend]
Collaboration diagram for UpdaterServices:

Collaboration graph
[legend]

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.

00074 { }

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

Definition at line 75 of file updaterservices.h.

00075 {reset();}


Member Function Documentation

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

Attach the updater to the stack.

Definition at line 89 of file updaterservices.cc.

Referenced by SimComponent::loadUpdaters().

00090 {
00091   if(!PU) return;
00092     
00093   list< Param* > params = PU->getParams();
00094   
00095   deque< unsigned int > dates;
00096     
00097   for(list<Param*>::const_iterator pit = params.begin();
00098       pit != params.end(); pit++) {
00099     
00100     dates = (*pit)->getUpdatingDates();
00101     
00102     for(unsigned int i = 0; i < dates.size(); i++) {
00103       _paramUpdater[ dates[i] ].push_back((*pit));
00104       _componentUpdater[ dates[i] ].push_back(PU);
00105     }
00106   }
00107   
00108   _updaters.push_back(PU);
00109 }

bool UpdaterServices::hasTemporals (  )  [inline]

Checks if any updater has been uploaded.

Definition at line 92 of file updaterservices.h.

Referenced by SimRunner::init_components().

00092 {return !_paramUpdater.empty();}

bool UpdaterServices::init (  )  [virtual]

Inits internals.

Implements Service.

Definition at line 39 of file updaterservices.cc.

Referenced by SimRunner::init_components().

00040 {
00041   //consolidate the lists of updaters by removing the duplicates (if they exist)
00042   for(map<unsigned int, list<ParamUpdaterBase*> >::iterator it = _componentUpdater.begin();
00043       it != _componentUpdater.end(); it++)
00044     it->second.unique();
00045   
00046   for(map<unsigned int, list<Param*> >::iterator it = _paramUpdater.begin();
00047       it != _paramUpdater.end(); it++)
00048     it->second.unique();
00049     
00050   _updaters.unique();
00051   
00052   for(list<ParamUpdaterBase*>::iterator it = _updaters.begin();
00053       it != _updaters.end(); it++)
00054     (*it)->init();
00055   
00056   return true;
00057 }

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.

Referenced by SimRunner::register_component().

00083 {
00084   sc->loadUpdaters(this);
00085 }

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

The generation time is passed to the updaters.

Definition at line 113 of file updaterservices.cc.

00114 {
00115   update_params(generation);
00116   update_components(generation);
00117 }

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

00078 {}

void UpdaterServices::reset (  )  [virtual]

Clears the containers.

Reimplemented from Service.

Definition at line 61 of file updaterservices.cc.

Referenced by SimRunner::reset_services(), and ~UpdaterServices().

00062 {
00063   map<unsigned int, list<Param*> >::iterator pit = _paramUpdater.begin();
00064   
00065   for(;pit != _paramUpdater.end(); pit++) {
00066     pit->second.clear();
00067   }
00068   _paramUpdater.clear();
00069   
00070   map<unsigned int, list<ParamUpdaterBase*> >::iterator scit = _componentUpdater.begin();
00071   
00072   for(;scit != _componentUpdater.end(); scit++) {
00073     scit->second.clear();
00074   }
00075   _componentUpdater.clear();
00076   
00077   _updaters.clear();
00078 }

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.

Referenced by notify().

00136 {
00137   map<unsigned int, list<ParamUpdaterBase*> >::iterator mit = _componentUpdater.find(generation);
00138   
00139   if(mit == _componentUpdater.end()) return;
00140   
00141   for(list<ParamUpdaterBase*>::iterator pit = mit->second.begin(); 
00142       pit != mit->second.end(); pit++) 
00143   {
00144     if( !(*pit)->update(generation) )
00145       warning("could not update component %s at generation %i.\n", 
00146               (*pit)->getComponent()->get_name().c_str(), generation);
00147     }
00148 }

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.

Referenced by notify().

00122 {
00123   map<unsigned int, list<Param*> >::iterator mit = _paramUpdater.find(generation);
00124   
00125   if(mit == _paramUpdater.end()) return;
00126   
00127   for(list<Param*>::iterator pit = mit->second.begin(); 
00128       pit != mit->second.end(); pit++)
00129     (*pit)->update(generation);
00130   
00131 }


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(), hasTemporals(), 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.1.2 by  doxygen 1.5.8 -- Nemo is hosted by  SourceForge.net Logo