Nemo  2.4.0
Simulate forward-in-time genetic evolution in a spatially explicit, individual-based stochastic simulator
stathandler.h
Go to the documentation of this file.
1 
29 #ifndef STATHANDLER_H
30 #define STATHANDLER_H
31 
32 #include <list>
33 #include <string>
34 #include <iostream>
35 #include "handler.h"
36 #include "statservices.h"
37 
38 class Metapop;
39 
40 class StatRecBase;
47 class StatHandlerBase : public Handler {
48 
49 private:
51  std::list<StatRecBase*> _stats;
52 
55 
56  typedef std::list< StatRecBase* >::iterator STAT_IT;
57 
58 protected:
61 
62 public:
63 
65 
66  virtual ~StatHandlerBase ( ) { }
67 
71 
72  void set_service (StatServices* srv) {_service = srv;}
73 
75 
76  unsigned int getOccurrence ( ) {return _service->getOccurrence();}
77 
78  unsigned int getNumOccurrences( ) {return _service->getNumOccurrences();}
79 
80  unsigned int getCurrentOccurrence ( ) {return _service->getCurrentOccurrence();}
81 
82  unsigned int getNbRecorders ( ) {return _stats.size();}
83 
84  std::list<StatRecBase*>& getStats ( ) {return _stats;}
85 
86  virtual void add (StatRecBase* rec) {_stats.push_back(rec);}
88 
89  virtual void reset ( );
90 
93  virtual void init ( );
95  virtual void update ( ) { }
99 
100  virtual bool setStatRecorders (std::string& token) = 0;
101 
102  virtual void clear ( ) = 0;
104 };
105 
109 template <class SH> class StatHandler: public StatHandlerBase {
110 
111 protected:
113  std::list<StatRecorder<SH>*> _recorders;
114 
115  typedef typename std::list< StatRecorder<SH>* >::iterator REC_IT;
116 
117 public:
118 
119  StatHandler( ) { }
120 
121  virtual ~StatHandler ( ) { }
122 
124  virtual void clear ( ) {_recorders.clear();}
125 
143  virtual StatRecorder<SH>* add (std::string Title, std::string Name, age_t AGE, unsigned int ARG1, unsigned int ARG2,
144  double(SH::* getStatNoArg)(void), double(SH::* getStatOneArg)(unsigned int),
145  double(SH::* getStatTwoArg)(unsigned int, unsigned int), void(SH::* setStat)(void))
146  {
147  StatRecorder<SH>* new_rec = new StatRecorder<SH>();
148 
149  new_rec->set(Title, Name, AGE, ARG1, ARG2,
150  getStatNoArg, getStatOneArg, getStatTwoArg, setStat);
151 
152  new_rec->setHandler(dynamic_cast<SH*> (this));
153 
154  _recorders.push_back(new_rec);
155 
156  StatHandlerBase::add(new_rec);
157 
158  return new_rec;
159  }
160 };
161 
162 // TraitStatHandler
163 //
167 template <class TP, class SH> class TraitStatHandler : public StatHandler<SH> {
168 protected:
173 public:
174  TraitStatHandler (TP* trait_proto);
175  virtual ~TraitStatHandler () { }
176 };
177 
178 template<class TP, class SH> TraitStatHandler<TP,SH>::TraitStatHandler(TP* trait_proto)
179 {
180  _SHLinkedTrait = trait_proto;
181  _SHLinkedTraitIndex = trait_proto->get_index();
182 }
183 
184 
185 // EventStatHandler
186 //
189 template <class LCE, class SH> class EventStatHandler : public StatHandler<SH> {
190 protected:
193 public:
194  EventStatHandler (LCE* lce);
195  virtual ~EventStatHandler () { }
196 };
197 
198 template<class LCE, class SH> EventStatHandler<LCE,SH>::EventStatHandler(LCE* lce)
199 {
200  _SHLinkedEvent = lce;
201 }
202 
203 
204 #endif
Template class for the LCEs StatHandler classes.
Definition: stathandler.h:189
LCE * _SHLinkedEvent
Pointer to the linked LCE.
Definition: stathandler.h:192
EventStatHandler(LCE *lce)
Definition: stathandler.h:198
virtual ~EventStatHandler()
Definition: stathandler.h:195
Service handler (an observer).
Definition: handler.h:35
Top class of the metapopulation structure, contains the patches.
Definition: metapop.h:79
Base class of the StatHandler class, implements the Handler interface.
Definition: stathandler.h:47
virtual void update()
This function is left empty as the StatServices calls StatRecorder::setVal directly.
Definition: stathandler.h:95
void set_service(StatServices *srv)
Definition: stathandler.h:72
std::list< StatRecBase * > & getStats()
Definition: stathandler.h:84
Metapop * get_pop_ptr()
Definition: stathandler.h:70
std::list< StatRecBase * > _stats
Link to the StatRecorder list elements in the StatHandler derived class.
Definition: stathandler.h:51
virtual void clear()=0
unsigned int getCurrentOccurrence()
Definition: stathandler.h:80
virtual void add(StatRecBase *rec)
Definition: stathandler.h:86
virtual bool setStatRecorders(std::string &token)=0
unsigned int getOccurrence()
Definition: stathandler.h:76
std::list< StatRecBase * >::iterator STAT_IT
Definition: stathandler.h:56
virtual ~StatHandlerBase()
Definition: stathandler.h:66
virtual void reset()
Empties the _stats list and calls clear() (defined in the derived class).
Definition: stathandler.cc:52
virtual void init()
Definition: stathandler.cc:38
StatHandlerBase()
Definition: stathandler.h:64
Metapop * _pop
Link to the current population, set through the link to the StatService.
Definition: stathandler.h:60
unsigned int getNbRecorders()
Definition: stathandler.h:82
StatServices * get_service()
Definition: stathandler.h:74
StatServices * _service
Link to the StatService.
Definition: stathandler.h:54
unsigned int getNumOccurrences()
Definition: stathandler.h:78
A class to compute and store the summary statistics associated with a SimComponent.
Definition: stathandler.h:109
virtual void clear()
Empties the _recorders list, they are destroyed in StatHandlerBase::reset().
Definition: stathandler.h:124
StatHandler()
Definition: stathandler.h:119
std::list< StatRecorder< SH > * > _recorders
The list of stat recorders.
Definition: stathandler.h:113
virtual StatRecorder< SH > * add(std::string Title, std::string Name, age_t AGE, unsigned int ARG1, unsigned int ARG2, double(SH::*getStatNoArg)(void), double(SH::*getStatOneArg)(unsigned int), double(SH::*getStatTwoArg)(unsigned int, unsigned int), void(SH::*setStat)(void))
Adds a StatRecorder to the list, it is also added to the StatHandlerBase::_stats list.
Definition: stathandler.h:143
std::list< StatRecorder< SH > * >::iterator REC_IT
Definition: stathandler.h:115
virtual ~StatHandler()
Definition: stathandler.h:121
Base class for the StatRecorder's, declares the interface to record stat values.
Definition: statrecorder.h:37
void setHandler(S *theHandler)
Sets the pointer to the StatHandler that owns this recorder.
Definition: statrecorder.h:128
void set(std::string T, std::string N, age_t AGE, unsigned int ARG1, unsigned int ARG2, double(S::*getNoArg)(void), double(S::*getOneArg)(unsigned int), double(S::*getTwoArg)(unsigned int, unsigned int), void(S::*setStat)(void))
Sets the recorder attributes.
Definition: statrecorder.h:144
The Service class used to manage the StatHandler objects.
Definition: statservices.h:49
unsigned int getNumOccurrences()
Returns the maximum number of generation records per replicate.
Definition: statservices.h:125
Metapop * get_pop_ptr()
Definition: statservices.h:105
unsigned int getCurrentOccurrence()
Returns the last generation recorded for current replicate.
Definition: statservices.h:135
unsigned int getOccurrence()
Definition: statservices.h:117
Template class for the trait's StatHandler.
Definition: stathandler.h:167
virtual ~TraitStatHandler()
Definition: stathandler.h:175
int _SHLinkedTraitIndex
Index of the trait in the Individual::Traits table.
Definition: stathandler.h:172
TraitStatHandler(TP *trait_proto)
Definition: stathandler.h:178
TP * _SHLinkedTrait
Pointer to a TraitProtoype object.
Definition: stathandler.h:170
Nemo2.
unsigned int age_t
Age class flags.
Definition: types.h:45

Generated for Nemo v2.4.0 by  doxygen 1.9.1 -- Nemo is hosted on  Download Nemo

Locations of visitors to this page
Catalogued on GSR