12 #ifndef SST_CORE_SERIALIZATION_SERIALIZE_H 13 #define SST_CORE_SERIALIZATION_SERIALIZE_H 15 #include "sst/core/serialization/serializer.h" 16 #include "sst/core/warnmacros.h" 24 namespace Serialization {
31 template <
class T,
class Enable =
void>
52 if constexpr ( std::is_pointer_v<T> ) {
55 if constexpr ( std::is_class_v<std::remove_pointer<T>> && !std::is_polymorphic_v<std::remove_pointer<T>> ) {
56 if ( ser.mode() == serializer::UNPACK ) {
57 t =
new typename std::remove_pointer<T>::type();
58 ser.report_new_pointer(reinterpret_cast<uintptr_t>(t));
60 t->serialize_order(ser);
63 static_assert(std::is_fundamental<T>::value,
"Trying to serialize an object that is not serializable.");
65 !std::is_fundamental<T>::value,
"Trying to serialize an object that is not serializable.");
71 if constexpr ( std::is_class_v<T> && !std::is_polymorphic_v<T> ) { t.serialize_order(ser); }
73 static_assert(std::is_fundamental<T>::value,
"Trying to serialize an object that is not serializable.");
75 !std::is_fundamental<T>::value,
"Trying to serialize an object that is not serializable.");
128 uintptr_t ptr =
reinterpret_cast<uintptr_t
>(&t);
130 switch ( ser.mode() ) {
131 case serializer::SIZER:
136 if ( ser.check_pointer_pack(ptr) ) {
145 case serializer::PACK:
148 ser.check_pointer_pack(ptr);
154 case serializer::UNPACK:
160 uintptr_t ptr_stored;
161 ser.unpack(ptr_stored);
164 ser.report_real_pointer(ptr_stored, ptr);
175 inline void operator()(T*& t,
serializer& ser)
180 uintptr_t ptr =
reinterpret_cast<uintptr_t
>(t);
181 if (
nullptr == t ) ptr = 0;
183 switch ( ser.mode() ) {
184 case serializer::SIZER:
189 if ( 0 == ptr )
return;
195 case serializer::PACK:
200 if ( 0 == ptr )
return;
204 case serializer::UNPACK:
206 uintptr_t ptr_stored;
207 ser.unpack(ptr_stored);
210 if ( 0 == ptr_stored ) {
215 uintptr_t real_ptr = ser.check_pointer_unpack(ptr_stored);
218 t =
reinterpret_cast<T*
>(real_ptr);
222 ser.report_real_pointer(ptr_stored, reinterpret_cast<uintptr_t>(t));
232 class serialize_impl<T, typename
std::enable_if<std::is_fundamental<T>::value || std::is_enum<T>::value>::type>
236 inline void operator()(T& t,
serializer& ser) { ser.primitive(t); }
264 class serialize_impl<T*,
typename std::enable_if<std::is_fundamental<T>::value || std::is_enum<T>::value>::type>
268 inline void operator()(T*& t,
serializer& ser)
270 switch ( ser.mode() ) {
271 case serializer::SIZER:
274 case serializer::PACK:
277 case serializer::UNPACK:
289 template <
class U,
class V>
294 inline void operator()(std::pair<U, V>& t,
serializer& ser)
335 #include "sst/core/serialization/serialize_array.h" 336 #include "sst/core/serialization/serialize_atomic.h" 337 #include "sst/core/serialization/serialize_deque.h" 338 #include "sst/core/serialization/serialize_list.h" 339 #include "sst/core/serialization/serialize_map.h" 340 #include "sst/core/serialization/serialize_priority_queue.h" 341 #include "sst/core/serialization/serialize_set.h" 342 #include "sst/core/serialization/serialize_string.h" 343 #include "sst/core/serialization/serialize_vector.h" 345 #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:35
Base serialize class.
Definition: serialize.h:32
Serialization "gateway" object.
Definition: serialize.h:110
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:123