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" 21 #include <unordered_map> 25 namespace Serialization {
33 type_hash(
const char* key)
35 int len = ::strlen(key);
37 for (
int i = 0; i < len; ++i ) {
63 return B((a << 10) + a);
69 ct_hash_rec(
const char* str)
71 return A(str[idx] + ct_hash_rec<idx - 1>(str));
78 ct_hash_rec<size_t(-1)>(
const char* UNUSED(str))
94 return E((d >> 11) ^ d);
101 return D((c << 3) + c);
106 template <
size_t idx>
108 ct_hash(
const char* str)
110 return C(ct_hash_rec<idx>(str));
114 #define COMPILE_TIME_HASH(x) (::SST::Core::Serialization::pvt::ct_hash<sizeof(x) - 2>(x)) 121 static constexpr uint32_t NullClsId = std::numeric_limits<uint32_t>::max();
123 virtual const char* cls_name()
const = 0;
125 virtual void serialize_order(
serializer& ser) = 0;
127 virtual uint32_t cls_id()
const = 0;
128 virtual std::string serialization_name()
const = 0;
133 typedef enum { ConstructorFlag } cxn_flag_t;
134 static void serializable_abort(uint32_t line,
const char* file,
const char* func,
const char* obj);
141 #define ImplementVirtualSerializable(obj) \ 143 virtual const char* cls_name() const override { return #obj; } 145 #define NotSerializable(obj) \ 147 static void throw_exc() { serializable_abort(CALL_INFO_LONG, #obj); } \ 148 virtual void serialize_order(SST::Core::Serialization::serializer& UNUSED(sst)) override { throw_exc(); } \ 149 virtual uint32_t cls_id() const override \ 154 static obj* construct_deserialize_stub() \ 159 virtual std::string serialization_name() const override \ 164 virtual const char* cls_name() const override { return #obj; } 166 #define ImplementSerializableDefaultConstructor(obj, obj_str) \ 168 virtual const char* cls_name() const override { return obj_str; } \ 169 virtual uint32_t cls_id() const override \ 171 return SST::Core::Serialization::serializable_builder_impl<obj>::static_cls_id(); \ 173 static obj* construct_deserialize_stub() { return new obj; } \ 174 virtual std::string serialization_name() const override { return obj_str; } \ 177 friend class SST::Core::Serialization::serializable_builder_impl<obj>; \ 178 static bool you_forgot_to_add_ImplementSerializable_to_this_class() { return false; } 180 #define SER_FORWARD_AS_ONE(...) __VA_ARGS__ 182 #define ImplementSerializable(...) \ 184 ImplementSerializableDefaultConstructor(SER_FORWARD_AS_ONE(__VA_ARGS__), #__VA_ARGS__) 193 virtual const char* name()
const = 0;
195 virtual uint32_t cls_id()
const = 0;
204 static const char* name_;
205 static const uint32_t cls_id_;
208 serializable* build()
const override {
return T::construct_deserialize_stub(); }
210 const char* name()
const override {
return name_; }
212 uint32_t cls_id()
const override {
return cls_id_; }
214 static uint32_t static_cls_id() {
return cls_id_; }
216 static const char* static_name() {
return name_; }
218 bool sanity(
serializable* ser)
override {
return (
typeid(T) ==
typeid(*ser)); }
224 typedef std::unordered_map<long, serializable_builder*> builder_map;
225 static builder_map* builders_;
237 static bool sanity(
serializable* ser, uint32_t cls_id) {
return (*builders_)[cls_id]->sanity(ser); }
239 static void delete_statics();
258 #define SerializableName(obj) #obj 260 #define DeclareSerializable(obj) 262 #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:34
Definition: serializable.h:201
Definition: serializable.h:118
Definition: serializable.h:186
static uint32_t add_builder(serializable_builder *builder, const char *name)
Definition: serializable.cc:39
Definition: serializable.h:221
Definition: serializable.h:138