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