MStream.h

Go to the documentation of this file.
00001 
00007 #ifndef MSTREAM_H
00008 #define MSTREAM_H
00009 
00010 #include "Vector.h"
00011 #include <string.h>
00012 
00013 class StreamMessage;
00014 class Communicate;
00015 
00016 class MIStream {
00017   private:
00018     int PE, tag;
00019     StreamMessage *msg;
00020     size_t currentPos;
00021     int currentIndex;
00022     StreamMessage *early;
00023     Communicate *cobj;
00024     unsigned int checksum;
00025     MIStream *Get(char *buf, size_t len);  // get len bytes from message to buf
00026   public:
00027     MIStream(Communicate *c, int pe, int tag);
00028     ~MIStream();
00029     MIStream *get(char &data) { 
00030       return Get(&data,sizeof(char)); 
00031     }
00032     MIStream *get(unsigned char &data) { 
00033       return Get((char *)&data,sizeof(unsigned char)); 
00034     }
00035     MIStream *get(short &data) { 
00036       return Get((char *)&data, sizeof(short)); 
00037     }
00038     MIStream *get(unsigned short &data) { 
00039       return Get((char *)&data, sizeof(unsigned short)); 
00040     }
00041     MIStream *get(int &data) { 
00042       return Get((char *)&data, sizeof(int)); 
00043     }
00044     MIStream *get(unsigned int &data) { 
00045       return Get((char *)&data, sizeof(unsigned int)); 
00046     }
00047     MIStream *get(long &data) { 
00048       return Get((char *)&data, sizeof(long)); 
00049     }
00050     MIStream *get(unsigned long &data) { 
00051       return Get((char *)&data, sizeof(unsigned long)); 
00052     }
00053     MIStream *get(float &data) { 
00054       return Get((char *)&data, sizeof(float)); 
00055     }
00056     MIStream *get(double &data) { 
00057       return Get((char *)&data, sizeof(double)); 
00058     }
00059     MIStream *get(size_t len, char *data) { 
00060       return Get(data,len*sizeof(char)); 
00061     }
00062     MIStream *get(size_t len, unsigned char *data) { 
00063       return Get((char *)data,len*sizeof(unsigned char)); 
00064     }
00065     MIStream *get(size_t len, short *data) { 
00066       return Get((char *)data,len*sizeof(short)); 
00067     }
00068     MIStream *get(size_t len, unsigned short *data) { 
00069       return Get((char *)data,len*sizeof(unsigned short)); 
00070     }
00071     MIStream *get(size_t len, int *data) { 
00072       return Get((char *)data,len*sizeof(int)); 
00073     }
00074     MIStream *get(size_t len, unsigned int *data) { 
00075       return Get((char *)data,len*sizeof(unsigned int)); 
00076     }
00077     MIStream *get(size_t len, long *data) { 
00078       return Get((char *)data,len*sizeof(long)); 
00079     }
00080     MIStream *get(size_t len, unsigned long *data) { 
00081       return Get((char *)data,len*sizeof(unsigned long)); 
00082     }
00083     MIStream *get(size_t len, float *data) { 
00084       return Get((char *)data,len*sizeof(float)); 
00085     }
00086     MIStream *get(size_t len, double *data) { 
00087       return Get((char *)data,len*sizeof(double)); 
00088     }
00089     MIStream *get(size_t len, Vector *data) {
00090       return Get((char *)data, len*sizeof(Vector));
00091     }
00092     MIStream *get(Vector *data) {
00093       return Get((char *)data, sizeof(Vector));
00094     }
00095     template <class T>
00096     MIStream *get(size_t len, T *data) {
00097       return Get((char *)data, len*sizeof(T));
00098     }
00099 };
00100 
00101 class MOStream {
00102   private:
00103     int PE, tag;
00104     unsigned int bufLen;
00105     StreamMessage *msgBuf;
00106     Communicate *cobj;
00107     MOStream *Put(char *buf, size_t len); // put len bytes from buf into message
00108   public:
00109     MOStream(Communicate *c, int pe, int tag, size_t bufSize);
00110     ~MOStream();
00111     void end(void);
00112     MOStream *put(char data) { 
00113       return Put(&data,sizeof(char)); 
00114     }
00115     MOStream *put(unsigned char data) { 
00116       return Put((char *)&data,sizeof(unsigned char)); 
00117     }
00118     MOStream *put(short data) { 
00119       return Put((char *)&data, sizeof(short)); 
00120     }
00121     MOStream *put(unsigned short data) { 
00122       return Put((char *)&data, sizeof(unsigned short)); 
00123     }
00124     MOStream *put(int data) { 
00125       return Put((char *)&data, sizeof(int)); 
00126     }
00127     MOStream *put(unsigned int data) { 
00128       return Put((char *)&data, sizeof(unsigned int)); 
00129     }
00130     MOStream *put(long data) { 
00131       return Put((char *)&data, sizeof(long)); 
00132     }
00133     MOStream *put(unsigned long data) { 
00134       return Put((char *)&data, sizeof(unsigned long)); 
00135     }
00136     MOStream *put(float data) { 
00137       return Put((char *)&data, sizeof(float)); 
00138     }
00139     MOStream *put(double data) { 
00140       return Put((char *)&data, sizeof(double)); 
00141     }
00142     MOStream *put(size_t len, char *data) { 
00143       return Put(data,len*sizeof(char)); 
00144     }
00145     MOStream *put(size_t len, unsigned char *data) { 
00146       return Put((char *)data,len*sizeof(unsigned char)); 
00147     }
00148     MOStream *put(size_t len, short *data) { 
00149       return Put((char *)data,len*sizeof(short)); 
00150     }
00151     MOStream *put(size_t len, unsigned short *data) { 
00152       return Put((char *)data,len*sizeof(unsigned short)); 
00153     }
00154     MOStream *put(size_t len, int *data) { 
00155       return Put((char *)data,len*sizeof(int)); 
00156     }
00157     MOStream *put(size_t len, unsigned int *data) { 
00158       return Put((char *)data,len*sizeof(unsigned int)); 
00159     }
00160     MOStream *put(size_t len, long *data) { 
00161       return Put((char *)data,len*sizeof(long)); 
00162     }
00163     MOStream *put(size_t len, unsigned long *data) { 
00164       return Put((char *)data,len*sizeof(unsigned long)); 
00165     }
00166     MOStream *put(size_t len, float *data) { 
00167       return Put((char *)data,len*sizeof(float)); 
00168     }
00169     MOStream *put(size_t len, double *data) { 
00170       return Put((char *)data,len*sizeof(double)); 
00171     }
00172     MOStream *put(Vector *data) { 
00173       return Put((char *)data,sizeof(Vector)); 
00174     }
00175     MOStream *put(size_t len, Vector *data) { 
00176       return Put((char *)data,len*sizeof(Vector)); 
00177     }
00178     MOStream *put(char *data) {
00179       size_t length = strlen(data);
00180       put((int)length);
00181       return put(length, data);
00182     }
00183     template <class T>
00184     MOStream *put(size_t len, T *data) { 
00185       return Put((char *)data,len*sizeof(T)); 
00186     }
00187 };
00188 
00189 #endif

Generated on Mon Jul 16 01:17:14 2018 for NAMD by  doxygen 1.4.7