SST/macro
serialize_list.h
Go to the documentation of this file.
1 #ifndef SERIALIZE_LIST_H
2 #define SERIALIZE_LIST_H
3 
4 #include <list>
5 #include <deque>
6 #include <sprockit/serializer.h>
7 
8 namespace sprockit {
9 
10 namespace pvt {
11 
12 template <class Container, class T>
13 void
14 serialize_container(Container& v, serializer& ser){
15  typedef typename Container::iterator iterator;
16  switch(ser.mode())
17  {
18  case serializer::SIZER: {
19  size_t size = v.size();
20  ser.size(size);
21  iterator it, end = v.end();
22  for (it=v.begin(); it != end; ++it){
23  T& t = *it;
24  serialize<T>()(t, ser);
25  }
26  break;
27  }
28  case serializer::PACK: {
29  size_t size = v.size();
30  ser.pack(size);
31  iterator it, end = v.end();
32  for (it=v.begin(); it != end; ++it){
33  T& t = *it;
34  serialize<T>()(t, ser);
35  }
36  break;
37  }
38  case serializer::UNPACK: {
39  size_t size;
40  ser.unpack(size);
41  for (int i=0; i < size; ++i){
42  T t;
43  serialize<T>()(t, ser);
44  v.push_back(t);
45  }
46  break;
47  }
48  }
49 }
50 
51 }
52 
53 template <class T>
54 class serialize <std::list<T> > {
55  typedef std::list<T> List;
56 public:
57  void
58  operator()(List& v, serializer& ser) {
59  pvt::serialize_container<List,T>(v,ser);
60  }
61 };
62 
63 template <class T>
64 class serialize <std::deque<T> > {
65  typedef std::deque<T> DQ;
66 public:
67  void
68  operator()(DQ& v, serializer& ser) {
69  pvt::serialize_container<DQ,T>(v,ser);
70  }
71 };
72 
73 
74 }
75 
76 #endif // SERIALIZE_LIST_H
void operator()(List &v, serializer &ser)
void unpack(T &t)
Definition: serializer.h:75
void operator()(DQ &v, serializer &ser)
SERIALIZE_MODE mode() const
Definition: serializer.h:84
This class is basically a wrapper for objects to declare the order in which their members should be s...
Definition: serializer.h:33
void serialize_container(Container &v, serializer &ser)