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() { ::SST::Core::Serialization::serializable::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 \ 152 return ::SST::Core::Serialization::serializable::NullClsId; \ 154 static obj* construct_deserialize_stub() \ 159 virtual std::string serialization_name() const override \ 164 virtual const char* cls_name() const override { return #obj; } 167 #define ImplementSerializableDefaultConstructor(obj, obj_str) \ 169 virtual const char* cls_name() const override \ 171 return SST::Core::Serialization::serializable_builder_impl<obj>::static_name(); \ 173 virtual uint32_t cls_id() const override \ 175 return SST::Core::Serialization::serializable_builder_impl<obj>::static_cls_id(); \ 177 static obj* construct_deserialize_stub() { return new obj; } \ 178 virtual std::string serialization_name() const override { return obj_str; } \ 181 friend class SST::Core::Serialization::serializable_builder_impl<obj>; \ 182 static bool you_forgot_to_add_ImplementSerializable_to_this_class() { return false; } 184 #define SER_FORWARD_AS_ONE(...) __VA_ARGS__ 186 #define ImplementSerializable(...) \ 188 ImplementSerializableDefaultConstructor(SER_FORWARD_AS_ONE(__VA_ARGS__), #__VA_ARGS__) 197 virtual const char* name()
const = 0;
199 virtual uint32_t cls_id()
const = 0;
208 static const char* name_;
209 static const uint32_t cls_id_;
212 serializable* build()
const override {
return T::construct_deserialize_stub(); }
214 const char* name()
const override {
return name_; }
216 uint32_t cls_id()
const override {
return cls_id_; }
218 static uint32_t static_cls_id() {
return cls_id_; }
220 static const char* static_name() {
return name_; }
222 bool sanity(
serializable* ser)
override {
return (
typeid(T) ==
typeid(*ser)); }
228 typedef std::unordered_map<long, serializable_builder*> builder_map;
229 static builder_map* builders_;
241 static bool sanity(
serializable* ser, uint32_t cls_id) {
return (*builders_)[cls_id]->sanity(ser); }
243 static void delete_statics();
262 #define SerializableName(obj) #obj 264 #define DeclareSerializable(obj) 267 #define SST_SER(obj) ser& obj; 268 #define SST_SER_AS_PTR(obj) ser | obj; 270 #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:205
Definition: serializable.h:118
Definition: serializable.h:190
static uint32_t add_builder(serializable_builder *builder, const char *name)
Definition: serializable.cc:39
Definition: serializable.h:225
Definition: serializable.h:138