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)
52 constexpr uint32_t B(
const uint32_t b)
58 constexpr uint32_t A(
const uint32_t a)
60 return B( (a << 10 ) + a);
65 constexpr uint32_t ct_hash_rec(
const char* str)
67 return A( str[idx] + ct_hash_rec<idx-1>(str) );
73 constexpr uint32_t ct_hash_rec<size_t(-1)>(
const char* UNUSED(str))
79 constexpr uint32_t E(
const uint32_t e)
85 constexpr uint32_t D(
const uint32_t d)
87 return E( (d >> 11) ^ d);
91 constexpr uint32_t C(
const uint32_t c)
93 return D( (c << 3 ) + c);
99 constexpr uint32_t ct_hash(
const char* str)
101 return C(ct_hash_rec<idx>(str));
105 #define COMPILE_TIME_HASH(x) (::SST::Core::Serialization::pvt::ct_hash<sizeof(x)-2>(x))
113 static constexpr uint32_t NullClsId = std::numeric_limits<uint32_t>::max();
116 cls_name()
const = 0;
123 virtual std::string serialization_name()
const = 0;
128 typedef enum { ConstructorFlag } cxn_flag_t;
129 static void serializable_abort(uint32_t line,
const char* file,
const char* func,
const char* obj);
137 #define ImplementVirtualSerializable(obj) \
139 obj(cxn_flag_t flag){}
142 #define NotSerializable(obj) \
146 serializable_abort(CALL_INFO_LONG, #obj); \
149 serialize_order(SST::Core::Serialization::serializer& UNUSED(sst)) override { \
153 cls_id() const override { \
158 construct_deserialize_stub() { \
162 virtual std::string \
163 serialization_name() const override { \
167 virtual const char* \
168 cls_name() const override { \
173 #define ImplementSerializableDefaultConstructor(obj) \
175 virtual const char* \
176 cls_name() const override { \
180 cls_id() const override { \
181 return SST::Core::Serialization::serializable_builder_impl<obj>::static_cls_id(); \
184 construct_deserialize_stub() { \
187 virtual std::string \
188 serialization_name() const override { \
192 friend class SST::Core::Serialization::serializable_builder_impl<obj>; \
194 you_forgot_to_add_ImplementSerializable_to_this_class() { \
198 #define ImplementSerializable(obj) \
200 ImplementSerializableDefaultConstructor(obj)
225 static const char* name_;
226 static const uint32_t cls_id_;
230 build()
const override {
231 return T::construct_deserialize_stub();
235 name()
const override {
240 cls_id()
const override {
256 return (
typeid(T) ==
typeid(*ser));
263 typedef std::unordered_map<long, serializable_builder*> builder_map;
264 static builder_map* builders_;
268 get_serializable(uint32_t cls_id);
279 return (*builders_)[cls_id]->sanity(ser);
302 #define SerializableName(obj) #obj
304 #define DeclareSerializable(obj)
307 #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:222
Definition: serializable.h:110
Definition: serializable.h:203
static uint32_t add_builder(serializable_builder *builder, const char *name)
Definition: serializable.cc:36
Definition: serializable.h:260
Definition: serializable.h:133