SST  14.1.0
StructuralSimulationToolkit
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_SERIALIZABLE_H
13 #define SST_CORE_SERIALIZATION_SERIALIZABLE_H
14 
15 #include "sst/core/serialization/serializable_base.h"
16 #include "sst/core/serialization/serialize.h"
17 
18 
19 namespace SST {
20 namespace Core {
21 namespace Serialization {
22 
23 
25 {
26 public:
27  static constexpr uint32_t NullClsId = std::numeric_limits<uint32_t>::max();
28 
29  // virtual const char* cls_name() const = 0;
30 
31  // virtual void serialize_order(serializer& ser) = 0;
32 
33  // virtual uint32_t cls_id() const = 0;
34  // virtual std::string serialization_name() const = 0;
35 
36  virtual ~serializable() {}
37 };
38 
39 namespace pvt {
40 
41 void size_serializable(serializable_base* s, serializer& ser);
42 
43 void pack_serializable(serializable_base* s, serializer& ser);
44 
45 void unpack_serializable(serializable_base*& s, serializer& ser);
46 
47 void map_serializable(serializable_base*& s, serializer& ser, const char* name);
48 
49 } // namespace pvt
50 
51 
52 template <class T>
54  T*, typename std::enable_if<std::is_base_of<SST::Core::Serialization::serializable, T>::value>::type>
55 {
56 
57  template <class A>
58  friend class serialize;
59  void operator()(T*& s, serializer& ser)
60  {
61  serializable_base* sp = static_cast<serializable_base*>(s);
62  switch ( ser.mode() ) {
63  case serializer::SIZER:
64  pvt::size_serializable(sp, ser);
65  break;
66  case serializer::PACK:
67  pvt::pack_serializable(sp, ser);
68  break;
69  case serializer::UNPACK:
70  pvt::unpack_serializable(sp, ser);
71  break;
72  case serializer::MAP:
73  // No mapping without a name
74  break;
75  }
76  s = static_cast<T*>(sp);
77  }
78 
79  void operator()(T*& s, serializer& ser, const char* name)
80  {
81  serializable_base* sp = static_cast<serializable_base*>(s);
82  switch ( ser.mode() ) {
83  case serializer::SIZER:
84  pvt::size_serializable(sp, ser);
85  break;
86  case serializer::PACK:
87  pvt::pack_serializable(sp, ser);
88  break;
89  case serializer::UNPACK:
90  pvt::unpack_serializable(sp, ser);
91  break;
92  case serializer::MAP:
93  pvt::map_serializable(sp, ser, name);
94  break;
95  }
96  s = static_cast<T*>(sp);
97  }
98 };
99 
100 template <class T>
101 void
102 serialize_intrusive_ptr(T*& t, serializer& ser)
103 {
104  serializable_base* s = t;
105  switch ( ser.mode() ) {
106  case serializer::SIZER:
107  pvt::size_serializable(s, ser);
108  break;
109  case serializer::PACK:
110  pvt::pack_serializable(s, ser);
111  break;
112  case serializer::UNPACK:
113  pvt::unpack_serializable(s, ser);
114  t = dynamic_cast<T*>(s);
115  break;
116  case serializer::MAP:
117  // Add your code here
118  break;
119  }
120 }
121 
122 template <class T>
124  T, typename std::enable_if<std::is_base_of<SST::Core::Serialization::serializable, T>::value>::type>
125 {
126  template <class A>
127  friend class serialize;
128  inline void operator()(T& t, serializer& ser)
129  {
130  // T* tmp = &t;
131  // serialize_intrusive_ptr(tmp, ser);
132  t.serialize_order(ser);
133  }
134 
135  inline void operator()(T& UNUSED(t), serializer& UNUSED(ser), const char* UNUSED(name))
136  {
137  // TODO: Need to figure out how to handle mapping mode for
138  // classes inheriting from serializable that are not pointers.
139  // For the core, this really only applies to SharedObjects,
140  // which may actually need their own specific serialization.
141 
142  // For now mapping mode won't provide any data
143  }
144 };
145 
146 
147 } // namespace Serialization
148 } // namespace Core
149 } // namespace SST
150 
151 //#include "sst/core/serialization/serialize_serializable.h"
152 
153 #endif
This class is basically a wrapper for objects to declare the order in which their members should be s...
Definition: serializer.h:43
Base serialize class.
Definition: serialize.h:45
Definition: action.cc:18
Definition: serializable.h:24
Serialization "gateway" object.
Definition: serialize.h:133
Definition: serializable_base.h:118