00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00043 #ifndef SIMTHETIC_CONTROL_INTERFACE_HEADER
00044 #define SIMTHETIC_CONTROL_INTERFACE_HEADER
00045
00046 #include <stdexcept>
00047
00048
00049 namespace simth
00050 {
00051
00052
00053 class Device;
00054
00055
00071 class ControlInterface
00072 {
00073 public:
00074 virtual ~ControlInterface() {} ;
00075 };
00076
00080 class ControlInterfaceVoid : public ControlInterface
00081 {
00082
00083 public:
00087 virtual void callFunc() = 0;
00088 };
00089
00096 template<class D>
00097 class ControlInterfaceVoidD : public ControlInterfaceVoid
00098 {
00099 public:
00101 typedef void (D::* MEM_FUNCTION_VOID)();
00102
00103 private:
00104 D* devPtr;
00105
00106 MEM_FUNCTION_VOID func;
00107
00108 public:
00113 ControlInterfaceVoidD(D* dev, MEM_FUNCTION_VOID function);
00114
00115
00116
00117 virtual void callFunc() {(devPtr->*func)();}
00118 };
00119
00125 template<class T>
00126 class ControlInterfaceT : public ControlInterface
00127 {
00128
00129 public:
00134 virtual void callFunc(T newValue) = 0;
00135 };
00136
00143 template<class T,class D>
00144 class ControlInterfaceTD : public ControlInterfaceT<T>
00145 {
00146 public:
00149 typedef void (D::* MEM_FUNCTION_ARG)(T arg);
00150
00151 private:
00152 D* devPtr;
00153
00154 MEM_FUNCTION_ARG func;
00155
00156 public:
00157 ControlInterfaceTD(D* dev, MEM_FUNCTION_ARG function);
00158 void callFunc(T newValue) {(devPtr->*func)(newValue);}
00159
00160 };
00161
00162
00163
00164 template<class D>
00165 ControlInterfaceVoidD<D>::ControlInterfaceVoidD(D* dev, MEM_FUNCTION_VOID function)
00166 : devPtr(dev), func(function)
00167 {
00168 if(dev == NULL) {
00169 throw std::runtime_error("ControlInterface::ControlInterface: device is NULL");
00170 }
00171 }
00172
00173 template<class T, class D>
00174 ControlInterfaceTD<T,D>::ControlInterfaceTD(D* dev, MEM_FUNCTION_ARG function)
00175 : devPtr(dev), func(function)
00176 {
00177 if(dev == NULL) {
00178 throw std::runtime_error("ControlInterface::ControlInterface: device is NULL");
00179 }
00180 }
00181
00182
00183
00184 }
00185
00186 #endif
00187
00188