12 #ifndef SST_CORE_SERIALIZATION_SERIALIZE_H 13 #define SST_CORE_SERIALIZATION_SERIALIZE_H 15 #include "sst/core/from_string.h" 16 #include "sst/core/serialization/objectMap.h" 17 #include "sst/core/serialization/serializer.h" 18 #include "sst/core/warnmacros.h" 22 #include <type_traits> 27 namespace Serialization {
33 constexpr
bool dependent_false =
false;
44 template <
class T,
class Enable =
void>
51 if constexpr ( std::is_pointer_v<T> ) {
55 std::is_class_v<
typename std::remove_pointer<T>::type> &&
56 !std::is_polymorphic_v<
typename std::remove_pointer<T>::type> ) {
57 if ( ser.mode() == serializer::UNPACK ) {
58 t =
new typename std::remove_pointer<T>::type();
59 ser.report_new_pointer(reinterpret_cast<uintptr_t>(t));
61 t->serialize_order(ser);
64 static_assert(dependent_false<T>,
"Trying to serialize an object that is not serializable.");
70 if constexpr ( std::is_class_v<T> && !std::is_polymorphic_v<T> ) { t.serialize_order(ser); }
72 static_assert(dependent_false<T>,
"Trying to serialize an object that is not serializable.");
77 inline void operator()(T& t,
serializer& ser,
const char* name)
80 if constexpr ( std::is_pointer_v<T> ) {
84 std::is_class_v<
typename std::remove_pointer<T>::type> &&
85 !std::is_polymorphic_v<
typename std::remove_pointer<T>::type> ) {
86 if ( ser.mode() == serializer::UNPACK ) {
87 t =
new typename std::remove_pointer<T>::type();
88 ser.report_new_pointer(reinterpret_cast<uintptr_t>(t));
90 if ( ser.mode() == serializer::MAP ) {
92 if (
nullptr == t )
return;
95 ser.report_object_map(map);
96 ser.mapper().map_hierarchy_start(name, map);
98 t->serialize_order(ser);
99 if ( ser.mode() == serializer::MAP ) ser.mapper().map_hierarchy_end();
102 static_assert(dependent_false<T>,
"Trying to serialize an object that is not serializable.");
108 if constexpr ( std::is_class_v<T> && !std::is_polymorphic_v<T> ) {
109 if ( ser.mode() == serializer::MAP ) {
112 ser.report_object_map(map);
113 ser.mapper().map_hierarchy_start(name, map);
115 t.serialize_order(ser);
116 if ( ser.mode() == serializer::MAP ) ser.mapper().map_hierarchy_end();
119 static_assert(dependent_false<T>,
"Trying to serialize an object that is not serializable.");
152 uintptr_t ptr =
reinterpret_cast<uintptr_t
>(&t);
154 switch ( ser.mode() ) {
155 case serializer::SIZER:
160 if ( ser.check_pointer_pack(ptr) ) {
169 case serializer::PACK:
172 ser.check_pointer_pack(ptr);
178 case serializer::UNPACK:
184 uintptr_t ptr_stored;
185 ser.unpack(ptr_stored);
188 ser.report_real_pointer(ptr_stored, ptr);
191 case serializer::MAP:
202 inline void operator()(T*& t,
serializer& ser)
207 uintptr_t ptr =
reinterpret_cast<uintptr_t
>(t);
208 if (
nullptr == t ) ptr = 0;
210 switch ( ser.mode() ) {
211 case serializer::SIZER:
216 if ( 0 == ptr )
return;
222 case serializer::PACK:
227 if ( 0 == ptr )
return;
231 case serializer::UNPACK:
234 uintptr_t ptr_stored;
235 ser.unpack(ptr_stored);
238 if ( 0 == ptr_stored ) {
243 uintptr_t real_ptr = ser.check_pointer_unpack(ptr_stored);
246 t =
reinterpret_cast<T*
>(real_ptr);
250 ser.report_real_pointer(ptr_stored, reinterpret_cast<uintptr_t>(t));
253 case serializer::MAP:
259 inline void operator()(T*& t,
serializer& ser,
const char* name)
266 if ( ser.mode() != serializer::MAP )
return;
268 ObjectMap* map = ser.check_pointer_map(reinterpret_cast<uintptr_t>(t));
269 if ( map !=
nullptr ) {
272 ser.mapper().map_existing_object(name, map);
285 class serialize_impl<T, typename
std::enable_if<std::is_fundamental<T>::value || std::is_enum<T>::value>::type>
289 inline void operator()(T& t,
serializer& ser) { ser.primitive(t); }
291 inline void operator()(T& t,
serializer& ser,
const char* name)
294 ser.mapper().map_primitive(name, obj_map);
313 inline void operator()(
bool& t,
serializer& ser,
const char* name)
316 ser.mapper().map_primitive(name, obj_map);
329 class serialize_impl<T*,
typename std::enable_if<std::is_fundamental<T>::value || std::is_enum<T>::value>::type>
333 inline void operator()(T*& t,
serializer& ser)
335 switch ( ser.mode() ) {
336 case serializer::SIZER:
339 case serializer::PACK:
342 case serializer::UNPACK:
346 case serializer::MAP:
357 template <
class U,
class V>
362 inline void operator()(std::pair<U, V>& t,
serializer& ser)
403 sst_map_object(
serializer& ser, T& t,
const char* name)
408 if ( ser.mode() == serializer::MAP ) {
serialize<T>()(t, ser, name); }
410 serialize<T>()(t, ser);
416 #define SST_SER(obj) sst_map_object(ser, obj, #obj); 417 #define SST_SER_AS_PTR(obj) ser | obj; 426 #define SST_INCLUDING_SERIALIZE_H 427 #include "sst/core/serialization/impl/serialize_array.h" 428 #include "sst/core/serialization/impl/serialize_atomic.h" 429 #include "sst/core/serialization/impl/serialize_deque.h" 430 #include "sst/core/serialization/impl/serialize_list.h" 431 #include "sst/core/serialization/impl/serialize_map.h" 432 #include "sst/core/serialization/impl/serialize_priority_queue.h" 433 #include "sst/core/serialization/impl/serialize_set.h" 434 #include "sst/core/serialization/impl/serialize_string.h" 435 #include "sst/core/serialization/impl/serialize_vector.h" 438 #undef SST_INCLUDING_SERIALIZE_H 440 #endif // SST_CORE_SERIALIZATION_SERIALIZE_H This class is basically a wrapper for objects to declare the order in which their members should be s...
Definition: serializer.h:43
ObjectMap object fundamental types, and classes treated as fundamental types.
Definition: objectMap.h:501
Base serialize class.
Definition: serialize.h:45
Class created by the serializer mapping mode used to map the variables for objects.
Definition: objectMap.h:61
ObjectMap object for non-fundamental, non-container types.
Definition: objectMap.h:453
Serialization "gateway" object.
Definition: serialize.h:133
void serialize_and_track_pointer(T &t, serializer &ser)
This will track the pointer to the object if pointer tracking is turned on.
Definition: serialize.h:147