Nemo  2.3.56
Simulate forward-in-time genetic evolution in a spatially explicit, individual-based stochastic simulator
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
39class Metapop;
40
41class StatRecBase;
48class StatHandlerBase : public Handler {
49
50private:
52 std::list<StatRecBase*> _stats;
53
56
57 typedef std::list< StatRecBase* >::iterator STAT_IT;
58
59protected:
62
63public:
64
66
67 virtual ~StatHandlerBase ( ) { }
68
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
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
110template <class SH> class StatHandler: public StatHandlerBase {
111
112protected:
114 std::list<StatRecorder<SH>*> _recorders;
115
116 typedef typename std::list< StatRecorder<SH>* >::iterator REC_IT;
117
118public:
119
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//
168template <class TP, class SH> class TraitStatHandler : public StatHandler<SH> {
169protected:
174public:
175 TraitStatHandler (TP* trait_proto);
176 virtual ~TraitStatHandler () { }
177};
178
179template<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
186// EventStatHandler
187//
190template <class LCE, class SH> class EventStatHandler : public StatHandler<SH> {
191protected:
194public:
196 virtual ~EventStatHandler () { }
197};
198
199template<class LCE, class SH> EventStatHandler<LCE,SH>::EventStatHandler(LCE* lce)
200{
201 _SHLinkedEvent = lce;
202}
203
204
205#endif
Template class for the LCEs StatHandler classes.
Definition: stathandler.h:190
LCE * _SHLinkedEvent
Pointer to the linked LCE.
Definition: stathandler.h:193
EventStatHandler(LCE *lce)
Definition: stathandler.h:199
virtual ~EventStatHandler()
Definition: stathandler.h:196
Service handler (an observer).
Definition: handler.h:36
Top class of the metapopulation structure, contains the patches.
Definition: metapop.h:80
Base class of the StatHandler class, implements the Handler interface.
Definition: stathandler.h:48
virtual void update()
This function is left empty as the StatServices calls StatRecorder::setVal directly.
Definition: stathandler.h:96
void set_service(StatServices *srv)
Definition: stathandler.h:73
std::list< StatRecBase * > & getStats()
Definition: stathandler.h:85
Metapop * get_pop_ptr()
Definition: stathandler.h:71
std::list< StatRecBase * >::iterator STAT_IT
Definition: stathandler.h:57
std::list< StatRecBase * > _stats
Link to the StatRecorder list elements in the StatHandler derived class.
Definition: stathandler.h:52
virtual void clear()=0
unsigned int getCurrentOccurrence()
Definition: stathandler.h:81
virtual void add(StatRecBase *rec)
Definition: stathandler.h:87
virtual bool setStatRecorders(std::string &token)=0
unsigned int getOccurrence()
Definition: stathandler.h:77
virtual ~StatHandlerBase()
Definition: stathandler.h:67
virtual void reset()
Empties the _stats list and calls clear() (defined in the derived class).
Definition: stathandler.cc:53
virtual void init()
Definition: stathandler.cc:39
StatHandlerBase()
Definition: stathandler.h:65
Metapop * _pop
Link to the current population, set through the link to the StatService.
Definition: stathandler.h:61
unsigned int getNbRecorders()
Definition: stathandler.h:83
StatServices * get_service()
Definition: stathandler.h:75
StatServices * _service
Link to the StatService.
Definition: stathandler.h:55
unsigned int getNumOccurrences()
Definition: stathandler.h:79
A class to compute and store the summary statistics associated with a SimComponent.
Definition: stathandler.h:110
virtual void clear()
Empties the _recorders list, they are destroyed in StatHandlerBase::reset().
Definition: stathandler.h:125
StatHandler()
Definition: stathandler.h:120
std::list< StatRecorder< SH > * >::iterator REC_IT
Definition: stathandler.h:116
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
std::list< StatRecorder< SH > * > _recorders
The list of stat recorders.
Definition: stathandler.h:114
virtual ~StatHandler()
Definition: stathandler.h:122
Base class for the StatRecorder's, declares the interface to record stat values.
Definition: statrecorder.h:38
Stores the pointers to the StatHandler's stat functions.
Definition: statrecorder.h:93
void setHandler(S *theHandler)
Sets the pointer to the StatHandler that owns this recorder.
Definition: statrecorder.h:129
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
The Service class used to manage the StatHandler objects.
Definition: statservices.h:50
unsigned int getNumOccurrences()
Returns the maximum number of generation records per replicate.
Definition: statservices.h:126
unsigned int getCurrentOccurrence()
Returns the last generation recorded for current replicate.
Definition: statservices.h:136
Metapop * get_pop_ptr()
Definition: statservices.h:106
unsigned int getOccurrence()
Definition: statservices.h:118
Template class for the trait's StatHandler.
Definition: stathandler.h:168
virtual ~TraitStatHandler()
Definition: stathandler.h:176
int _SHLinkedTraitIndex
Index of the trait in the Individual::Traits table.
Definition: stathandler.h:173
TraitStatHandler(TP *trait_proto)
Definition: stathandler.h:179
TP * _SHLinkedTrait
Pointer to a TraitProtoype object.
Definition: stathandler.h:171
unsigned int age_t
Age class flags.
Definition: types.h:46

Generated for Nemo v2.3.56 by  doxygen 1.9.0 -- Nemo is hosted on  Download Nemo

Locations of visitors to this page
Catalogued on GSR