Main Page   Class Hierarchy   Compound List   File List   Compound Members   File Members  

ConnectionWrap.h

Go to the documentation of this file.
00001 #ifndef CONNECTIONWRAP_H
00002 #define CONNECTIONWRAP_H
00003 #include <string>
00004 #include "Connection.h"
00005 #include "FilterConnection.h"
00006 #include "ConfigConnection.h"
00010 union ConnectionU {     //Makes for quick and dirty casting with no up or down casting
00011         Connection<char> * charConn;
00012         Connection<double> * doubleConn;
00013         Connection<float> * floatConn;
00014         Connection<short> * shortConn;
00015         FilterConnection<char>  * charFConn;
00016         FilterConnection<double>* doubleFConn;
00017         FilterConnection<float> * floatFConn;
00018         FilterConnection<short> * shortFConn;
00019         ConfigConnection        * configConn;
00020         void * voidStar;
00021 } typedef ConnectionU;
00025 #define SHORTCONN 0
00026 #define CHARCONN  1
00027 #define BYTECONN  1
00028 #define FLOATCONN 2
00029 #define DOUBLECONN 3
00030 #define CONFIGCONN 4
00031 
00036 class ConnectionWrap { //5 bytes Not too bad
00037         public:
00041         ConnectionU conn;
00045         char type;
00049         ConnectionWrap(): conn() { type = (char)0; conn.voidStar = NULL; }
00053         ConnectionWrap(void * connection,int type): conn() {
00054                 this->conn.voidStar = connection;
00055                 this->type = (char)type;
00056         }
00060         int getFileHandle() {
00061                 if (type==SHORTCONN) {
00062                         return conn.shortConn->getFileHandle();
00063                 } else if (type==CHARCONN) {
00064                         return conn.charConn->getFileHandle();
00065                 } else if (type==FLOATCONN) {
00066                         return conn.floatConn->getFileHandle();
00067                 } else if (type==DOUBLECONN) {
00068                         return conn.doubleConn->getFileHandle();
00069                 }
00070                 return 0;
00071         }
00075         bool readable() {
00076                 if (type==SHORTCONN) {
00077                         return conn.shortConn->readable();
00078                 } else if (type==CHARCONN) {
00079                         return conn.charConn->readable();
00080                 } else if (type==FLOATCONN) {
00081                         return conn.floatConn->readable();
00082                 } else if (type==DOUBLECONN) {
00083                         return conn.doubleConn->readable();
00084                 }
00085                 return 0;
00086         }
00090         string * getXML() {
00091                 if (type==SHORTCONN) {
00092                         return conn.shortFConn->getXML();
00093                 } else if (type==CHARCONN) {
00094                         return conn.charFConn->getXML();
00095                 } else if (type==FLOATCONN) {
00096                         return conn.floatFConn->getXML();
00097                 } else if (type==DOUBLECONN) {
00098                         return conn.doubleFConn->getXML();
00099                 }
00100                 return 0;
00101         }
00105         void disconnect() {
00106                 if (type==SHORTCONN) {
00107                         return conn.shortConn->disconnect();
00108                 } else if (type==CHARCONN) {
00109                         return conn.charConn->disconnect();
00110                 } else if (type==FLOATCONN) {
00111                         return conn.floatConn->disconnect();
00112                 } else if (type==DOUBLECONN) {
00113                         return conn.doubleConn->disconnect();
00114                 } else if (type==CONFIGCONN) {
00115                         return conn.configConn->disconnect();
00116                 }
00117         }
00121         void process() {
00122                 if (type==SHORTCONN) {
00123                         conn.shortFConn->process();
00124                 } else if (type==CHARCONN) {
00125                         conn.charFConn->process();
00126                 } else if (type==FLOATCONN) {
00127                         conn.floatFConn->process();
00128                 } else if (type==DOUBLECONN) {
00129                         conn.doubleFConn->process();
00130                 }
00131         }
00135         ~ConnectionWrap() {
00136                 //delete conn.voidStar;
00137                 if (conn.voidStar!=NULL) {
00138                         if (type==SHORTCONN) {
00139                                 delete conn.shortFConn;
00140                         } else if (type==CHARCONN) {
00141                                 delete conn.charFConn;
00142                         } else if (type==FLOATCONN) {
00143                                 delete conn.floatFConn;
00144                         } else if (type==DOUBLECONN) {
00145                                 delete conn.doubleFConn;
00146                         } else if (type==CONFIGCONN) {
00147                                 delete conn.configConn;
00148                         }
00149                 }
00150                 conn.voidStar = NULL;
00151         }
00156         void write(char * buffer,int size) {
00157                 if (type==SHORTCONN ) {
00158                         conn.shortConn->write((short*)buffer,size);
00159                 } else if (type==CHARCONN || type==CONFIGCONN) {
00160                         conn.charConn->write((char*)buffer,size);
00161                 } else if (type==FLOATCONN ) {
00162                         conn.floatConn->write((float*)buffer,size);
00163                 } else if (type==DOUBLECONN ) {
00164                         conn.doubleConn->write((double*)buffer,size);
00165                 } else if (type==CONFIGCONN ) {
00166                         conn.configConn->write((char*)buffer,size);
00167                 }
00168         }
00173         int read(char * buffer,int size) {
00174                 if (type==SHORTCONN ) {
00175                         return conn.shortConn->write((short*)buffer,size);
00176                 } else if (type==CHARCONN || type==CONFIGCONN) {
00177                         return conn.charConn->write((char*)buffer,size);
00178                 } else if (type==FLOATCONN ) {
00179                         return conn.floatConn->write((float*)buffer,size);
00180                 } else if (type==DOUBLECONN ) {
00181                         return conn.doubleConn->write((double*)buffer,size);
00182                 } else if (type==CONFIGCONN ) {
00183                         return conn.configConn->write((char*)buffer,size);
00184                 }
00185                 return 0;
00186         }
00190         bool readReady() {
00191                 if (type==SHORTCONN ) {
00192                         return conn.shortConn->readReady();
00193                 } else if (type==CHARCONN || type==CONFIGCONN) {
00194                         return conn.charConn->readReady();
00195                 } else if (type==FLOATCONN ) {
00196                         return conn.floatConn->readReady();
00197                 } else if (type==DOUBLECONN ) {
00198                         return conn.doubleConn->readReady();
00199                 }
00200                 return false;
00201         }
00205         bool writeReady() {
00206                 if (type==SHORTCONN ) {
00207                         return conn.shortConn->writeReady();
00208                 } else if (type==CHARCONN || type==CONFIGCONN) {
00209                         return conn.charConn->writeReady();
00210                 } else if (type==FLOATCONN ) {
00211                         return conn.floatConn->writeReady();
00212                 } else if (type==DOUBLECONN ) {
00213                         return conn.doubleConn->writeReady();
00214                 }
00215                 return false;
00216         }
00220         int getDataSize() {
00221                 if (type==SHORTCONN ) {
00222                         return conn.shortConn->getDataSize();
00223                 } else if (type==CHARCONN || type==CONFIGCONN) {
00224                         return conn.charConn->getDataSize();
00225                 } else if (type==FLOATCONN ) {
00226                         return conn.floatConn->getDataSize();
00227                 } else if (type==DOUBLECONN ) {
00228                         return conn.doubleConn->getDataSize();
00229                 }
00230                 return 0;
00231         }
00235         void disconnectFrom(ConnectionWrap * w) {
00236                 if (type==SHORTCONN && w->type ==SHORTCONN) {
00237                         ((FilterConnection<short>*)(conn.shortConn))->disconnectFrom((Connection<short>*)w->conn.shortConn);
00238                 } else if (type==CHARCONN && w->type==CHARCONN) {
00239                         ((FilterConnection<char>*)(conn.charConn))->disconnectFrom((Connection<char>*)w->conn.charConn);
00240                 } else if (type==FLOATCONN && w->type==FLOATCONN) {
00241                         ((FilterConnection<float>*)(conn.floatConn))->disconnectFrom((Connection<float>*)w->conn.floatConn);
00242                 } else if (type==DOUBLECONN && w->type==DOUBLECONN) {
00243                         ((FilterConnection<double>*)(conn.doubleConn))->disconnectFrom((Connection<double>*)w->conn.doubleConn);
00244                 } else {
00245                         throw new string("Connections are of different data types!");
00246                 }
00247         }
00251         void disconnectTo(ConnectionWrap * w) {
00252                 if (type==SHORTCONN && w->type ==SHORTCONN) {
00253                         ((FilterConnection<short>*)(conn.shortConn))->disconnectTo((FilterConnection<short>*)w->conn.shortFConn);
00254                 } else if (type==CHARCONN && w->type==CHARCONN) {
00255                         ((FilterConnection<char>*)(conn.charConn))->disconnectTo((FilterConnection<char>*)w->conn.charFConn);
00256                 } else if (type==FLOATCONN && w->type==FLOATCONN) {
00257                         ((FilterConnection<float>*)(conn.floatConn))->disconnectTo((FilterConnection<float>*)w->conn.floatFConn);
00258                 } else if (type==DOUBLECONN && w->type==DOUBLECONN) {
00259                         ((FilterConnection<double>*)(conn.doubleConn))->disconnectTo((FilterConnection<double>*)w->conn.doubleFConn);
00260                 } else {
00261                         throw new string("Connections are of different data types!");
00262                 }
00263         }
00267         void connectFrom(ConnectionWrap * w) {
00268                 if (type==SHORTCONN && w->type ==SHORTCONN) {
00269                         ((FilterConnection<short>*)(conn.shortConn))->connectFrom(*(Connection<short>*)w->conn.shortConn);
00270                 } else if (type==CHARCONN && w->type==CHARCONN) {
00271                         return ((FilterConnection<char>*)(conn.charConn))->connectFrom(*(Connection<char>*)w->conn.charConn);
00272                 } else if (type==FLOATCONN && w->type==FLOATCONN) {
00273                         return ((FilterConnection<float>*)(conn.floatConn))->connectFrom(*(Connection<float>*)w->conn.floatConn);
00274                 } else if (type==DOUBLECONN && w->type==DOUBLECONN) {
00275                         return ((FilterConnection<double>*)(conn.doubleConn))->connectFrom(*(Connection<double>*)w->conn.doubleConn);
00276                 } else {
00277                         throw new string("Connections are of different data types!");
00278                 }
00279         }
00280 };
00281 #endif

Generated on Tue Dec 17 21:14:13 2002 for AUSS_Connector by doxygen1.2.18