--- trunk/OOPSE/libmdtools/Functor.hpp 2004/01/27 19:15:20 987 +++ trunk/OOPSE/libmdtools/Functor.hpp 2004/02/03 17:10:44 1007 @@ -1,6 +1,51 @@ #ifndef _FUNCTOR_H_ #define _FUNCTOR_H_ +#include + +using namespace std; + +class ObjFunctor0{ + public: + virtual double operator()(vector&)=0; +}; + +class PtrFunctor0 : ObjFunctor0{ + + public: + + PtrFunctor0(double (*thePtrFunc)(vector&)){ + ptrFunc = thePtrFunc; + } + + virtual double operator()(vector& arg){ + return (*ptrFunc)(arg); + }; + + protected: + double (*ptrFunc)(vector&); +}; + + +//ClassMemObjFunctor class wraps a pointer pointing to a member function of a class +// +template +class ClassMemObjFunctor0 : public ObjFunctor0{ + public: + ClassMemObjFunctor0(TClass* thePtrClass, double (TClass::*thePtrFunc)(vector&)){ + ptrClass = thePtrClass; + ptrFunc = thePtrFunc; + } + + double operator()(vector& arg){ + return (*ptrClass.*ptrFunc)(arg); + } + protected: + + double (TClass::*ptrFunc)(vector&); + TClass* ptrClass; +}; + /** * Abstract class of object function which have an overloaded method * to calculate the gradient @@ -13,8 +58,6 @@ class ObjFunctor1{ }; - - //PtrFunctor class wraps a pointer which points to an objct function. // PtrFunctor can be invoked by // functor(vector&, vector&) @@ -44,8 +87,8 @@ class ClassMemObjFunctor1 : public ObjFunctor1{ ptrFunc = thePtrFunc; } - double operator()(vector&, vector&){ - return (*ptrClass.*ptrFunc))(arg, grad); + double operator()(vector&arg, vector&grad){ + return (*ptrClass.*ptrFunc)(arg, grad); } protected: