//------------------------------------------------------------------------------ // Functor callbacker -- // (C) Piero Giubilato 2008, Berkeley Lab -- //------------------------------------------------------------------------------ //______________________________________________________________________________ // {Trace} // [File name] "task_Clbk.h" // [Author] "Piero Giubilato" // [Version] "0.1" // [Modified by] "Piero Giubilato" // [Last revision] "04 Oct 2008" // [Language] "C++" // [Compiler] "Visual C++ 8.x 9.x" // [Member of] "Cool SEAL" // [Project] "SEAL" // [Description] "Functor class for generalized callback implementation" // [Key documentation] // "Visual C++ Reference Help" // {Trace} //______________________________________________________________________________ // Overloading check #ifndef task_Clbk_H #define task_Clbk_H // Application component #include "global.h" // Abstract base class class task_Clbk { public: // Two possible functions to call clbk functions. virtual void call(const int arg_0) = 0; // 1 int arg call virtual void call(const int arg_0, const int arg_1) = 0; // 2 int arg call }; // Derived specialized class for static function handling class task_clbk_ST: public task_Clbk { private: // Single pointer for static callback void (*st_Pt_1Int)(const int); // Pointer to static function with 1 int argument void (*st_Pt_2Int)(const int, const int); // Pointer to static function with 2 int argument // Pointer cleanup void clean() {st_Pt_1Int = NULL; st_Pt_2Int = NULL;} public: // Constructors - 1 or 2 int args static function task_clbk_ST(void(*_fnc_Pt)(const int)) {clean(); st_Pt_1Int = _fnc_Pt;} task_clbk_ST(void(*_fnc_Pt)(const int, const int)) {clean(); st_Pt_2Int = _fnc_Pt;} // 1 argument call void call(const int arg_0) { if (st_Pt_1Int) (*st_Pt_1Int)(arg_0); else dbg_Print("task_clbk_ST::call: unreferenced 1 arg static callback assignement!", DBG_LVL_PLAY); } // 2 arguments call void call(const int arg_0, const int arg_1) { if (st_Pt_2Int) (*st_Pt_2Int)(arg_0, arg_1); else dbg_Print("task_clbk_ST::call: unreferenced 2 arg static callback assignement!", DBG_LVL_PLAY); } }; // Derived specialized class (through templating) for member function handling template class task_clbk_MB: public task_Clbk { private: // The two paramenters for the members callback TClass* obj_Pt; // Pointer to instance void (TClass::*mb_Pt_1Int)(const int); // Pointer to member function with 1 int as argument void (TClass::*mb_Pt_2Int)(const int, const int); // Pointer to member function with 2 int as argument // Pointer cleanup void clean() {mb_Pt_1Int = NULL; mb_Pt_2Int = NULL; obj_Pt = NULL;} public: // Constructor - 1 or 2 int args member function task_clbk_MB(TClass* _obj_Pt, void(TClass::*_fnc_Pt)(const int)) {clean(); obj_Pt = _obj_Pt; mb_Pt_1Int = _fnc_Pt;} task_clbk_MB(TClass* _obj_Pt, void(TClass::*_fnc_Pt)(const int, const int)) {clean(); obj_Pt = _obj_Pt; mb_Pt_2Int = _fnc_Pt;} // 1 argument call void call(const int arg_0) { if (obj_Pt && mb_Pt_1Int) (*obj_Pt.*mb_Pt_1Int)(arg_0); else dbg_Print("task_clbk_Spec::call: unreferenced 1 arg member callback assignement!", DBG_LVL_PLAY); }; // 2 arguments call void call(const int arg_0, const int arg_1) { if (obj_Pt && mb_Pt_2Int) (*obj_Pt.*mb_Pt_2Int)(arg_0, arg_1); else dbg_Print("task_clbk_Spec::call: unreferenced 2 args member callback assignement!", DBG_LVL_PLAY); }; }; // Overloading check #endif