Nemo  2.3.46
stathandler.h
Go to the documentation of this file.
1 
30 #ifndef STATHANDLER_H
31 #define STATHANDLER_H
32 
33 #include <list>
34 #include <string>
35 #include <iostream>
36 #include "handler.h"
37 #include "statservices.h"
38 
39 class Metapop;
40 
41 class StatRecBase;
48 class StatHandlerBase : public Handler {
49 
50 private:
52  std::list<StatRecBase*> _stats;
53 
56 
57  typedef std::list< StatRecBase* >::iterator STAT_IT;
58 
59 protected:
62 
63 public:
64 
65  StatHandlerBase ( ) : _service(0) {}
66 
67  virtual ~StatHandlerBase ( ) { }
68 
71  Metapop* get_pop_ptr ( ) {return _service->get_pop_ptr();}
72 
73  void set_service (StatServices* srv) {_service = srv;}
74 
76 
77  unsigned int getOccurrence ( ) {return _service->getOccurrence();}
78 
79  unsigned int getNumOccurrences( ) {return _service->getNumOccurrences();}
80 
81  unsigned int getCurrentOccurrence ( ) {return _service->getCurrentOccurrence();}
82 
83  unsigned int getNbRecorders ( ) {return _stats.size();}
84 
85  std::list<StatRecBase*>& getStats ( ) {return _stats;}
86 
87  virtual void add (StatRecBase* rec) {_stats.push_back(rec);}
89 
90  virtual void reset ( );
91 
94  virtual void init ( );
96  virtual void update ( ) { }
100 
101  virtual bool setStatRecorders (std::string& token) = 0;
102 
103  virtual void clear ( ) = 0;
105 };
106 
110 template <class SH> class StatHandler: public StatHandlerBase {
111 
112 protected:
114  std::list<StatRecorder<SH>*> _recorders;
115 
116  typedef typename std::list< StatRecorder<SH>* >::iterator REC_IT;
117 
118 public:
119 
120  StatHandler( ) { }
121 
122  virtual ~StatHandler ( ) { }
123 
125  virtual void clear ( ) {_recorders.clear();}
126 
144  virtual StatRecorder<SH>* add (std::string Title, std::string Name, age_t AGE, unsigned int ARG1, unsigned int ARG2,
145  double(SH::* getStatNoArg)(void), double(SH::* getStatOneArg)(unsigned int),
146  double(SH::* getStatTwoArg)(unsigned int, unsigned int), void(SH::* setStat)(void))
147  {
148  StatRecorder<SH>* new_rec = new StatRecorder<SH>();
149 
150  new_rec->set(Title, Name, AGE, ARG1, ARG2,
151  getStatNoArg, getStatOneArg, getStatTwoArg, setStat);
152 
153  new_rec->setHandler(dynamic_cast<SH*> (this));
154 
155  _recorders.push_back(new_rec);
156 
157  StatHandlerBase::add(new_rec);
158 
159  return new_rec;
160  }
161 };
162 
163 // TraitStatHandler
164 //
168 template <class TP, class SH> class TraitStatHandler : public StatHandler<SH> {
169 protected:
174 public:
175  TraitStatHandler (TP* trait_proto);
176  virtual ~TraitStatHandler () { }
177 };
178 
179 template<class TP, class SH> TraitStatHandler<TP,SH>::TraitStatHandler(TP* trait_proto)
180 {
181  _SHLinkedTrait = trait_proto;
182  _SHLinkedTraitIndex = trait_proto->get_index();
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
std::list< StatRecBase * > & getStats()
Definition: stathandler.h:85
unsigned int getOccurrence()
Definition: stathandler.h:77
The Service class used to manage the StatHandler objects.
Definition: statservices.h:50
Template class for the LCEs StatHandler classes.
Definition: stathandler.h:189
Stores the pointers to the StatHandler's stat functions.
Definition: statrecorder.h:92
virtual ~TraitStatHandler()
Definition: stathandler.h:176
std::list< StatRecorder< SH > * >::iterator REC_IT
Definition: stathandler.h:116
StatHandler()
Definition: stathandler.h:120
unsigned int age_t
Age class flags.
Definition: types.h:46
TP * _SHLinkedTrait
Pointer to a TraitProtoype object.
Definition: stathandler.h:171
virtual bool setStatRecorders(std::string &token)=0
Top class of the metapopulation structure, contains the patches.
Definition: metapop.h:79
void set_service(StatServices *srv)
Definition: stathandler.h:73
LCE * _SHLinkedEvent
Pointer to the linked LCE.
Definition: stathandler.h:192
unsigned int getNbRecorders()
Definition: stathandler.h:83
Base class of the StatHandler class, implements the Handler interface.
Definition: stathandler.h:48
std::list< StatRecBase * >::iterator STAT_IT
Definition: stathandler.h:57
virtual void clear()=0
Base class for the StatRecorder's, declares the interface to record stat values.
Definition: statrecorder.h:38
virtual ~EventStatHandler()
Definition: stathandler.h:195
int _SHLinkedTraitIndex
Index of the trait in the Individual::Traits table.
Definition: stathandler.h:173
Template class for the trait's StatHandler.
Definition: stathandler.h:168
unsigned int getCurrentOccurrence()
Definition: stathandler.h:81
EventStatHandler(LCE *lce)
Definition: stathandler.h:198
Metapop * get_pop_ptr()
Definition: statservices.h:106
std::list< StatRecorder< SH > * > _recorders
The list of stat recorders.
Definition: stathandler.h:114
virtual void reset()
Empties the _stats list and calls clear() (defined in the derived class).
Definition: stathandler.cc:53
unsigned int getNumOccurrences()
Returns the maximum number of generation records per replicate.
Definition: statservices.h:126
Service handler (an observer).
Definition: handler.h:36
Metapop * get_pop_ptr()
Definition: stathandler.h:71
virtual void init()
Definition: stathandler.cc:39
A class to compute and store the summary statistics associated with a SimComponent.
Definition: stathandler.h:110
StatServices * _service
Link to the StatService.
Definition: stathandler.h:55
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:144
void setHandler(S *theHandler)
Sets the pointer to the StatHandler that owns this recorder.
Definition: statrecorder.h:129
unsigned int getNumOccurrences()
Definition: stathandler.h:79
Metapop * _pop
Link to the current population, set through the link to the StatService.
Definition: stathandler.h:61
TraitStatHandler(TP *trait_proto)
Definition: stathandler.h:179
StatHandlerBase()
Definition: stathandler.h:65
std::list< StatRecBase * > _stats
Link to the StatRecorder list elements in the StatHandler derived class.
Definition: stathandler.h:52
unsigned int getOccurrence()
Definition: statservices.h:118
virtual void add(StatRecBase *rec)
Definition: stathandler.h:87
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:145
virtual ~StatHandler()
Definition: stathandler.h:122
virtual void clear()
Empties the _recorders list, they are destroyed in StatHandlerBase::reset().
Definition: stathandler.h:125
virtual ~StatHandlerBase()
Definition: stathandler.h:67
unsigned int getCurrentOccurrence()
Returns the last generation recorded for current replicate.
Definition: statservices.h:136
virtual void update()
This function is left empty as the StatServices calls StatRecorder::setVal directly.
Definition: stathandler.h:96
StatServices * get_service()
Definition: stathandler.h:75

Generated for Nemo v2.3.0 by  doxygen 1.8.8 --
Catalogued on GSR