Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 25 additions & 8 deletions src/sst/core/serialization/impl/serialize_adapter.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,23 +31,40 @@ constexpr bool is_adapter_v = is_same_type_template_v<T, std::stack> || is_same_

// Serialize adapter classes std::stack, std::queue, std::priority_queue
template <typename T>
class serialize_impl<T, std::enable_if_t<is_adapter_v<std::remove_pointer_t<T>>>>
class serialize_impl<T, std::enable_if_t<is_adapter_v<T>>>
{
struct S : std::remove_pointer_t<T>
struct S : T
{
using std::remove_pointer_t<T>::c; // access protected container
using T::c; // access protected container
};

void operator()(T& v, serializer& ser, ser_opt_t options)
{
if constexpr ( std::is_pointer_v<T> ) {
if ( ser.mode() == serializer::UNPACK ) v = new std::remove_pointer_t<T>;
SST_SER(static_cast<S&>(*v).c, options); // serialize the underlying container
}
else {
switch ( ser.mode() ) {
case serializer::MAP:
ser.mapper().map_hierarchy_start(ser.getMapName(), new ObjectMapContainer<T>(&v));
SST_SER_NAME(static_cast<S&>(v).c, "container",
options | SerOption::map_read_only); // serialize the underlying container
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's read-only now. Question: Do we really need to pass other options down, or can we just ignore options and pass SerOption::map_read_only? (In that case, we probably don't need to pass options in the SST_SER() call below either, and we can say UNUSED(options).)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For now, I believe read-only only affects fundamentals because it is not applied to members of a class. We'll need to figure out how we want this to apply to data members. We may need to track it as part of the path. I could see accessing an object through different paths where on path is read-only and the other isn't. It's an interesting problem.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, but my question was mainly about other options when serializing, say std::priority_queue. Are there any serialization options when serializing std::priority_queue which need to be passed when serializing the underlying container, or can we just ignore all serialization options passed when serializing std::priority_queue?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I add read-only for std::priority_queue now, but I pass the adapter serialization options as-is to the serialization of the underlying container.

ser.mapper().map_hierarchy_end();
break;

default:
SST_SER(static_cast<S&>(v).c, options); // serialize the underlying container
break;
}
}

SST_FRIEND_SERIALIZE();
};

template <typename T>
class serialize_impl<T*, std::enable_if_t<is_adapter_v<T>>>
{
void operator()(T*& obj, serializer& ser, ser_opt_t options)
{
if ( ser.mode() == serializer::UNPACK ) obj = new T;
SST_SER(*obj, options);
}
SST_FRIEND_SERIALIZE();
};

Expand Down
Loading