+ added eoFunctorStat class

This commit is contained in:
Caner Candan 2012-06-14 01:05:27 +02:00
commit 0d92a48d89

View file

@ -4,6 +4,8 @@
#include <eoFunctorStore.h>
#include <utils/eoStat.h>
/** Wrapper to turn any stand-alone function and into an eoStat.
*
* 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