+ added eoFunctorStat class
This commit is contained in:
parent
cd94be6957
commit
0d92a48d89
1 changed files with 36 additions and 0 deletions
|
|
@ -4,6 +4,8 @@
|
||||||
#include <eoFunctorStore.h>
|
#include <eoFunctorStore.h>
|
||||||
#include <utils/eoStat.h>
|
#include <utils/eoStat.h>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/** Wrapper to turn any stand-alone function and into an eoStat.
|
/** Wrapper to turn any stand-alone function and into an eoStat.
|
||||||
*
|
*
|
||||||
* The function should take an eoPop as argument.
|
* The function should take an eoPop as argument.
|
||||||
|
|
@ -41,4 +43,38 @@ eoFuncPtrStat<EOT, T>& makeFuncPtrStat( T (*func)(const eoPop<EOT>&), eoFunctorS
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Wrapper to turn any stand-alone function and into an eoStat.
|
||||||
|
*
|
||||||
|
* The function should take an eoPop as argument.
|
||||||
|
*
|
||||||
|
* @ingroup Stats
|
||||||
|
*/
|
||||||
|
template <class EOT, class T>
|
||||||
|
class eoFunctorStat : public eoStat<EOT, T>
|
||||||
|
{
|
||||||
|
public :
|
||||||
|
eoFunctorStat(eoUF< const eoPop<EOT>&, T >& f, std::string _description = "functor")
|
||||||
|
: eoStat<EOT, T>(T(), _description), func(f)
|
||||||
|
{}
|
||||||
|
|
||||||
|
using eoStat<EOT, T>::value;
|
||||||
|
|
||||||
|
void operator()(const eoPop<EOT>& pop) {
|
||||||
|
value() = func(pop);
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
eoUF< const eoPop<EOT>&, T >& func;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @ingroup Stats
|
||||||
|
*/
|
||||||
|
template <class EOT, class T>
|
||||||
|
eoFunctorStat<EOT, T>& makeFunctorStat( eoUF< const eoPop<EOT>&, T >& func, eoFunctorStore& store, std::string description = "func") {
|
||||||
|
return store.storeFunctor(
|
||||||
|
new eoFunctorStat<EOT, T>( func, description)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
Reference in a new issue