00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #ifndef _UIUC_CHARM_PUP_STL_H
00017 #define _UIUC_CHARM_PUP_STL_H
00018
00019
00020
00021
00022 #include <set>
00023 #include <vector>
00024 #include <list>
00025 #include <map>
00026 #include <string>
00027 #include <complex>
00028 #include <utility>
00029 #include "pup.h"
00030
00031
00032
00033 template <class A,class B>
00034 inline void operator|(PUP::er &p,typename std::pair<A,B> &v)
00035 {
00036 p.syncComment(PUP::sync_index);
00037 p|v.first;
00038 p.syncComment(PUP::sync_item);
00039 p|v.second;
00040 }
00041
00042 template <class A,class B>
00043 inline void operator|(PUP::er &p,typename std::pair<const A,B> &v)
00044 {
00045 p.syncComment(PUP::sync_index);
00046 p|*(A *)&v.first;
00047 p.syncComment(PUP::sync_item);
00048 p|v.second;
00049 }
00050 template <class T>
00051 inline void operator|(PUP::er &p,std::complex<T> &v)
00052 {
00053 T re=v.real(), im=v.imag();
00054 p|re; p|im;
00055 v=std::complex<T>(re,im);
00056 }
00057 template <class charType>
00058 inline void operator|(PUP::er &p,typename std::basic_string<charType> &v)
00059 {
00060 int nChar=v.length();
00061 p|nChar;
00062 if (p.isUnpacking()) {
00063 charType *buf=new charType[nChar];
00064 p(buf,nChar);
00065 v=std::basic_string<charType>(buf,nChar);
00066 delete[] buf;
00067 }
00068 else {
00069
00070 p((charType *)v.data(),nChar);
00071 }
00072 }
00073 inline void operator|(PUP::er &p,std::string &v)
00074 {
00075 p.syncComment(PUP::sync_begin_object,"std::string");
00076 int nChar=v.length();
00077 p|nChar;
00078 if (p.isUnpacking()) {
00079 char *buf=new char[nChar];
00080 p(buf,nChar);
00081 v=std::basic_string<char>(buf,nChar);
00082 delete[] buf;
00083 }
00084 else {
00085
00086 p((char *)v.data(),nChar);
00087 }
00088 p.syncComment(PUP::sync_end_object);
00089 }
00090
00091
00092
00093
00094 template <class container>
00095 inline int PUP_stl_container_size(PUP::er &p,container &c) {
00096 int nElem=c.size();
00097 p|nElem;
00098 return nElem;
00099 }
00100
00101
00102 template <class container, class dtype>
00103 inline void PUP_stl_container_items(PUP::er &p,container &c) {
00104 for (typename container::iterator it=c.begin();
00105 it!=c.end();
00106 ++it) {
00107 p.syncComment(PUP::sync_item);
00108
00109 p|*(dtype *)&(*it);
00110 }
00111 }
00112
00113 template <class container,class dtype>
00114 inline void PUP_stl_container(PUP::er &p,container &c) {
00115 p.syncComment(PUP::sync_begin_array);
00116 int nElem=PUP_stl_container_size(p,c);
00117 if (p.isUnpacking())
00118 {
00119 c.resize(0);
00120 for (int i=0;i<nElem;i++) {
00121 p.syncComment(PUP::sync_item);
00122 dtype n;
00123 p|n;
00124 c.push_back(n);
00125 }
00126 }
00127 else PUP_stl_container_items<container, dtype>(p,c);
00128 p.syncComment(PUP::sync_end_array);
00129 }
00130
00131
00132 template <class container,class dtype>
00133 inline void PUP_stl_map(PUP::er &p,container &c) {
00134 p.syncComment(PUP::sync_begin_list);
00135 int nElem=PUP_stl_container_size(p,c);
00136 if (p.isUnpacking())
00137 {
00138 for (int i=0;i<nElem;i++) {
00139 dtype n;
00140 p|n;
00141 c.insert(n);
00142 }
00143 }
00144 else PUP_stl_container_items<container, dtype>(p,c);
00145 p.syncComment(PUP::sync_end_list);
00146 }
00147
00148 template <class T>
00149 inline void operator|(PUP::er &p,typename std::vector<T> &v)
00150 { PUP_stl_container<std::vector<T>,T>(p,v); }
00151 template <class T>
00152 inline void operator|(PUP::er &p,typename std::list<T> &v)
00153 { PUP_stl_container<std::list<T>,T>(p,v); }
00154
00155 template <class V,class T,class Cmp>
00156 inline void operator|(PUP::er &p,typename std::map<V,T,Cmp> &m)
00157
00158 { PUP_stl_map<std::map<V,T,Cmp>,std::pair<V,T> >(p,m); }
00159 template <class V,class T,class Cmp>
00160 inline void operator|(PUP::er &p,typename std::multimap<V,T,Cmp> &m)
00161 { PUP_stl_map<std::multimap<V,T,Cmp>,std::pair<const V,T> >(p,m); }
00162 template <class T>
00163 inline void operator|(PUP::er &p,typename std::set<T> &m)
00164 { PUP_stl_map<std::set<T>,T >(p,m); }
00165
00166 #endif