00001 /* Callback function class 00002 * Borrowed from CodeGuru.com 00003 * http://www.codeguru.com/Cpp/Cpp/cpp_mfc/callbacks/article.php/c4129/ 00004 */ 00005 00006 #if !defined( _CCALLBACK_H_ ) 00007 00008 #define _CCALLBACK_H_ 00009 00010 #include "Log.h" 00011 00012 class cCallback 00013 { 00014 public: 00015 virtual void Execute(int ButtonID) const =0; 00016 virtual ~cCallback() { }; 00017 }; 00018 00019 template <class cInstance> 00020 class TCallback : public cCallback 00021 { 00022 public: 00023 TCallback() // constructor 00024 { 00025 pFunction = 0; 00026 } 00027 00028 typedef void (cInstance::*tFunction)(int Param); 00029 00030 virtual void Execute(int ButtonID) const 00031 { 00032 if (pFunction) (cInst->*pFunction)(ButtonID); 00033 else Log::s_log->Message("Error: Attempt to call uninitialized callback function"); 00034 } 00035 00036 void SetCallback (cInstance *cInstancePointer, 00037 tFunction pFunctionPointer) 00038 { 00039 cInst = cInstancePointer; 00040 pFunction = pFunctionPointer; 00041 } 00042 00043 private: 00044 cInstance *cInst; 00045 tFunction pFunction; 00046 }; 00047 00048 00049 #endif
1.4.7