Nemo  2.4.0
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
110  _setStat(0), _myHandler(0) {}
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
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

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
151 {
152  StatRecBase::set(T, N, AGE, ARG1, ARG2);
153 
154  _getStat = getNoArg;
155  _getStatOneArg = getOneArg;
156  _getStatTwoArg = getTwoArg;
157  _setStat = setStat;
158 }
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

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.

128 {_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.

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

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.0 by  doxygen 1.9.1 -- Nemo is hosted on  Download Nemo

Locations of visitors to this page
Catalogued on GSR