SST/macro
serialize.h
Go to the documentation of this file.
1 #ifndef SERIALIZE_H
2 #define SERIALIZE_H
3 
4 #include <sprockit/serializer.h>
6 #include <sprockit/debug.h>
7 
8 DeclareDebugSlot(serialize);
9 
10 namespace sprockit {
11 
12 template <class T>
13 class serialize {
14  public:
15  inline void operator()(T& t, serializer& ser){
16  ser.primitive(t);
17  }
18 };
19 
20 template <>
21 class serialize<bool> {
22  public:
23  void operator()(bool &t, serializer& ser){
24  int bval = t;
25  ser.primitive(bval);
26  t = bool(bval);
27  }
28 };
29 
30 namespace pvt {
31 
32 void
34 
35 void
37 
38 void
40 
41 }
42 
43 
44 template <>
46 
47  public:
48  void
50  {
51  switch (ser.mode()){
52  case serializer::SIZER:
54  break;
55  case serializer::PACK:
57  break;
58  case serializer::UNPACK:
60  break;
61  }
62  }
63 
64 };
65 
66 template < typename T, typename S >
67 struct is_base_of // checks if T is a base of S
68 {
69  typedef char yes[1];
70  typedef char no[2];
71 
72  static yes& check(S*);
73  static no& check(...);
74 
75  static bool const value = sizeof(check(static_cast<T*>(0))) == sizeof(yes);
76 };
77 
78 template <class T,bool flag>
80 {
81  public:
82  void
83  operator()(serializer& ser, T*& t){
84  abort();
85  }
86 };
87 
88 template <class T>
89 class serialize_ptr<T,false>
90 {
91  public:
92  void
93  operator()(serializer& ser, T*& t){
94  ser.primitive(t);
95  }
96 };
97 
98 template <class T>
99 class serialize_ptr<T,true>
100 {
101  public:
102  void
103  operator()(serializer& ser, T*& t){
104  serializable* s = t;
105  serialize<serializable*>()(s, ser);
106  t = static_cast<T*>(s);
107  }
108 };
109 
110 inline void
111 operator&(serializer& ser, void* v){
112  ser.primitive(v);
113 }
114 
115 template <class T>
116 inline void
117 operator&(serializer& ser, T*& t){
119 }
120 
121 template <class T>
122 inline void
123 operator&(serializer& ser, T& t){
124  serialize<T>()(t, ser);
125 }
126 
127 }
128 
130 #include <sprockit/serialize_list.h>
131 #include <sprockit/serialize_map.h>
132 #include <sprockit/serialize_set.h>
135 
136 #endif // SERIALIZE_H
DeclareDebugSlot(serialize)
debug_int operator&(const debug_int &lhs, const debug_int &rhs)
Definition: debug.h:80
void operator()(bool &t, serializer &ser)
Definition: serialize.h:23
void size_serializable(serializable *s, 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 operator()(serializable *&s, serializer &ser)
Definition: serialize.h:49
void pack_serializable(serializable *s, serializer &ser)
void unpack_serializable(serializable *&s, serializer &ser)
void operator()(serializer &ser, T *&t)
Definition: serialize.h:83
void operator()(T &t, serializer &ser)
Definition: serialize.h:15
void operator()(serializer &ser, T *&t)
Definition: serialize.h:93
void operator()(serializer &ser, T *&t)
Definition: serialize.h:103
void primitive(T &t)
Definition: serializer.h:102