SST  6.1.0
StructuralSimulationToolkit
serialize_serializable.h
1 // Copyright 2009-2016 Sandia Corporation. Under the terms
2 // of Contract DE-AC04-94AL85000 with Sandia Corporation, the U.S.
3 // Government retains certain rights in this software.
4 //
5 // Copyright (c) 2009-2016, Sandia Corporation
6 // All rights reserved.
7 //
8 // This file is part of the SST software package. For license
9 // information, see the LICENSE file in the top level directory of the
10 // distribution.
11 
12 #ifndef SERIALIZE_SERIALIZABLE_H
13 #define SERIALIZE_SERIALIZABLE_H
14 
15 #include <sst/core/serialization/serializable.h>
16 #include <sst/core/serialization/serializer.h>
17 #include <sst/core/serialization/serialize.h>
18 //#include <sprockit/ptr_type.h>
19 #include <iostream>
20 
21 namespace SST {
22 namespace Core {
23 namespace Serialization {
24 
25 namespace pvt {
26 
27 void
28 size_serializable(serializable* s, serializer& ser);
29 
30 void
31 pack_serializable(serializable* s, serializer& ser);
32 
33 void
34 unpack_serializable(serializable*& s, serializer& ser);
35 
36 }
37 
38 template <>
40 
41 public:
42 void
43 operator()(serializable*& s, serializer& ser)
44 {
45  switch (ser.mode()){
46  case serializer::SIZER:
47  pvt::size_serializable(s,ser);
48  break;
49  case serializer::PACK:
50  pvt::pack_serializable(s,ser);
51  break;
52  case serializer::UNPACK:
53  pvt::unpack_serializable(s,ser);
54  break;
55  }
56 }
57 
58 };
59 
60 
61 template <class T>
62 class serialize<T*, typename std::enable_if<std::is_base_of<SST::Core::Serialization::serializable,T>::value>::type> {
63 
64 public:
65 void
66 operator()(T*& s, serializer& ser)
67 {
68  serializable* sp = static_cast<serializable*>(s);
69  switch (ser.mode()){
70  case serializer::SIZER:
71  pvt::size_serializable(sp,ser);
72  break;
73  case serializer::PACK:
74  pvt::pack_serializable(sp,ser);
75  break;
76  case serializer::UNPACK:
77  pvt::unpack_serializable(sp,ser);
78  break;
79  }
80  s = static_cast<T*>(sp);
81 }
82 
83 };
84 
85 template <class T>
86 void
87 serialize_intrusive_ptr(T*& t, serializer& ser)
88 {
89  serializable* s = t;
90  switch (ser.mode()){
91 case serializer::SIZER:
92  pvt::size_serializable(s,ser);
93  break;
94 case serializer::PACK:
95  pvt::pack_serializable(s,ser);
96  break;
97 case serializer::UNPACK:
98  pvt::unpack_serializable(s,ser);
99  t = dynamic_cast<T*>(s);
100  break;
101  }
102 }
103 
104 template <class T>
105 class serialize <T, typename std::enable_if<std::is_base_of<SST::Core::Serialization::serializable,T>::value>::type> {
106 public:
107  inline void operator()(T& t, serializer& ser){
108  // T* tmp = &t;
109  // serialize_intrusive_ptr(tmp, ser);
110  t.serialize_order(ser);
111  }
112 };
113 
114 // Hold off on trivailly_serializable for now, as it's not really safe
115 // in the case of inheritance
116 //
117 // template <class T>
118 // class serialize <T, typename std::enable_if<std::is_base_of<SST::Core::Serialization::trivially_serializable,T>::value>::type> {
119 // public:
120 // inline void operator()(T& t, serializer& ser){
121 // ser.primitive(t);
122 // }
123 // };
124 
125 
126 }
127 }
128 }
129 
130 #endif // SERIALIZE_SERIALIZABLE_H
This class is basically a wrapper for objects to declare the order in which their members should be s...
Definition: serializer.h:35
Definition: action.cc:17
Definition: serializable.h:108
Base serialize class.
Definition: serialize.h:32