Nemo  2.4.2
Simulate forward-in-time genetic evolution in a spatially explicit, individual-based stochastic simulator
StatRecorder< S > Class Template Reference

Stores the pointers to the StatHandler's stat functions. More...

#include <statrecorder.h>

+ Inheritance diagram for StatRecorder< S >:
+ Collaboration diagram for StatRecorder< S >:

Public Member Functions

 StatRecorder ()
 
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. More...
 
void setHandler (S *theHandler)
 Sets the pointer to the StatHandler that owns this recorder. More...
 
virtual double setVal (age_t AGE)
 Calls the linked stat function and returns the result. More...
 
- Public Member Functions inherited from StatRecBase
 StatRecBase ()
 
virtual ~StatRecBase ()
 
void set (std::string T, std::string N, age_t AGE, unsigned int ARG1, unsigned int ARG2)
 Sets the recorder attributes. More...
 
void setName (std::string N)
 
std::string getTitle ()
 
std::string getName ()
 
age_t getAge ()
 
unsigned int getArg1 ()
 
unsigned int getArg2 ()
 

Private Attributes

double(S::* _getStat )(void)
 Pointer to a 'stat getter' function of S using no argument. More...
 
double(S::* _getStatOneArg )(unsigned int)
 Pointer to a 'stat getter' function of S using a single unsigned int argument. More...
 
double(S::* _getStatTwoArg )(unsigned int, unsigned int)
 Pointer to a 'stat getter' function of S using two unsigned int arguments. More...
 
void(S::* _setStat )(void)
 Pointer to a 'stat setter' function of S using no argument. More...
 
S * _myHandler
 Pointer to the owner of this recorder. More...
 

Detailed Description

template<class S>
class StatRecorder< S >

Stores the pointers to the StatHandler's stat functions.

Constructor & Destructor Documentation

◆ StatRecorder()

template<class S >
StatRecorder< S >::StatRecorder ( )
inline
109  _setStat(0), _myHandler(0) {}
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
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

Member Function Documentation

◆ set()

template<class S >
void StatRecorder< S >::set ( std::string  T,
std::string  N,
age_t  AGE,
unsigned int  ARG1,
unsigned int  ARG2,
double(S::*)(void)  getNoArg,
double(S::*)(unsigned int)  getOneArg,
double(S::*)(unsigned int, unsigned int)  getTwoArg,
void(S::*)(void)  setStat 
)

Sets the recorder attributes.

Parameters
Tthe stat title
Nthe stat name (headers in the output file)
AGEage on which the stat should be processed
ARG1the frist argument to pass to the S function
ARG2the second argument to pass to the S function
getNoArgfunction ptr to a S getter, taking no arguments
getOneArgfunction ptr to a S getter with a single uint argument
getTwoArgfunction ptr to a S getter with two uint arguments
setStatptr to a setter function in class S
150 {
151  StatRecBase::set(T, N, AGE, ARG1, ARG2);
152 
153  _getStat = getNoArg;
154  _getStatOneArg = getOneArg;
155  _getStatTwoArg = getTwoArg;
156  _setStat = setStat;
157 }
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

References StatRecBase::set().

Referenced by StatHandler< SH >::add().

+ Here is the caller graph for this function:

◆ setHandler()

template<class S >
void StatRecorder< S >::setHandler ( S *  theHandler)
inline

Sets the pointer to the StatHandler that owns this recorder.

127 {_myHandler = theHandler;}

References StatRecorder< S >::_myHandler.

Referenced by StatHandler< SH >::add().

+ Here is the caller graph for this function:

◆ setVal()

template<class S >
double StatRecorder< S >::setVal ( age_t  AGE)
virtual

Calls the linked stat function and returns the result.

Returns
the stat value that will be recorded in the output file
Parameters
AGEage class on which the stat should be processed

Implements StatRecBase.

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 }
age_t getAge()
Definition: statrecorder.h:78
unsigned int getArg2()
Definition: statrecorder.h:80
unsigned int getArg1()
Definition: statrecorder.h:79
std::string getName()
Definition: statrecorder.h:77
void fatal(const char *str,...)
Definition: output.cc:98
void message(const char *message,...)
Definition: output.cc:38

References fatal(), and message().

Member Data Documentation

◆ _getStat

template<class S >
double(S::* StatRecorder< S >::_getStat) (void)
private

Pointer to a 'stat getter' function of S using no argument.

◆ _getStatOneArg

template<class S >
double(S::* StatRecorder< S >::_getStatOneArg) (unsigned int)
private

Pointer to a 'stat getter' function of S using a single unsigned int argument.

◆ _getStatTwoArg

template<class S >
double(S::* StatRecorder< S >::_getStatTwoArg) (unsigned int, unsigned int)
private

Pointer to a 'stat getter' function of S using two unsigned int arguments.

◆ _myHandler

template<class S >
S* StatRecorder< S >::_myHandler
private

Pointer to the owner of this recorder.

Referenced by StatRecorder< S >::setHandler().

◆ _setStat

template<class S >
void(S::* StatRecorder< S >::_setStat) (void)
private

Pointer to a 'stat setter' function of S using no argument.

A setter function only sets some inner variables subsequently fetched by getter's


The documentation for this class was generated from the following file:

Generated for Nemo v2.4.2 by  doxygen 1.9.1

Catalogued on GSR