00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #ifndef SOCKETS_H_INCLUDED
00019 #define SOCKETS_H_INCLUDED
00020 #include "common.h"
00021 #include "module.h"
00022
00023
00024
00025
00026
00028
00043 class Socket
00044 {
00045 public:
00047 virtual void Print(class Print& dest)
00048 {
00049 dest.print("Type not defined");
00050 }
00051
00053
00055 virtual bool IsParameter()
00056 {
00057 return (false);
00058 }
00059
00060
00061
00062
00064 virtual bool Parse(const char * string)
00065 {
00066 return(false);
00067 }
00068
00070
00072 virtual void * GetPayload(int& size)
00073 {
00074 Errorln("No payload");
00075 return(NULL);
00076 }
00077
00079
00081 virtual const char * GetType()
00082 {
00083 Errorln("Type not defined");
00084 return("");
00085 };
00086 };
00087
00088
00089 #ifdef DOXYDOC //a fudge to document the classes created from the following #define
00090
00092
00100 template<class T>
00101 class SocketT : public Socket
00102 {
00103 public:
00105 inline operator T() const;
00107
00110 inline T* GetPointer(){return(&m_data);}
00112 inline const T& operator = (const T value);
00114 inline const T& operator += (const T value);
00116 inline const T& operator -= (const T value);
00118 inline const T& operator *= (const T value);
00120 inline const T& operator /= (const T value);
00122
00124 virtual const char * GetType();
00125 virtual void Print(class Print& dest);
00127 /
00129 virtual void * GetPayload(int& size);
00130 protected:\
00131 T m_data;\
00132 }
00133 #endif
00134
00135
00136 #define DEFINE_SOCKET(C,T,P,D)\
00137 class C : public Socket\
00138 {\
00139 public:\
00140 C(){m_data = 0;}\
00141 inline operator T() const {return (m_data);}\
00142 inline T* GetPointer(){return(&m_data);}\
00143 inline const T& operator = (const T value){m_data = value; return m_data;}\
00144 inline const T& operator += (const T value){m_data += value; return m_data;}\
00145 inline const T& operator -= (const T value){m_data -= value; return m_data;}\
00146 inline const T& operator *= (const T value){m_data *= value; return m_data;}\
00147 inline const T& operator /= (const T value){m_data /= value; return m_data;}\
00148 virtual const char * GetType(){return(#C);}\
00149 virtual void Print(class Print& dest){dest.print((P)m_data,D);}\
00150 virtual void * GetPayload(int& size){size = sizeof(T);return(&m_data);}\
00151 protected:\
00152 T m_data;\
00153 };
00154
00155
00156
00157
00158 DEFINE_SOCKET(Socket8,byte,int,DEC);
00159 DEFINE_SOCKET(Socket16,short,short,DEC);
00160 DEFINE_SOCKET(Socket32,long,long,DEC);
00161 DEFINE_SOCKET(SocketF,float,float,6);
00162 #undef DEFINE_SOCKET
00163
00164
00165 #ifdef DOXYDOC //a fudge to document the classes created from the following #define
00166
00168
00182 template<class T>
00183 class ParameterT : public SocketT
00184 {
00185 public:
00187 inline operator T() const;
00189
00192 inline T* GetPointer(){return(&m_data);}
00194 inline const T& operator = (const T value);
00196 inline const T& operator += (const T value);
00198 inline const T& operator -= (const T value);
00200 inline const T& operator *= (const T value);
00202 inline const T& operator /= (const T value);
00203 virtual const char * GetType();
00204 virtual void Print(class Print& dest);
00205 virtual void * GetPayload(int& size);
00207 virtual bool IsParameter(){return (true);}
00209
00213 virtual bool Parse(const char * string){m_data = P(string);}
00214 }
00215 #endif
00216
00217
00218 #define DEFINE_PARAMETER(C,T,D,P)\
00219 class C : public D\
00220 {\
00221 public:\
00222 inline operator T() const {return (m_data);}\
00223 inline const T& operator = (const T value){m_data = value; return m_data;}\
00224 inline const T& operator += (const T value){m_data += value; return m_data;}\
00225 inline const T& operator -= (const T value){m_data -= value; return m_data;}\
00226 inline const T& operator *= (const T value){m_data *= value; return m_data;}\
00227 inline const T& operator /= (const T value){m_data /= value; return m_data;}\
00228 virtual bool IsParameter(){return (true);}\
00229 virtual bool Parse(const char * string){m_data = P(string);}\
00230 };\
00231
00232
00233
00234 DEFINE_PARAMETER(Parameter8,byte,Socket8,atoi);
00235 DEFINE_PARAMETER(Parameter16,short,Socket16,atoi);
00236 DEFINE_PARAMETER(Parameter32,long,Socket32,atoi);
00237 DEFINE_PARAMETER(ParameterF,float,SocketF,atof);
00238
00239
00240
00241 #undef DEFINE_PARAMETER
00242
00243 #ifdef DOXYDOC //a fudge to document the classes created from the following #define
00244
00246
00283 template<class T>
00284 class PlugT
00285 {
00286 public:
00288 inline operator T() const;
00290 inline void operator = (const PlugT& ptr);
00292 inline void operator = (const T value);
00294 inline const T& operator += (const T value);
00296 inline const T& operator -= (const T value);
00298 inline const T& operator *= (const T value);
00300 inline const T& operator /= (const T value);
00302 inline T * GetPointer();
00304
00306 inline bool IsConnected();
00308
00312 bool Connect(const char * name)
00314 void Invalidate();
00315 }
00316
00317 #endif
00318
00319
00320
00321 #define DEFINE_PLUG(C,T,D)\
00322 class C\
00323 {\
00324 public:\
00325 C(){m_socket = NULL;}\
00326 inline operator D() const {return (*m_socket);}\
00327 inline void operator = (const C& ptr){if(m_socket)*m_socket = *ptr.m_socket;}\
00328 inline void operator = (const D value){if(m_socket)*m_socket = value;}\
00329 inline const T& operator += (const D value){*m_socket += value; return *m_socket;}\
00330 inline const T& operator -= (const D value){*m_socket -= value; return *m_socket;}\
00331 inline const T& operator *= (const D value){*m_socket *= value; return *m_socket;}\
00332 inline const T& operator /= (const D value){*m_socket /= value; return *m_socket;}\
00333 inline D * GetPointer(){return (m_socket->GetPointer());}\
00334 inline bool IsConnected(){return(m_socket != NULL);}\
00335 bool Connect(const char * name){\
00336 m_socket = (T*)g_moduleManager.GetSocket(name,#T);\
00337 return(IsConnected());\
00338 }\
00339 void Invalidate(){m_socket = NULL;}\
00340 private:\
00341 T * m_socket;\
00342 };
00343
00344
00345 DEFINE_PLUG(Plug8,Socket8,byte);
00346 DEFINE_PLUG(Plug16,Socket16,short);
00347 DEFINE_PLUG(Plug32,Socket32,long);
00348 DEFINE_PLUG(PlugF,SocketF,float);
00349 #undef DEFINE_PLUG
00350
00351
00352 #define DEFINE_SPLICE(C,T,D)\
00353 class C : public T\
00354 {\
00355 public:\
00356 C(){m_data = 0;\
00357 m_socket = NULL;\
00358 }\
00359 inline operator D() const {return (*m_socket);}\
00360 inline void operator = (const D value){m_data = value;}\
00361 inline const D& operator += (const D value){m_data = *m_socket + value; return m_data;}\
00362 inline const D& operator -= (const D value){m_data = *m_socket - value; return m_data;}\
00363 inline const D& operator *= (const D value){m_data = *m_socket * value; return m_data;}\
00364 inline const D& operator /= (const D value){m_data = *m_socket / value; return m_data;}\
00365 inline void PassThrough(){m_data = *m_socket;}\
00366 inline bool IsConnected(){return(m_socket != NULL);}\
00367 bool Connect(const char * name){\
00368 m_socket = (T*)g_moduleManager.GetSocket(name,#T);\
00369 if(m_socket) g_moduleManager.ReplaceSocket(m_socket,this);\
00370 return(IsConnected());\
00371 }\
00372 void Invalidate(){m_socket = NULL;}\
00373 private:\
00374 T * m_socket;\
00375 };
00376
00377
00378 DEFINE_SPLICE(Splice8,Socket8,byte);
00379 DEFINE_SPLICE(Splice16,Socket16,short);
00380 DEFINE_SPLICE(Splice32,Socket32,long);
00381 DEFINE_SPLICE(SpliceF,SocketF,float);
00382 #undef DEFINE_SPLICE
00383
00384
00385 #endif //#ifndef SOCKETS_H_INCLUDED
00386
00387