From 0d92a48d8969196c258de4317eaa834d55016f04 Mon Sep 17 00:00:00 2001 From: Caner Candan Date: Thu, 14 Jun 2012 01:05:27 +0200 Subject: [PATCH] + added eoFunctorStat class --- eo/src/utils/eoFuncPtrStat.h | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/eo/src/utils/eoFuncPtrStat.h b/eo/src/utils/eoFuncPtrStat.h index 316b7f42..c7728157 100644 --- a/eo/src/utils/eoFuncPtrStat.h +++ b/eo/src/utils/eoFuncPtrStat.h @@ -4,6 +4,8 @@ #include #include + + /** Wrapper to turn any stand-alone function and into an eoStat. * * The function should take an eoPop as argument. @@ -41,4 +43,38 @@ eoFuncPtrStat& makeFuncPtrStat( T (*func)(const eoPop&), eoFunctorS ); } +/** Wrapper to turn any stand-alone function and into an eoStat. + * + * The function should take an eoPop as argument. + * + * @ingroup Stats + */ +template +class eoFunctorStat : public eoStat +{ +public : + eoFunctorStat(eoUF< const eoPop&, T >& f, std::string _description = "functor") + : eoStat(T(), _description), func(f) + {} + + using eoStat::value; + + void operator()(const eoPop& pop) { + value() = func(pop); + } + +private: + eoUF< const eoPop&, T >& func; +}; + +/** + * @ingroup Stats + */ +template +eoFunctorStat& makeFunctorStat( eoUF< const eoPop&, T >& func, eoFunctorStore& store, std::string description = "func") { + return store.storeFunctor( + new eoFunctorStat( func, description) + ); +} + #endif