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" 20 #define SST_INCLUDING_SERIALIZE_H 21 #include "sst/core/serialization/impl/serialize_utility.h" 22 #undef SST_INCLUDING_SERIALIZE_H 27 #include <type_traits> 37 #define SST_FRIEND_SERIALIZE() \ 38 template <class SER> \ 39 friend class pvt::serialize 51 using ser_opt_t = uint32_t;
67 as_ptr_elem = 1u << 2,
69 map_read_only = 1u << 3,
82 return flags &
static_cast<ser_opt_t
>(option);
86 namespace Core::Serialization {
89 void sst_ser_object(serializer& ser, T&& obj, ser_opt_t options,
const char* name);
93 constexpr decltype(
auto)
96 if constexpr ( std::is_pointer_v<T> )
112 template <
typename T,
typename =
void>
115 static_assert(std::is_class_v<std::remove_pointer_t<T>>,
116 "Trying to serialize a non-class type (or a pointer to one) with the default serialize_impl.");
118 static_assert(std::is_final_v<std::remove_pointer_t<T>> || !std::is_polymorphic_v<std::remove_pointer_t<T>>,
119 "The type or the pointed-to-type is polymorphic and non-final, so serialize_impl cannot know the runtime type " 120 "of the object being serialized. Polymorphic classes need to inherit from the serializable class and call the " 121 "ImplementSerializable() macro. For classes marked final, this is not necessary.");
123 static_assert(has_serialize_order_v<std::remove_pointer_t<T>>,
124 "The type or the pointed-to-type does not have a serialize_impl specialization, nor a public " 125 "serialize_order() method. This means that there is not a serialize_impl class specialization for " 126 "the type or a pointer to the type, and so the default serialize_impl is used which requires a " 127 "public serialize_order() method to be defined inside of the class type.");
130 void operator()(T& t,
serializer& ser, ser_opt_t UNUSED(options))
132 const auto& tPtr = get_ptr(t);
133 const auto mode = ser.mode();
134 if ( mode == serializer::MAP ) {
137 ser.mapper().report_object_map(map);
138 ser.mapper().map_hierarchy_start(ser.getMapName(), map);
140 else if constexpr ( std::is_pointer_v<T> ) {
141 if ( mode == serializer::UNPACK ) {
142 t =
new std::remove_pointer_t<T>();
143 ser.unpacker().report_new_pointer(reinterpret_cast<uintptr_t>(t));
148 tPtr->serialize_order(ser);
150 if ( mode == serializer::MAP ) ser.mapper().map_hierarchy_end();
166 friend void SST::Core::Serialization::sst_ser_object(
serializer& ser, U&& obj, ser_opt_t options,
const char* name);
178 void serialize_and_track_pointer(T& t,
serializer& ser, ser_opt_t options)
180 if ( !ser.is_pointer_tracking_enabled() )
return serialize_impl<T>()(t, ser, options);
183 uintptr_t ptr =
reinterpret_cast<uintptr_t
>(&t);
185 switch ( ser.mode() ) {
186 case serializer::SIZER:
191 if ( ser.sizer().check_pointer_sizer(ptr) ) {
200 case serializer::PACK:
203 ser.packer().check_pointer_pack(ptr);
209 case serializer::UNPACK:
215 uintptr_t ptr_stored;
216 ser.unpack(ptr_stored);
219 ser.unpacker().report_real_pointer(ptr_stored, ptr);
223 case serializer::MAP:
234 friend void SST::Core::Serialization::sst_ser_object(
serializer& ser, U&& obj, ser_opt_t options,
const char* name);
235 void operator()(T*& t,
serializer& ser, ser_opt_t options)
238 if ( !ser.is_pointer_tracking_enabled() ) {
239 switch ( ser.mode() ) {
240 case serializer::UNPACK:
246 bool nonnull = t !=
nullptr;
247 ser.primitive(nonnull);
253 case serializer::MAP:
259 uintptr_t ptr =
reinterpret_cast<uintptr_t
>(t);
260 if (
nullptr == t ) ptr = 0;
262 switch ( ser.mode() ) {
263 case serializer::SIZER:
268 if ( 0 == ptr )
return;
272 if ( !ser.sizer().check_pointer_sizer(ptr) ) {
276 case serializer::PACK:
281 if ( 0 == ptr )
return;
283 if ( !ser.packer().check_pointer_pack(ptr) ) {
287 case serializer::UNPACK:
290 uintptr_t ptr_stored;
291 ser.unpack(ptr_stored);
294 if ( 0 == ptr_stored ) {
299 uintptr_t real_ptr = ser.unpacker().check_pointer_unpack(ptr_stored);
302 t =
reinterpret_cast<T*
>(real_ptr);
306 ser.unpacker().report_real_pointer(ptr_stored, reinterpret_cast<uintptr_t>(t));
310 case serializer::MAP:
312 ObjectMap* map = ser.mapper().check_pointer_map(reinterpret_cast<uintptr_t>(t));
313 if ( map !=
nullptr ) {
316 ser.mapper().map_existing_object(ser.getMapName(), map);
335 template <
class TREF>
337 sst_ser_object(
serializer& ser, TREF&& obj, ser_opt_t options,
const char* name)
340 using T = std::remove_reference_t<TREF>;
344 if ( !ser.is_pointer_tracking_enabled() ) {
350 if ( ser.mode() == serializer::MAP ) {
353 if ( SerOption::is_set(options, SerOption::no_map) )
return;
355 pvt::serialize<T>()(obj, ser, options);
359 if constexpr ( !std::is_pointer_v<T> ) {
361 if ( SerOption::is_set(options, SerOption::as_ptr) ) {
362 pvt::serialize<T>().serialize_and_track_pointer(obj, ser, options);
365 pvt::serialize<T>()(obj, ser, options);
370 pvt::serialize<T>()(obj, ser, options);
378 [[deprecated(
"The ser& syntax for serialization has been deprecated and will be removed in SST 16. Please use the " 379 "SST_SER macro for serializing data. The macro supports additional options to control the details of " 380 "serialization. See the SerOption enum for details.")]]
382 operator&(serializer& ser, T&& obj)
384 SST::Core::Serialization::sst_ser_object(ser, obj, SerOption::no_map,
"");
388 [[deprecated(
"The ser| syntax for serialization has been deprecated and will be removed in SST 16. Please use the " 389 "SST_SER macro with the SerOption::as_ptr flag for serializing data. The macro supports additional " 390 "options to control the details of serialization. See the SerOption enum for details.")]]
392 operator|(serializer& ser, T&& obj)
394 SST::Core::Serialization::sst_ser_object(ser, obj, SerOption::no_map | SerOption::as_ptr,
"");
399 #define SST_SER(obj, ...) \ 400 SST::Core::Serialization::sst_ser_object( \ 401 ser, (obj), SST::Core::Serialization::pvt::sst_ser_or_helper(__VA_ARGS__), #obj) 403 #define SST_SER_NAME(obj, name, ...) \ 404 SST::Core::Serialization::sst_ser_object( \ 405 ser, (obj), SST::Core::Serialization::pvt::sst_ser_or_helper(__VA_ARGS__), name) 411 template <
typename... Args>
413 sst_ser_or_helper(Args... args)
415 return (SerOption::none | ... | args);
424 #define SST_INCLUDING_SERIALIZE_H 425 #include "sst/core/serialization/impl/serialize_adapter.h" 426 #include "sst/core/serialization/impl/serialize_aggregate.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_bitset.h" 430 #include "sst/core/serialization/impl/serialize_insertable.h" 431 #include "sst/core/serialization/impl/serialize_optional.h" 434 #include "sst/core/serialization/impl/serialize_string.h" 435 #include "sst/core/serialization/impl/serialize_trivial.h" 436 #include "sst/core/serialization/impl/serialize_tuple.h" 437 #include "sst/core/serialization/impl/serialize_unique_ptr.h" 438 #include "sst/core/serialization/impl/serialize_valarray.h" 439 #include "sst/core/serialization/impl/serialize_variant.h" 442 #undef SST_INCLUDING_SERIALIZE_H 444 #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:42
Definition: serialize.h:53
Base serialize class.
Definition: serialize.h:113
Base class for objects created by the serializer mapping mode used to map the variables for objects...
Definition: objectMap.h:158
ObjectMap object for non-fundamental, non-container types.
Definition: objectMap.h:675
ObjectMap context which is saved in a virtual stack when name or other information changes...
Definition: serializer.h:155
Serialization "gateway" object called by sst_ser_object().
Definition: serialize.h:163
Options
Options use to control how serialization acts for specific elements that are serialized.
Definition: serialize.h:59