Nemo  2.3.56
Simulate forward-in-time genetic evolution in a spatially explicit, individual-based stochastic simulator
statrecorder.h
Go to the documentation of this file.
1
29#ifndef __STAT_REC_H__
30#define __STAT_REC_H__
31
32#include <string>
33#include "types.h"
34#include "output.h"
35
39
40private:
42 std::string _title;
44 std::string _name;
46 unsigned int _arg1;
47 unsigned int _arg2;
50
51public:
52
53 StatRecBase ( ) : _title(""), _name(""), _arg1(0), _arg2(0), _age(ALL) { }
54
55
56 virtual ~StatRecBase ( ) { }
57
65 void set (std::string T, std::string N, age_t AGE,
66 unsigned int ARG1, unsigned int ARG2)
67 {
68 _title = T;
69 _name = N;
70 _age = AGE;
71 _arg1 = ARG1;
72 _arg2 = ARG2;
73 }
74
77 void setName (std::string N) {_name = N;}
78 std::string getTitle ( ) {return _title;}
79 std::string getName ( ) {return _name;}
80 age_t getAge ( ) {return _age;}
81 unsigned int getArg1 ( ) {return _arg1;}
82 unsigned int getArg2 ( ) {return _arg2;}
83
85
88 virtual double setVal (age_t AGE) = 0;
89};
90
92template <class S> class StatRecorder : public StatRecBase
93{
94private:
96 double (S::* _getStat) (void);
98 double (S::* _getStatOneArg) (unsigned int);
100 double (S::* _getStatTwoArg) (unsigned int, unsigned int);
104 void (S::* _setStat) (void);
107
108public:
109
111 _setStat(0), _myHandler(0) {}
112
124 void set(std::string T, std::string N, age_t AGE, unsigned int ARG1, unsigned int ARG2,
125 double (S::* getNoArg)(void), double(S::* getOneArg)(unsigned int),
126 double(S::* getTwoArg)(unsigned int,unsigned int), void(S::* setStat)(void));
127
129 void setHandler (S* theHandler) {_myHandler = theHandler;}
130
135 virtual double setVal (age_t AGE);
136
137};
138/* _/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/ */
139//
140// ****** StatRecorder ******
141
142// ----------------------------------------------------------------------------------------
143// StatRecorder::set()
144// ----------------------------------------------------------------------------------------
145template<class S> void StatRecorder<S>::set(std::string T, std::string N, age_t AGE,
146 unsigned int ARG1,
147 unsigned int ARG2,
148 double (S::* getNoArg) (void),
149 double (S::* getOneArg)(unsigned int),
150 double (S::* getTwoArg)(unsigned int,unsigned int),
151 void (S::* setStat) (void) )
152{
153 StatRecBase::set(T, N, AGE, ARG1, ARG2);
154
155 _getStat = getNoArg;
156 _getStatOneArg = getOneArg;
157 _getStatTwoArg = getTwoArg;
158 _setStat = setStat;
159}
160// ----------------------------------------------------------------------------------------
161// StatRecorder::setVal
162// ----------------------------------------------------------------------------------------
163template<class S> double StatRecorder<S>::setVal(age_t AGE)
164{
165 double statValue = 0;
166
167 if(getAge() & AGE) {
168#ifdef _DEBUG_
169 message(" %s",getName().c_str());
170#endif
171 //run _setStat if exists
172 if(_setStat != 0) (_myHandler->*_setStat)();
173
174 //get the value:
175 if(_getStat != 0)
176
177 statValue = (_myHandler->*_getStat)();
178
179 else if(_getStatOneArg != 0)
180
181 statValue = (_myHandler->*_getStatOneArg)(getArg1());
182
183 else if(_getStatTwoArg != 0)
184
185 statValue = (_myHandler->*_getStatTwoArg)(getArg1(), getArg2());
186
187 else {
188
189 fatal("StatRecorder \"%s\" has no _getStat funct ptr !!\n", getName().c_str());
190
191 }
192 }
193
194 return statValue;
195}
196
197#endif
198
Base class for the StatRecorder's, declares the interface to record stat values.
Definition: statrecorder.h:38
unsigned int _arg2
Definition: statrecorder.h:47
virtual ~StatRecBase()
Definition: statrecorder.h:56
age_t getAge()
Definition: statrecorder.h:80
void set(std::string T, std::string N, age_t AGE, unsigned int ARG1, unsigned int ARG2)
Sets the recorder attributes.
Definition: statrecorder.h:65
age_t _age
The age class for which this stat applies.
Definition: statrecorder.h:49
unsigned int getArg2()
Definition: statrecorder.h:82
unsigned int getArg1()
Definition: statrecorder.h:81
std::string _title
The title of the stat recorder, longer and more explicite than the name.
Definition: statrecorder.h:42
std::string getName()
Definition: statrecorder.h:79
void setName(std::string N)
Definition: statrecorder.h:77
virtual double setVal(age_t AGE)=0
Stores the value in the vector following the ordering option.
std::string getTitle()
Definition: statrecorder.h:78
std::string _name
Name of the stat, should be short (20 char) and R compliant (no '-', '+', ' ')
Definition: statrecorder.h:44
StatRecBase()
Definition: statrecorder.h:53
unsigned int _arg1
A argument to be passed to one of the function variable stored in the StatRecorder structure.
Definition: statrecorder.h:46
Stores the pointers to the StatHandler's stat functions.
Definition: statrecorder.h:93
StatRecorder()
Definition: statrecorder.h:110
void setHandler(S *theHandler)
Sets the pointer to the StatHandler that owns this recorder.
Definition: statrecorder.h:129
double(S::* _getStat)(void)
Pointer to a 'stat getter' function of S using no argument.
Definition: statrecorder.h:96
double(S::* _getStatOneArg)(unsigned int)
Pointer to a 'stat getter' function of S using a single unsigned int argument.
Definition: statrecorder.h:98
void(S::* _setStat)(void)
Pointer to a 'stat setter' function of S using no argument.
Definition: statrecorder.h:104
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 double setVal(age_t AGE)
Calls the linked stat function and returns the result.
Definition: statrecorder.h:163
double(S::* _getStatTwoArg)(unsigned int, unsigned int)
Pointer to a 'stat getter' function of S using two unsigned int arguments.
Definition: statrecorder.h:100
S * _myHandler
Pointer to the owner of this recorder.
Definition: statrecorder.h:106
void fatal(const char *str,...)
Definition: output.cc:96
void message(const char *message,...)
Definition: output.cc:40
#define ALL
All ages age class flag.
Definition: types.h:56
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