00001
00002 #ifndef _DATAARRAY_H
00003 #define _DATAARRAY_H
00004
00005 #include <stdio.h>
00006 #include <stdarg.h>
00007 #include <cstdlib>
00008 #include <sys/stat.h>
00009 #include "alloc.h"
00010 #include "myendian.h"
00011 #include "remotesocket.h"
00012
00013 template <class Etype>
00014 int RemoteSocket::SendVar(Etype a)
00015 {
00016 #ifdef ANIDEBUG
00017 cout << "RemoteSocket::SendVar: Sending " << sizeof(Etype) << " byte element: " << a << "..." << flush;
00018 #endif
00019
00020 Etype b = setByteOrder(a);
00021 SendBytes(sizeof(Etype), &b);
00022
00023 #ifdef ANIDEBUG
00024 cout << "done!" << endl << flush;
00025 #endif
00026
00027 return 0;
00028 }
00029
00030 template <class Etype>
00031 inline Etype RemoteSocket::RecvVar()
00032 {
00033 Etype a;
00034 RecvVar(&a);
00035 return a;
00036 }
00037
00038 template <class Etype>
00039 int RemoteSocket::RecvVar(Etype *a)
00040 {
00041 #ifdef ANIDEBUG
00042 cout << "RemoteSocket::RecvVar: Receiving " << sizeof(Etype) << " byte element: " << flush;
00043 #endif
00044
00045 Etype b;
00046 RecvBytes(sizeof(Etype), &b);
00047 *a = setByteOrder(b);
00048
00049 #ifdef ANIDEBUG
00050 cout << *a << endl << flush;
00051 #endif
00052
00053 return 0;
00054 }
00055
00056 inline int RemoteSocket::SendArrayGeneric(void *a, int totsize, int elemsize)
00057 {
00058 unsigned char *data;
00059 ALLOC1D(&data, totsize);
00060
00061 memcpy(data, a, totsize);
00062 setByteOrder(data, totsize, elemsize);
00063 SendBytes(totsize, data);
00064
00065 FREE1D(&data, totsize);
00066
00067 return 0;
00068 }
00069
00070 inline int RemoteSocket::RecvArrayGeneric(void *a, int totsize, int elemsize)
00071 {
00072 RecvBytes(totsize, a);
00073 setByteOrder(reinterpret_cast<unsigned char*>(a), totsize, elemsize);
00074
00075 return 0;
00076 }
00077
00078 #endif // _DATAARRAY_H
00079