SST/macro
serialize_set.h
Go to the documentation of this file.
1 #ifndef SERIALIZE_SET_H
2 #define SERIALIZE_SET_H
3 
4 #include <set>
5 #include <sprockit/unordered.h>
6 #include <sprockit/serializer.h>
7 
8 namespace sprockit {
9 
10 namespace pvt {
11 
12 template <class Set, class T>
13 void
14 serialize_set(Set& v, serializer& ser) {
15  typedef typename Set::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 = const_cast<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 = const_cast<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.insert(t);
45  }
46  break;
47  }
48  }
49 }
50 
51 } //end ns pvt
52 
53 template <class T>
54 class serialize<std::set<T> > {
55  typedef std::set<T> Set;
56  public:
57  void
58  operator()(Set& v, serializer& ser) {
59  pvt::serialize_set<Set,T>(v,ser);
60  }
61 };
62 
63 #if !SPKT_ENABLE_ORDERED_MAP
64 template <class T>
65 class serialize<spkt_unordered_set<T> > {
66  typedef spkt_unordered_set<T> Set;
67  public:
68  void
69  operator()(Set& v, serializer& ser) {
70  pvt::serialize_set<Set,T>(v,ser);
71  }
72 };
73 #endif
74 
75 }
76 
77 #endif // SERIALIZE_SET_H
void operator()(Set &v, serializer &ser)
Definition: serialize_set.h:58
void unpack(T &t)
Definition: serializer.h:75
void operator()(Set &v, serializer &ser)
Definition: serialize_set.h:69
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_set(Set &v, serializer &ser)
Definition: serialize_set.h:14