00001 /****************************************************************************** 00002 ** Copyright (c) 1992-2010 VT MAK 00003 ** All rights reserved. 00004 ******************************************************************************/ 00005 00010 00011 #ifndef lgrCommandFunctor_H_ 00012 #define lgrCommandFunctor_H_ 00013 00014 #include <vlutil/vlSmartPointers.h> 00015 00016 namespace MAKLogger 00017 { 00018 00022 class DT_DLL_LGRCORE DtCommandFunctor 00023 { 00024 public: 00026 virtual ~DtCommandFunctor() {} 00028 virtual DtResponse operator()(const DtCommand& command) = 0; 00029 }; 00030 00034 class DT_DLL_LGRCORE DtResponseFunctor 00035 { 00036 public: 00038 virtual ~DtResponseFunctor(){} 00040 virtual void operator()(DtResponse command) = 0; 00041 }; 00042 00043 00045 typedef DtBoost::shared_ptr<DtCommandFunctor> DtCommandFunctorSP; 00046 typedef DtBoost::shared_ptr<DtResponseFunctor> DtResponseFunctorSP; 00047 00048 00051 00052 template <typename T> 00053 class DtLgrCommandHandlerFunctor : public DtCommandFunctor 00054 { 00055 public: 00057 typedef DtResponse (T::*ProcCmdFunction)(const DtCommand& command); 00058 00073 DtLgrCommandHandlerFunctor(T* object,ProcCmdFunction function); 00074 00076 virtual ~DtLgrCommandHandlerFunctor(); 00077 00080 virtual DtResponse operator()(const DtCommand& command); 00081 00082 protected: 00084 T* myObject; 00086 ProcCmdFunction myFunction; 00087 }; 00088 00091 00092 template <typename T> 00093 class DtCommandInterfaceFunctor : public DtResponseFunctor 00094 { 00095 public: 00097 typedef void (T::*ProcCmdFunction)(DtResponse command); 00098 00113 DtCommandInterfaceFunctor(T* object,ProcCmdFunction function); 00114 00115 00117 virtual ~DtCommandInterfaceFunctor(); 00118 00121 virtual void operator()(DtResponse command); 00122 00123 protected: 00125 T* myObject; 00127 ProcCmdFunction myFunction; 00128 }; 00129 00132 template <typename T> 00133 DtCommandFunctorSP createHandler(T* const object, 00134 typename DtLgrCommandHandlerFunctor<T>::ProcCmdFunction function); 00135 00138 template <typename T> 00139 DtResponseFunctorSP createHandler(T* const object, 00140 typename DtCommandInterfaceFunctor<T>::ProcCmdFunction function); 00141 00142 #define lgrCommandFunctor_inl_ 00143 #include "lgrCommandFunctor.inl" 00144 #undef lgrCommandFunctor_inl_ 00145 00146 } 00147 00148 #endif 00149