diff --git a/src/base/statistics.hh b/src/base/statistics.hh index 048c1be860..fbf8ee7698 100644 --- a/src/base/statistics.hh +++ b/src/base/statistics.hh @@ -777,6 +777,25 @@ class FunctorProxy : public ProxyInfo Result total() const { return (*functor)(); } }; +/** + * A proxy similar to the FunctorProxy, but allows calling a method of a bound + * object, instead of a global free-standing function. + */ +template +class MethodProxy : public ProxyInfo +{ + private: + T *object; + typedef V (T::*MethodPointer) () const; + MethodPointer method; + + public: + MethodProxy(T *obj, MethodPointer meth) : object(obj), method(meth) {} + Counter value() const { return (object->*method)(); } + Result result() const { return (object->*method)(); } + Result total() const { return (object->*method)(); } +}; + template class ValueBase : public DataWrap { @@ -805,6 +824,22 @@ class ValueBase : public DataWrap return this->self(); } + /** + * Extended functor that calls the specified method of the provided object. + * + * @param obj Pointer to the object whose method should be called. + * @param method Pointer of the function / method of the object. + * @return Updated stats item. + */ + template + Derived & + method(T *obj, V (T::*method)() const) + { + proxy = new MethodProxy(obj, method); + this->setInit(); + return this->self(); + } + Counter value() { return proxy->value(); } Result result() const { return proxy->result(); } Result total() const { return proxy->total(); };