Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

controlinterface.h

Go to the documentation of this file.
00001 /*-*-c++-*-*****************************************************************
00002                           controlinterface.h  -  description
00003                              -------------------
00004     begin                : Wed May 8 2002
00005     copyright            : (C) 2002 by Peter Haase
00006     email                : mail@p-haase.de
00007  ***************************************************************************/
00008 
00009 /***************************************************************************
00010  *                                                                         *
00011  *   This library is free software; you can redistribute it and/or         *
00012  *   modify it under the terms of the GNU Lesser General Public            *
00013  *   License as published by the Free Software Foundation; either          *
00014  *   version 2.1 of the License, or (at your option) any later version.    *
00015  *                                                                         *
00016  *   This library is distributed in the hope that it will be useful,       *
00017  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00018  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU     *
00019  *   Lesser General Public License for more details.                       *
00020  *                                                                         *
00021  *   You should have received a copy of the GNU Lesser General Public      *
00022  *   License along with this library; if not, write to the Free Software   *
00023  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston,                 *
00024  *   MA  02111-1307  USA                                                   *
00025  *                                                                         *
00026  ***************************************************************************/
00027 
00043 #ifndef SIMTHETIC_CONTROL_INTERFACE_HEADER
00044 #define SIMTHETIC_CONTROL_INTERFACE_HEADER
00045 
00046 #include <stdexcept>
00047 // yes, we really don't need any further headers
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     /* This function invokes the function that is wrapped
00115        by this control interface.
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 

Generated on Mon Apr 24 21:19:19 2006 for simthetic by  doxygen 1.4.1