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

Generated for Nemo v2.4.0 by  doxygen 1.9.1 -- Nemo is hosted on  Download Nemo

Locations of visitors to this page
Catalogued on GSR