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

Generated for Nemo v2.4.2 by  doxygen 1.9.1

Catalogued on GSR