#ifndef eoFuncPtrStat_h #define eoFuncPtrStat_h #include #include /** Wrapper to turn any stand-alone function and into an eoStat. * * The function should take an eoPop as argument. * * @ingroup Stats */ template class eoFuncPtrStat : public eoStat { public : typedef T (*func_t)(const eoPop&); eoFuncPtrStat(func_t f, std::string _description = "func_ptr") : eoStat(T(), _description), func(f) {} using eoStat::value; void operator()(const eoPop& pop) { value() = func(pop); } private: func_t func; }; /** * @ingroup Stats */ template eoFuncPtrStat& makeFuncPtrStat( T (*func)(const eoPop&), eoFunctorStore& store, std::string description = "func") { return store.storeFunctor( new eoFuncPtrStat( func, description) ); } /** 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