12 #ifndef SST_CORE_SERIALIZATION_SERIALIZABLE_H
13 #define SST_CORE_SERIALIZATION_SERIALIZABLE_H
15 #include "sst/core/serialization/serializer.h"
16 #include "sst/core/warnmacros.h"
17 #include <unordered_map>
24 namespace Serialization {
31 inline uint32_t type_hash(
const char* key)
33 int len = ::strlen(key);
35 for(
int i = 0; i < len; ++i) {
51 constexpr uint32_t B(
const uint32_t b)
57 constexpr uint32_t A(
const uint32_t a)
59 return B( (a << 10 ) + a);
64 constexpr uint32_t ct_hash_rec(
const char* str)
66 return A( str[idx] + ct_hash_rec<idx-1>(str) );
72 constexpr uint32_t ct_hash_rec<size_t(-1)>(
const char* UNUSED(str))
78 constexpr uint32_t E(
const uint32_t e)
84 constexpr uint32_t D(
const uint32_t d)
86 return E( (d >> 11) ^ d);
90 constexpr uint32_t C(
const uint32_t c)
92 return D( (c << 3 ) + c);
98 constexpr uint32_t ct_hash(
const char* str)
100 return C(ct_hash_rec<idx>(str));
104 #define COMPILE_TIME_HASH(x) (::SST::Core::Serialization::pvt::ct_hash<sizeof(x)-2>(x))
112 static constexpr uint32_t NullClsId = std::numeric_limits<uint32_t>::max();
115 cls_name()
const = 0;
122 virtual std::string serialization_name()
const = 0;
127 typedef enum { ConstructorFlag } cxn_flag_t;
128 static void serializable_abort(uint32_t line,
const char* file,
const char* func,
const char* obj);
136 #define ImplementVirtualSerializable(obj) \
138 obj(cxn_flag_t flag){}
141 #define NotSerializable(obj) \
145 serializable_abort(CALL_INFO_LONG, #obj); \
148 serialize_order(SST::Core::Serialization::serializer& UNUSED(sst)) override { \
152 cls_id() const override { \
157 construct_deserialize_stub() { \
161 virtual std::string \
162 serialization_name() const override { \
166 virtual const char* \
167 cls_name() const override { \
172 #define ImplementSerializableDefaultConstructor(obj) \
174 virtual const char* \
175 cls_name() const override { \
179 cls_id() const override { \
180 return SST::Core::Serialization::serializable_builder_impl<obj>::static_cls_id(); \
183 construct_deserialize_stub() { \
186 virtual std::string \
187 serialization_name() const override { \
191 friend class SST::Core::Serialization::serializable_builder_impl<obj>; \
193 you_forgot_to_add_ImplementSerializable_to_this_class() { \
197 #define ImplementSerializable(obj) \
199 ImplementSerializableDefaultConstructor(obj)
224 static const char* name_;
225 static const uint32_t cls_id_;
229 build()
const override {
230 return T::construct_deserialize_stub();
234 name()
const override {
239 cls_id()
const override {
255 return (
typeid(T) ==
typeid(*ser));
262 typedef std::unordered_map<long, serializable_builder*> builder_map;
263 static builder_map* builders_;
267 get_serializable(uint32_t cls_id);
278 return (*builders_)[cls_id]->sanity(ser);
301 #define SerializableName(obj) #obj
303 #define DeclareSerializable(obj)
306 #include "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
Definition: serializable.h:221
Definition: serializable.h:109
Definition: serializable.h:202
static uint32_t add_builder(serializable_builder *builder, const char *name)
Definition: serializable.cc:37
Definition: serializable.h:259
Definition: serializable.h:132