12#ifndef SST_CORE_SERIALIZATION_IMPL_SERIALIZE_OPTIONAL_H
13#define SST_CORE_SERIALIZATION_IMPL_SERIALIZE_OPTIONAL_H
15#ifndef SST_INCLUDING_SERIALIZE_H
17 "The header file sst/core/serialization/impl/serialize_optional.h should not be directly included as it is not part of the stable public API. The file is included in sst/core/serialization/serialize.h"
20#include "sst/core/serialization/serializer.h"
25namespace SST::Core::Serialization {
36 std::optional<T>& obj;
41 ObjectMapOptionalHasValue(std::optional<T>& obj,
ObjectMap* parent) :
48 void set_impl(
const std::string& value)
override
52 if ( has_value == old )
return;
56 parent->
addVariable(
"value", ObjectMapSerialization(*obj));
65 void operator()(std::optional<T>& obj,
serializer& ser, ser_opt_t options)
67 bool has_value = obj.has_value();
69 switch ( ser.mode() ) {
71 ser.mapper().map_hierarchy_start(ser.getMapName(),
new ObjectMapContainer<std::optional<T>>(&obj));
72 ser.mapper().map_object(
"has_value",
new ObjectMapOptionalHasValue(obj, ser.mapper().get_top()));
73 if ( obj ) ser.mapper().map_object(
"value", ObjectMapSerialization(*obj));
74 ser.mapper().map_hierarchy_end();
77 case serializer::SIZER:
81 case serializer::PACK:
85 case serializer::UNPACK:
86 ser.unpack(has_value);
95 if ( has_value ) SST_SER(*obj, options);
98 SST_FRIEND_SERIALIZE();
Class used to map containers.
Definition objectMap.h:1420
ObjectMap representing fundamental types, and classes treated as fundamental types.
Definition objectMap.h:1230
virtual void set_impl(const std::string &value) override
Set the value of the object represented as a string.
Definition objectMap.h:1244
Base class for objects created by the serializer mapping mode used to map the variables for objects.
Definition objectMap.h:188
virtual void removeVariable(const std::string &UNUSED(name))
Removes a variable from this ObjectMap.
Definition objectMap.h:412
virtual void addVariable(const std::string &UNUSED(name), ObjectMap *UNUSED(obj))
Adds a variable to this ObjectMap.
Definition objectMap.h:403
Base serialize class.
Definition serialize.h:132
This class is basically a wrapper for objects to declare the order in which their members should be s...
Definition serializer.h:43