00001
00002
00003
00004
00005
00006 #include <stdio.h>
00007 #include <stdlib.h>
00008 #include <string.h>
00009 #include "converse.h"
00010 #include "pup.h"
00011 #include "pup_toNetwork4.h"
00012
00013
00014
00015
00016
00017
00018 void PUP_toNetwork4_sizer::bytes(void *p,size_t n,size_t itemSize,PUP::dataType t)
00019 {
00020 switch (t) {
00021 case PUP::Tchar:
00022 case PUP::Tuchar:
00023 case PUP::Tbyte:
00024 nBytes+=n;
00025 break;
00026 default:
00027 nBytes+=n*4;
00028 }
00029 }
00030
00031 void PUP_toNetwork4_pack::bytes(void *p,size_t n,size_t itemSize,PUP::dataType t)
00032 {
00033 size_t i;
00034 switch (t) {
00035 case PUP::Tchar:
00036 case PUP::Tuchar:
00037 case PUP::Tbyte:
00038 memcpy(buf,p,n);
00039 buf+=n;
00040 break;
00041 #define casePUP_toNetwork4_type(enumName,typeName,writeAs) \
00042 case PUP::enumName: \
00043 for (i=0;i<n;i++) \
00044 w((writeAs)( ((typeName *)p)[i] ));\
00045 break
00046
00047 casePUP_toNetwork4_type(Tfloat,float,float);
00048 casePUP_toNetwork4_type(Tdouble,double,float);
00049 case PUP::Tushort:
00050 casePUP_toNetwork4_type(Tshort,short,int);
00051 case PUP::Tuint:
00052 casePUP_toNetwork4_type(Tint,int,int);
00053 case PUP::Tulong:
00054 casePUP_toNetwork4_type(Tlong,long,int);
00055 casePUP_toNetwork4_type(Tbool,bool,int);
00056 case PUP::Tsync:
00057 break;
00058 default:
00059 CmiAbort("Unrecognized type passed to PUP_toNetwork4_pack!\n");
00060 }
00061 #undef casePUP_toNetwork4_type
00062 }
00063
00064 void PUP_toNetwork4_unpack::bytes(void *p,size_t n,size_t itemSize,PUP::dataType t)
00065 {
00066 size_t i;
00067 switch (t) {
00068 case PUP::Tchar:
00069 case PUP::Tuchar:
00070 case PUP::Tbyte:
00071 memcpy(p,buf,n);
00072 buf+=n;
00073 break;
00074 #define casePUP_toNetwork4_type(enumName,typeName,readAs) \
00075 case PUP::enumName: \
00076 for (i=0;i<n;i++) \
00077 ((typeName *)p)[i]=(typeName)read_##readAs();\
00078 break
00079
00080 casePUP_toNetwork4_type(Tfloat,float,float);
00081 casePUP_toNetwork4_type(Tdouble,double,float);
00082 case PUP::Tushort:
00083 casePUP_toNetwork4_type(Tshort,short,int);
00084 case PUP::Tuint:
00085 casePUP_toNetwork4_type(Tint,int,int);
00086 case PUP::Tulong:
00087 casePUP_toNetwork4_type(Tlong,long,int);
00088 casePUP_toNetwork4_type(Tbool,bool,int);
00089 case PUP::Tsync:
00090 break;
00091 default:
00092 CmiAbort("Unrecognized type passed to PUP_toNetwork4_unpack!\n");
00093 }
00094 }
00095
00096
00097