00001
00007 #ifndef __FASP_MANAGER_FUNCTOR_H__
00008 #define __FASP_MANAGER_FUNCTOR_H__
00009
00010 #include "FaspManagerCommon.h"
00011
00012 namespace Aspera
00013 {
00014 namespace FaspManager
00015 {
00016
00017
00018 struct JobStats;
00019 struct FileStats;
00020
00021
00023 class Functor
00024 {
00025
00026 public:
00028 virtual ~Functor( ) { };
00029
00033 virtual Functor *Clone( ) = 0;
00034
00041 virtual void operator()(callback_event_e cb_event, const JobStats* j_stats, const FileStats* f_stats ) = 0;
00042
00045
00046 virtual bool CompareWith(const Functor* other) = 0;
00047 };
00048
00051 template <class T> class CallbackFunctor : public Functor
00052 {
00053
00054 private:
00055 T *m_obj_ptr;
00056
00057 void (T::*m_fnct_ptr)(callback_event_e cb_event, const JobStats*, const FileStats* );
00058
00059
00060 public:
00065 FASP_MANAGER_API CallbackFunctor( T *obj, void (T::*fnct)(callback_event_e cb_event, const JobStats*, const FileStats* ) ):
00066 m_obj_ptr( obj ),
00067 m_fnct_ptr( fnct )
00068 { };
00069
00073 FASP_MANAGER_API CallbackFunctor( CallbackFunctor &functor )
00074 : Functor()
00075 {
00076 m_obj_ptr = functor.m_obj_ptr;
00077 m_fnct_ptr = functor.m_fnct_ptr;
00078 };
00079
00081 FASP_MANAGER_API ~CallbackFunctor( ) { };
00082
00086 FASP_MANAGER_API Functor *Clone( )
00087 { return new CallbackFunctor( *this ); };
00088
00095 FASP_MANAGER_API void operator()(callback_event_e cb_event, const JobStats* j_stats, const FileStats* f_stats )
00096 { (m_obj_ptr->*m_fnct_ptr)(cb_event, j_stats, f_stats ); };
00097
00098 FASP_MANAGER_API bool CompareWith(const Functor* other)
00099 {
00100 if (const CallbackFunctor* cbfOther = dynamic_cast<const CallbackFunctor*>(other)) {
00101 return (m_obj_ptr == cbfOther->m_obj_ptr) && (m_fnct_ptr == cbfOther->m_fnct_ptr);
00102 }
00103 return false;
00104 }
00105 };
00106
00107
00108 }
00109 }
00110
00111 #endif