00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054 #ifndef __CK_PUP_H
00055 #define __CK_PUP_H
00056
00057 #include <stdio.h>
00058
00059 #ifndef __cplusplus
00060 #error "Use pup_c.h for C programs-- pup.h is for C++ programs"
00061 #endif
00062
00063 #ifdef STANDALONE_PUP
00064 #define CmiAbort(x) { printf(x); abort(); }
00065 #else
00066 #ifndef CHARM_H
00067 # include "converse.h"
00068 #endif
00069 extern "C" void CmiAbort(const char *msg);
00070 #endif
00071
00072
00073
00074
00075 typedef struct {int is_only_a_name;} CkMigrateMessage;
00076
00077 namespace PUP {
00078
00079 #if CMK_LONG_LONG_DEFINED
00080 #define CMK_PUP_LONG_LONG long long
00081 #elif CMK___int64_DEFINED
00082 #define CMK_PUP_LONG_LONG __int64
00083 #endif
00084
00085
00086
00087 typedef enum {
00088
00089 Tchar=0,Tshort, Tint, Tlong, Tlonglong,
00090 Tuchar,Tushort,Tuint,Tulong, Tulonglong,
00091 Tfloat,Tdouble,Tlongdouble,
00092 Tbool,
00093 Tbyte,
00094 Tsync,
00095 Tpointer,
00096 dataType_last
00097 } dataType;
00098
00099
00100 typedef unsigned char myByte;
00101
00102
00103 class er;
00104 class able;
00105
00106
00107 class seekBlock {
00108 enum {maxSections=3};
00109 int secTab[maxSections+1];
00110 int nSec;
00111 int secTabOff;
00112 er &p;
00113 CmiBool hasEnded;
00114 public:
00115
00116 seekBlock(er &Np,int nSections);
00117
00118 ~seekBlock();
00119
00120
00121 void seek(int toSection);
00122
00123 void endBlock(void);
00124
00125
00126
00127 union {
00128 int off;
00129 long loff;
00130 const myByte *cptr;
00131 myByte *ptr;
00132 void *vptr;
00133 } data;
00134 };
00135
00136
00137 class er {
00138 private:
00139 er(const er &p);
00140 protected:
00142 enum {IS_USERLEVEL=0x0004,
00143 IS_DELETING =0x0008,
00144 IS_COMMENTS =0x0010,
00145 IS_RESTARTING=0x0020
00146 };
00148 enum {IS_SIZING =0x0100,
00149 IS_PACKING =0x0200,
00150 IS_UNPACKING=0x0400,
00151 TYPE_MASK =0xFF00
00152 };
00153 unsigned int PUP_er_state;
00154 #if CMK_EXPLICIT
00155 explicit
00156 #endif
00157 er(unsigned int inType): PUP_er_state(inType) {}
00158 public:
00159 virtual ~er();
00160
00161
00162 CmiBool isSizing(void) const {return (PUP_er_state&IS_SIZING)!=0?CmiTrue:CmiFalse;}
00163 CmiBool isPacking(void) const {return (PUP_er_state&IS_PACKING)!=0?CmiTrue:CmiFalse;}
00164 CmiBool isUnpacking(void) const {return (PUP_er_state&IS_UNPACKING)!=0?CmiTrue:CmiFalse;}
00165 const char * typeString() const;
00166 unsigned int getStateFlags(void) const {return PUP_er_state;}
00167
00168
00169 void becomeDeleting(void) {PUP_er_state|=IS_DELETING;}
00170 CmiBool isDeleting(void) const {return (PUP_er_state&IS_DELETING)!=0?CmiTrue:CmiFalse;}
00171
00172
00173 void becomeUserlevel(void) {PUP_er_state|=IS_USERLEVEL;}
00174 CmiBool isUserlevel(void) const {return (PUP_er_state&IS_USERLEVEL)!=0?CmiTrue:CmiFalse;}
00175
00176
00177 void becomeRestarting(void) {PUP_er_state|=IS_RESTARTING;}
00178 CmiBool isRestarting(void) const {return (PUP_er_state&IS_RESTARTING)!=0?CmiTrue:CmiFalse;}
00179
00180 CmiBool hasComments(void) const {return (PUP_er_state&IS_COMMENTS)!=0?CmiTrue:CmiFalse;}
00181
00182
00183 void operator()(signed char &v) {(*this)(&v,1);}
00184 #if CMK_SIGNEDCHAR_DIFF_CHAR
00185 void operator()(char &v) {(*this)(&v,1);}
00186 #endif
00187 void operator()(short &v) {(*this)(&v,1);}
00188 void operator()(int &v) {(*this)(&v,1);}
00189 void operator()(long &v) {(*this)(&v,1);}
00190 void operator()(unsigned char &v) {(*this)(&v,1);}
00191 void operator()(unsigned short &v) {(*this)(&v,1);}
00192 void operator()(unsigned int &v) {(*this)(&v,1);}
00193 void operator()(unsigned long &v) {(*this)(&v,1);}
00194 void operator()(float &v) {(*this)(&v,1);}
00195 void operator()(double &v) {(*this)(&v,1);}
00196 #if CMK_LONG_DOUBLE_DEFINED
00197 void operator()(long double &v) {(*this)(&v,1);}
00198 #endif
00199 void operator()(CmiBool &v) {(*this)(&v,1);}
00200 #ifdef CMK_PUP_LONG_LONG
00201 void operator()(CMK_PUP_LONG_LONG &v) {(*this)(&v,1);}
00202 void operator()(unsigned CMK_PUP_LONG_LONG &v) {(*this)(&v,1);}
00203 #endif
00204 void operator()(void* &v,void* sig) {(*this)(&v,1,sig);}
00205
00206
00207
00208 void operator()(signed char *a,int nItems)
00209 {bytes((void *)a,nItems,sizeof(signed char),Tchar);}
00210 #if CMK_SIGNEDCHAR_DIFF_CHAR
00211 void operator()(char *a,int nItems)
00212 {bytes((void *)a,nItems,sizeof(char),Tchar);}
00213 #endif
00214 void operator()(short *a,int nItems)
00215 {bytes((void *)a,nItems,sizeof(short),Tshort);}
00216 void operator()(int *a,int nItems)
00217 {bytes((void *)a,nItems,sizeof(int),Tint);}
00218 void operator()(long *a,int nItems)
00219 {bytes((void *)a,nItems,sizeof(long),Tlong);}
00220
00221
00222 void operator()(unsigned char *a,int nItems)
00223 {bytes((void *)a,nItems,sizeof(unsigned char),Tuchar);}
00224 void operator()(unsigned short *a,int nItems)
00225 {bytes((void *)a,nItems,sizeof(unsigned short),Tushort);}
00226 void operator()(unsigned int *a,int nItems)
00227 {bytes((void *)a,nItems,sizeof(unsigned int),Tuint);}
00228 void operator()(unsigned long *a,int nItems)
00229 {bytes((void *)a,nItems,sizeof(unsigned long),Tulong);}
00230
00231
00232 void operator()(float *a,int nItems)
00233 {bytes((void *)a,nItems,sizeof(float),Tfloat);}
00234 void operator()(double *a,int nItems)
00235 {bytes((void *)a,nItems,sizeof(double),Tdouble);}
00236
00237 #if CMK_LONG_DOUBLE_DEFINED
00238 void operator()(long double *a,int nItems)
00239 {bytes((void *)a,nItems,sizeof(long double),Tlongdouble);}
00240 #endif
00241
00242
00243 void operator()(CmiBool *a,int nItems)
00244 {bytes((void *)a,nItems,sizeof(CmiBool),Tbool);}
00245
00246 #ifdef CMK_PUP_LONG_LONG
00247 void operator()(CMK_PUP_LONG_LONG *a,int nItems)
00248 {bytes((void *)a,nItems,sizeof(CMK_PUP_LONG_LONG),Tlonglong);}
00249 void operator()(unsigned CMK_PUP_LONG_LONG *a,int nItems)
00250 {bytes((void *)a,nItems,sizeof(unsigned CMK_PUP_LONG_LONG),Tulonglong);}
00251 #endif
00252
00253
00254
00255 void operator()(void **a,int nItems,void *pointerSignature)
00256 {bytes((void *)a,nItems,sizeof(void *),Tpointer);}
00257
00258
00259
00260
00261
00262
00263
00264
00265
00266 void operator()(able** a)
00267 {object(a);}
00268
00269 void operator()(able& a);
00270
00272 virtual void comment(const char *message);
00273
00276 virtual void synchronize(unsigned int sync);
00277
00280 inline void syncComment(unsigned int sync,const char *message=0) {
00281 #if CMK_ERROR_CHECKING
00282 if (hasComments()) {
00283 synchronize(sync);
00284 if (message) comment(message);
00285 }
00286 #else
00287
00288 #endif
00289 }
00290
00291
00292
00293 virtual void bytes(void *p,int n,size_t itemSize,dataType t) =0;
00294 virtual void object(able** a);
00295
00296 virtual int size(void) const { return 0; }
00297
00298
00299 virtual void impl_startSeek(seekBlock &s);
00300 virtual int impl_tell(seekBlock &s);
00301 virtual void impl_seek(seekBlock &s,int off);
00302 virtual void impl_endSeek(seekBlock &s);
00303
00304
00305
00306 virtual void pupCmiAllocBuf(void **msg)
00307 {CmiAbort("Undefined PUPer:Did you use PUP_toMem or PUP_fromMem?\n");}
00308
00309
00310
00311 virtual void pupCmiAllocBuf(void **msg, int size)
00312 {CmiAbort("Undefined PUPer:Did you use PUP_toMem or PUP_fromMem?\n");}
00313 };
00314
00325 enum {
00326 sync_builtin=0x70000000,
00327 sync_begin=sync_builtin+0x01000000,
00328 sync_end=sync_builtin+0x02000000,
00329 sync_last_system=sync_builtin+0x09000000,
00330 sync_array_m=0x00100000,
00331 sync_list_m=0x00200000,
00332 sync_object_m=0x00300000,
00333
00334 sync_begin_array=sync_begin+sync_array_m,
00335 sync_begin_list=sync_begin+sync_list_m,
00336 sync_begin_object=sync_begin+sync_object_m,
00337
00338 sync_end_array=sync_end+sync_array_m,
00339 sync_end_list=sync_end+sync_list_m,
00340 sync_end_object=sync_end+sync_object_m,
00341
00342 sync_item=sync_builtin+0x00110000,
00343 sync_index=sync_builtin+0x00120000,
00344
00345 sync_last
00346 };
00347
00348
00349
00350 class sizer : public er {
00351 protected:
00352 int nBytes;
00353
00354 virtual void bytes(void *p,int n,size_t itemSize,dataType t);
00355 public:
00356
00357 sizer(void):er(IS_SIZING),nBytes(0) {}
00358
00359
00360 int size(void) const {return nBytes;}
00361 };
00362
00363 template <class T>
00364 inline int size(T &t) {
00365 PUP::sizer p; p|t; return p.size();
00366 }
00367
00368
00369 class mem : public er {
00370 protected:
00371 myByte *origBuf;
00372 myByte *buf;
00373 mem(unsigned int type,myByte *Nbuf):er(type),origBuf(Nbuf),buf(Nbuf) {}
00374 mem(const mem &p);
00375 void operator=(const mem &p);
00376
00377
00378 virtual void impl_startSeek(seekBlock &s);
00379 virtual int impl_tell(seekBlock &s);
00380 virtual void impl_seek(seekBlock &s,int off);
00381 public:
00382
00383 int size(void) const {return buf-origBuf;}
00384 };
00385
00386
00387 class toMem : public mem {
00388 protected:
00389
00390 virtual void bytes(void *p,int n,size_t itemSize,dataType t);
00391 public:
00392
00393 toMem(void *Nbuf):mem(IS_PACKING,(myByte *)Nbuf) {}
00394 };
00395 template <class T>
00396 inline void toMemBuf(T &t,void *buf,int len) {
00397 PUP::toMem p(buf);
00398 p|t;
00399 if (p.size()!=len) CmiAbort("Size mismatch during PUP::toMemBuf!\n"
00400 "This means your pup routine doesn't match during sizing and packing");
00401 }
00402
00403
00404 class fromMem : public mem {
00405 protected:
00406
00407 virtual void bytes(void *p,int n,size_t itemSize,dataType t);
00408 public:
00409
00410 fromMem(const void *Nbuf):mem(IS_UNPACKING,(myByte *)Nbuf) {}
00411 };
00412 template <class T>
00413 inline void fromMemBuf(T &t,void *buf,int len) {
00414 PUP::fromMem p(buf);
00415 p|t;
00416 if (p.size()!=len) CmiAbort("Size mismatch during PUP::fromMemBuf!\n"
00417 "This means your pup routine doesn't match during packing and unpacking");
00418 }
00419
00420
00421 class disk : public er {
00422 protected:
00423 FILE *F;
00424 disk(unsigned int type,FILE *f):er(type),F(f) {}
00425 disk(const disk &p);
00426 void operator=(const disk &p);
00427
00428
00429 virtual void impl_startSeek(seekBlock &s);
00430 virtual int impl_tell(seekBlock &s);
00431 virtual void impl_seek(seekBlock &s,int off);
00432 };
00433
00434
00435 class toDisk : public disk {
00436 protected:
00437
00438 virtual void bytes(void *p,int n,size_t itemSize,dataType t);
00439 public:
00440
00441
00442
00443 toDisk(FILE *f):disk(IS_PACKING,f) {}
00444 };
00445
00446
00447 class fromDisk : public disk {
00448 protected:
00449
00450 virtual void bytes(void *p,int n,size_t itemSize,dataType t);
00451 public:
00452
00453
00454
00455 fromDisk(FILE *f):disk(IS_UNPACKING,f) {}
00456 };
00457
00458
00459 class toTextUtil : public er {
00460 private:
00461 char *cur;
00462 int level;
00463 void beginEnv(const char *type,int n=0);
00464 void endEnv(const char *type);
00465 char *beginLine(void);
00466 void endLine(void);
00467 protected:
00468 virtual char *advance(char *cur)=0;
00469 toTextUtil(unsigned int inType,char *buf);
00470 toTextUtil(const toTextUtil &p);
00471 void operator=(const toTextUtil &p);
00472 public:
00473 virtual void comment(const char *message);
00474 virtual void synchronize(unsigned int m);
00475 protected:
00476 virtual void bytes(void *p,int n,size_t itemSize,dataType t);
00477 virtual void object(able** a);
00478 };
00479
00480 class sizerText : public toTextUtil {
00481 private:
00482 char line[1000];
00483 int charCount;
00484 protected:
00485 virtual char *advance(char *cur);
00486 public:
00487 sizerText(void);
00488 int size(void) const {return charCount+1; }
00489 };
00490
00491
00492 class toText : public toTextUtil {
00493 private:
00494 char *buf;
00495 int charCount;
00496 protected:
00497 virtual char *advance(char *cur);
00498 public:
00499 toText(char *outStr);
00500 toText(const toText &p);
00501 void operator=(const toText &p);
00502 int size(void) const {return charCount+1; }
00503 };
00504
00505 class toTextFile : public er {
00506 protected:
00507 FILE *f;
00508 virtual void bytes(void *p,int n,size_t itemSize,dataType t);
00509 public:
00510
00511
00512 toTextFile(FILE *f_) :er(IS_PACKING), f(f_) {}
00513 toTextFile(const toTextFile &p);
00514 void operator=(const toTextFile &p);
00515 virtual void comment(const char *message);
00516 };
00517 class fromTextFile : public er {
00518 protected:
00519 FILE *f;
00520 int readInt(const char *fmt="%d");
00521 unsigned int readUint(const char *fmt="%u");
00522 CMK_TYPEDEF_INT8 readLongInt(const char *fmt="%lld");
00523 double readDouble(void);
00524
00525 virtual void bytes(void *p,int n,size_t itemSize,dataType t);
00526 virtual void parseError(const char *what);
00527 public:
00528
00529
00530 fromTextFile(FILE *f_) :er(IS_UNPACKING), f(f_) {}
00531 fromTextFile(const fromTextFile &p);
00532 void operator=(const fromTextFile &p);
00533 virtual void comment(const char *message);
00534 };
00535
00536
00537
00538 class machineInfo {
00539 public:
00540 typedef unsigned char myByte;
00541 myByte magic[4];
00542 myByte version;
00543
00544 myByte intBytes[4];
00545 myByte intFormat;
00546
00547 myByte floatBytes;
00548 myByte doubleBytes;
00549 myByte floatFormat;
00550
00551 myByte boolBytes;
00552 myByte pointerBytes;
00553
00554 myByte padding[1];
00555
00556
00557 CmiBool valid(void) const;
00558
00559 CmiBool needsConversion(void) const;
00560
00561
00562 static const machineInfo ¤t(void);
00563 };
00564
00566 class wrap_er : public er {
00567 protected:
00568 er &p;
00569 public:
00570 wrap_er(er &p_,unsigned int newFlags=0) :er(p_.getStateFlags()|newFlags), p(p_) {}
00571 virtual int size(void) const { return p.size(); }
00572
00573 virtual void impl_startSeek(seekBlock &s);
00574 virtual int impl_tell(seekBlock &s);
00575 virtual void impl_seek(seekBlock &s,int off);
00576 virtual void impl_endSeek(seekBlock &s);
00577 };
00578
00579
00580
00581
00582 class xlater : public wrap_er {
00583 protected:
00584 typedef void (*dataConverterFn)(int N,const myByte *in,myByte *out,int nElem);
00585
00586
00587
00588
00589 dataConverterFn convertFn[dataType_last];
00590
00591 size_t convertSize[dataType_last];
00592 void setConverterInt(const machineInfo &m,const machineInfo &cur,
00593 int isUnsigned,int intType,dataType dest);
00594
00595
00596 virtual void bytes(void *p,int n,size_t itemSize,dataType t);
00597 public:
00598 xlater(const machineInfo &fromMachine, er &fromData);
00599 };
00600
00601
00602
00603 class able {
00604 public:
00605
00606 class PUP_ID {
00607 public:
00608 enum {len=8};
00609 unsigned char hash[len];
00610 PUP_ID() {}
00611 PUP_ID(int val) {for (int i=0;i<len;i++) hash[i]=val;}
00612 PUP_ID(const char *name) {setName(name);}
00613 void setName(const char *name);
00614 CmiBool operator==(const PUP_ID &other) const {
00615 for (int i=0;i<len;i++)
00616 if (hash[i]!=other.hash[i])
00617 return CmiFalse;
00618 return CmiTrue;
00619 }
00620 void pup(er &p) {
00621 p((char *)hash,sizeof(unsigned char)*len);
00622 }
00623 void pup(er &p) const {
00624 p((char *)hash,sizeof(unsigned char)*len);
00625 }
00626 };
00627
00628 protected:
00629 able() {}
00630 able(CkMigrateMessage *) {}
00631 virtual ~able();
00632
00633 public:
00634
00635 typedef able* (*constructor_function)(void);
00636 static PUP_ID register_constructor(const char *className,
00637 constructor_function fn);
00638 static constructor_function get_constructor(const PUP_ID &id);
00639 virtual able *clone(void) const;
00640
00641
00642 virtual void pup(er &p);
00643 virtual const PUP_ID &get_PUP_ID(void) const=0;
00644 };
00645
00646
00647
00648 #define PUPable_operator_inside(className)\
00649 friend inline void operator|(PUP::er &p,className &a) {a.pup(p);}\
00650 friend inline void operator|(PUP::er &p,className* &a) {\
00651 PUP::able *pa=a; p(&pa); a=(className *)pa;\
00652 }
00653
00654
00655 #define PUPable_operator_outside(className)\
00656 inline void operator|(PUP::er &p,className &a) {a.pup(p);}\
00657 inline void operator|(PUP::er &p,className* &a) {\
00658 PUP::able *pa=a; p(&pa); a=(className *)pa;\
00659 }
00660
00661
00662
00663 #define PUPable_decl(className) \
00664 PUPable_decl_inside(className) \
00665 PUPable_operator_inside(className)
00666
00667 #define PUPable_decl_template(className) \
00668 PUPable_decl_inside_template(className) \
00669 PUPable_operator_inside(className)
00670
00671
00672 #define PUPable_decl_inside(className) \
00673 private: \
00674 static PUP::able *call_PUP_constructor(void); \
00675 static PUP::able::PUP_ID my_PUP_ID;\
00676 public:\
00677 virtual const PUP::able::PUP_ID &get_PUP_ID(void) const; \
00678 static void register_PUP_ID(const char* name);
00679
00680 #define PUPable_decl_inside_template(className) \
00681 private: \
00682 static PUP::able* call_PUP_constructor(void) { \
00683 return new className((CkMigrateMessage *)0);} \
00684 static PUP::able::PUP_ID my_PUP_ID;\
00685 public: \
00686 virtual const PUP::able::PUP_ID &get_PUP_ID(void) const { \
00687 return my_PUP_ID; } \
00688 static void register_PUP_ID(const char* name) { \
00689 my_PUP_ID=register_constructor(name,call_PUP_constructor);}
00690
00691
00692 #define PUPable_decl_outside(className) \
00693 PUPable_operator_outside(className)
00694
00695
00696 #define PUPable_decl_outside_template(templateParameters,className) \
00697 template<templateParameters> inline void operator|(PUP::er &p,className &a) {a.pup(p);} \
00698 template<templateParameters> inline void operator|(PUP::er &p,className* &a) { \
00699 PUP::able *pa=a; p(&pa); a=(className *)pa; } \
00700 template<templateParameters> PUP::able *className::call_PUP_constructor(void) { \
00701 return new className((CkMigrateMessage *)0);} \
00702 template<templateParameters> const PUP::able::PUP_ID &className::get_PUP_ID(void) const { \
00703 return className::my_PUP_ID; } \
00704 template<templateParameters> void className::register_PUP_ID(const char* name) { \
00705 my_PUP_ID=register_constructor(name,className::call_PUP_constructor);}
00706
00707
00708
00709
00710 #define PUPable_abstract(className) \
00711 public:\
00712 virtual const PUP::able::PUP_ID &get_PUP_ID(void) const =0; \
00713 PUPable_operator_inside(className)
00714
00715
00716 #define PUPable_def(className) \
00717 PUP::able *className::call_PUP_constructor(void) \
00718 { return new className((CkMigrateMessage *)0);}\
00719 const PUP::able::PUP_ID &className::get_PUP_ID(void) const\
00720 { return className::my_PUP_ID; }\
00721 PUP::able::PUP_ID className::my_PUP_ID;\
00722 void className::register_PUP_ID(const char* name)\
00723 {my_PUP_ID=register_constructor(name,\
00724 className::call_PUP_constructor);}
00725
00726
00727 #define PUPable_def_template(className) \
00728 template<> PUP::able::PUP_ID className::my_PUP_ID = 0;
00729
00730
00731 #define PUPable_reg(className) \
00732 className::register_PUP_ID(#className);
00733 #define PUPable_reg2(classIdentifier,className) \
00734 classIdentifier::register_PUP_ID(className);
00735
00736
00737 }
00738
00739 inline void operator|(PUP::er &p,PUP::able &a) {a.pup(p);}
00740 inline void operator|(PUP::er &p,PUP::able* &a) {p(&a);}
00741
00742
00743
00744
00745
00746
00747 template <class T>
00748 class CkPointer {
00749 T *allocated;
00750 T *ptr;
00751
00752 #if 0
00753
00754 CkPointer(const CkPointer<T> &src);
00755 #else
00756
00757
00758 public:
00759 CkPointer(const CkPointer<T> &src) {
00760 CmiAbort("PUPable_marshall's cannot be passed by value. Pass them only by reference!");
00761 }
00762 void operator=(const CkPointer<T> &src) {
00763 CmiAbort("PUPable_marshall's cannot be passed by value. Pass them only by reference!");
00764 }
00765 #endif
00766 protected:
00767 T *peek(void) {return ptr;}
00768 public:
00770 CkPointer(T *src)
00771 {
00772 allocated=0;
00773 ptr=src;
00774 }
00775
00777 CkPointer(void) {
00778 ptr=allocated=0;
00779 }
00780
00781 ~CkPointer() { if (allocated) delete allocated; }
00782
00785 inline operator T* () { allocated=0; return ptr; }
00786
00787 inline void pup(PUP::er &p) {
00788 bool ptrWasNull=(ptr==0);
00789
00790 PUP::able *ptr_able=ptr;
00791 p|ptr_able;
00792 ptr=(T *)ptr_able;
00793
00794 if (ptrWasNull)
00795 {
00796
00797 allocated=ptr;
00798 }
00799 }
00800 friend inline void operator|(PUP::er &p,CkPointer<T> &v) {v.pup(p);}
00801 };
00802 #define PUPable_marshall CkPointer
00803
00804
00805
00806 template<class T>
00807 class CkReference : private CkPointer<T> {
00808 public:
00810 CkReference(T &src)
00811 :CkPointer<T>(&src) { }
00812
00814 CkReference(void) {}
00815
00818 inline operator T& () { return *this->peek(); }
00819
00820 inline void pup(PUP::er &p) {CkPointer<T>::pup(p);}
00821
00822 friend inline void operator|(PUP::er &p,CkReference<T> &v) {v.pup(p);}
00823 };
00824
00825
00826 typedef PUP::er PUPer;
00827 typedef PUP::able PUPable;
00828
00829
00830
00831
00832
00833
00834
00835
00836 namespace PUP {
00844 template<class T> class as_bytes {
00845 #ifdef CK_DEFAULT_BITWISE_PUP
00846 public: enum {value=1};
00847 #else
00848 public: enum {value=0};
00849 #endif
00850 };
00851 }
00852
00853 #ifdef CK_DEFAULT_BITWISE_PUP
00855 template <class T>
00856 inline void operator|(PUP::er &p,T &t) {p((void *)&t,sizeof(T));}
00857 template <class T>
00858 inline void PUParray(PUP::er &p,T *ta,int n) { p((void *)ta,n*sizeof(T)); }
00859
00860
00861 # define PUPmarshall(type) \
00862 template<class T> inline void operator|(PUP::er &p,T &t) { t.pup(p); } \
00863 template<class T> inline void PUParray(PUP::er &p,T *t,int n) { \
00864 for (int i=0;i<n;i++) p|t[i]; \
00865 }
00866
00867 #else
00869
00872 template<class T>
00873 inline void operator|(PUP::er &p,T &t) {
00874 p.syncComment(PUP::sync_begin_object);
00875 t.pup(p);
00876 p.syncComment(PUP::sync_end_object);
00877 }
00878
00882 template<class T>
00883 inline void PUParray(PUP::er &p,T *t,int n) {
00884 p.syncComment(PUP::sync_begin_array);
00885 for (int i=0;i<n;i++) {
00886 p.syncComment(PUP::sync_item);
00887 p|t[i];
00888 }
00889 p.syncComment(PUP::sync_end_array);
00890 }
00891
00892
00893 # define PUPmarshall(type)
00894 #endif
00895 #define PUPmarshal(type) PUPmarshall(type)
00896
00897
00899 #define PUPbytes(type) \
00900 inline void operator|(PUP::er &p,type &t) {p((char *)&t,sizeof(type));} \
00901 inline void PUParray(PUP::er &p,type *ta,int n) { p((char *)ta,n*sizeof(type)); } \
00902 namespace PUP { template<> class as_bytes<type> { \
00903 public: enum {value=1}; \
00904 }; }
00905 #define PUPmarshallBytes(type) PUPbytes(type)
00906
00908 #define PUPfunctionpointer(fnPtrType) \
00909 inline void operator|(PUP::er &p,fnPtrType &t) {p((char *)&t,sizeof(fnPtrType));}
00910
00912 #define PUPenum(enumType) \
00913 inline void operator|(PUP::er &p,enumType &e) { int v=e; p|v; e=v; }
00914
00915
00920 #define PUP_BUILTIN_SUPPORT(type) \
00921 inline void operator|(PUP::er &p,type &t) {p(t);} \
00922 inline void PUParray(PUP::er &p,type *ta,int n) { p(ta,n); } \
00923 namespace PUP { template<> class as_bytes<type> { \
00924 public: enum {value=1}; \
00925 }; }
00926 PUP_BUILTIN_SUPPORT(signed char)
00927 #if CMK_SIGNEDCHAR_DIFF_CHAR
00928 PUP_BUILTIN_SUPPORT(char)
00929 #endif
00930 PUP_BUILTIN_SUPPORT(unsigned char)
00931 PUP_BUILTIN_SUPPORT(short)
00932 PUP_BUILTIN_SUPPORT(int)
00933 PUP_BUILTIN_SUPPORT(long)
00934 PUP_BUILTIN_SUPPORT(unsigned short)
00935 PUP_BUILTIN_SUPPORT(unsigned int)
00936 PUP_BUILTIN_SUPPORT(unsigned long)
00937 PUP_BUILTIN_SUPPORT(float)
00938 PUP_BUILTIN_SUPPORT(double)
00939 PUP_BUILTIN_SUPPORT(CmiBool)
00940 #if CMK_LONG_DOUBLE_DEFINED
00941 PUP_BUILTIN_SUPPORT(long double)
00942 #endif
00943 #ifdef CMK_PUP_LONG_LONG
00944 PUP_BUILTIN_SUPPORT(CMK_PUP_LONG_LONG)
00945 PUP_BUILTIN_SUPPORT(unsigned CMK_PUP_LONG_LONG)
00946 #endif
00947
00948
00949
00950
00951
00952 #define PUPn(field) \
00953 do{ if (p.hasComments()) p.comment(#field); p|field; } while(0)
00954
00955
00956 #define PUPv(field,len) \
00957 do{ if (p.hasComments()) p.comment(#field); PUParray(p,field,len); } while(0)
00958
00959
00960 #endif //def __CK_PUP_H
00961
00962