#ifndef HEPUSEMETHOD_H #define HEPUSEMETHOD_H // ---------------------------------------------------------------------- // // useMethod.h - definition of interface to access arbitraty method // in arbitrary classes. // // A ZMuseMethod is used to wrappe around a 'get' method while // a ZMsetMethod is used to wrappe around a 'set' method // // newUseMethod and newSetMethod are prone to memory leak if the user // change the method in the middle. // This is because the addresse of one ZMuse/setMethod is share among // several ColumnAttribs (each time you copy it, etc...). // Since newUseMethod NEED to return a new instance of ZMuseMethod // that can have polymorphism, newUseMethod have to call new. // However it is not trivial do not when to delete it. ZM_BEGIN_NAMESPACE( zmht ) /* namespace zmht { */ template class ZMuseMethod { public: virtual T evaluate() = 0; }; template class ZMsetMethod { public: virtual void set(T) = 0; }; template class ZMuseMethodImpl : public ZMuseMethod { public: typedef T (Obj::*methodPointer)(); ZMuseMethodImpl(Obj* object, methodPointer method); virtual T evaluate(); protected: Obj* _object; methodPointer _method; }; template class ZMsetMethodImpl : public ZMsetMethod { public: typedef Y (Obj::*methodPointer)(T); ZMsetMethodImpl(Obj* object, methodPointer method); virtual void set(T); protected: Obj* _object; methodPointer _method; }; #ifdef FUNCTION_TEMPLATE_PROTOTYPE_NEEDED // this two function are actually defined in useMethod.icc // the two definition perturbe gcc. template ZMuseMethod* newUseMethod(Obj* object, ZMuseMethodImpl::methodPointer method ); template ZMsetMethod* newSetMethod(Obj* object, ZMsetMethodImpl::methodPointer method ); #endif ZM_END_NAMESPACE( zmht ) /* } // namespace zmht */ #include "HepTuple/useMethod.icc" #endif // HEPUSEMETHOD_H