SST  14.0.0
StructuralSimulationToolkit
serialize_serializable.h
1 // Copyright 2009-2024 NTESS. Under the terms
2 // of Contract DE-NA0003525 with NTESS, the U.S.
3 // Government retains certain rights in this software.
4 //
5 // Copyright (c) 2009-2024, NTESS
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 SST_CORE_SERIALIZATION_SERIALIZE_SERIALIZABLE_H
13 #define SST_CORE_SERIALIZATION_SERIALIZE_SERIALIZABLE_H
14 
15 #include "sst/core/serialization/serializable.h"
16 #include "sst/core/serialization/serialize.h"
17 #include "sst/core/serialization/serializer.h"
18 
19 #include <iostream>
20 
21 namespace SST {
22 namespace Core {
23 namespace Serialization {
24 
25 namespace pvt {
26 
27 void size_serializable(serializable* s, serializer& ser);
28 
29 void pack_serializable(serializable* s, serializer& ser);
30 
31 void unpack_serializable(serializable*& s, serializer& ser);
32 
33 
34 void size_pointer(serializable* s, serializer& ser);
35 
36 void pack_pointer(serializable* s, serializer& ser);
37 
38 void unpack_pointer(serializable*& s, serializer& ser);
39 
40 } // namespace pvt
41 
42 template <>
44 {
45 
46  template <class A>
47  friend class serialize;
48  void operator()(serializable*& s, serializer& ser)
49  {
50  switch ( ser.mode() ) {
51  case serializer::SIZER:
52  pvt::size_serializable(s, ser);
53  break;
54  case serializer::PACK:
55  pvt::pack_serializable(s, ser);
56  break;
57  case serializer::UNPACK:
58  pvt::unpack_serializable(s, ser);
59  break;
60  }
61  }
62 };
63 
64 template <class T>
66  T*, typename std::enable_if<std::is_base_of<SST::Core::Serialization::serializable, T>::value>::type>
67 {
68 
69  template <class A>
70  friend class serialize;
71  void operator()(T*& s, serializer& ser)
72  {
73  serializable* sp = static_cast<serializable*>(s);
74  switch ( ser.mode() ) {
75  case serializer::SIZER:
76  pvt::size_serializable(sp, ser);
77  break;
78  case serializer::PACK:
79  pvt::pack_serializable(sp, ser);
80  break;
81  case serializer::UNPACK:
82  pvt::unpack_serializable(sp, ser);
83  break;
84  }
85  s = static_cast<T*>(sp);
86  }
87 };
88 
89 template <class T>
90 void
91 serialize_intrusive_ptr(T*& t, serializer& ser)
92 {
93  serializable* s = t;
94  switch ( ser.mode() ) {
95  case serializer::SIZER:
96  pvt::size_serializable(s, ser);
97  break;
98  case serializer::PACK:
99  pvt::pack_serializable(s, ser);
100  break;
101  case serializer::UNPACK:
102  pvt::unpack_serializable(s, ser);
103  t = dynamic_cast<T*>(s);
104  break;
105  }
106 }
107 
108 template <class T>
110  T, typename std::enable_if<std::is_base_of<SST::Core::Serialization::serializable, T>::value>::type>
111 {
112  template <class A>
113  friend class serialize;
114  inline void operator()(T& t, serializer& ser)
115  {
116  // T* tmp = &t;
117  // serialize_intrusive_ptr(tmp, ser);
118  t.serialize_order(ser);
119  }
120 };
121 
122 // Hold off on trivially_serializable for now, as it's not really safe
123 // in the case of inheritance
124 //
125 // template <class T>
126 // class serialize <T, typename
127 // std::enable_if<std::is_base_of<SST::Core::Serialization::trivially_serializable,T>::value>::type> { public:
128 // inline void operator()(T& t, serializer& ser){
129 // ser.primitive(t);
130 // }
131 // };
132 
133 } // namespace Serialization
134 } // namespace Core
135 } // namespace SST
136 
137 #endif // SST_CORE_SERIALIZATION_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
Base serialize class.
Definition: serialize.h:32
Definition: action.cc:18
Definition: serializable.h:118
Serialization "gateway" object.
Definition: serialize.h:110