SST 16.0.0
Structural Simulation Toolkit
serialize_adapter.h
1// Copyright 2009-2026 NTESS. Under the terms
2// of Contract DE-NA0003525 with NTESS, the U.S.
3// Government retains certain rights in this software.
4//
5// Copyright (c) 2009-2026, NTESS
6// All rights reserved.
7//
8// This file is part of the SST software package. For license
9// information, see the LICENSE file in the top level directory of the
10// distribution.
11
12#ifndef SST_CORE_SERIALIZATION_IMPL_SERIALIZE_ADAPTER_H
13#define SST_CORE_SERIALIZATION_IMPL_SERIALIZE_ADAPTER_H
14
15#ifndef SST_INCLUDING_SERIALIZE_H
16#warning \
17 "The header file sst/core/serialization/impl/serialize_adapter.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"
18#endif
19
20#include "sst/core/serialization/serializer.h"
21
22#include <queue>
23#include <stack>
24#include <type_traits>
25
26namespace SST::Core::Serialization {
27
28template <typename T>
29constexpr bool is_adapter_v = is_same_type_template_v<T, std::stack> || is_same_type_template_v<T, std::queue> ||
30 is_same_type_template_v<T, std::priority_queue>;
31
32// Serialize adapter classes std::stack, std::queue, std::priority_queue
33template <typename T>
34class serialize_impl<T, std::enable_if_t<is_adapter_v<T>>>
35{
36 struct S : T
37 {
38 using T::c; // access protected container
39 };
40
41 void operator()(T& v, serializer& ser, ser_opt_t options)
42 {
43 switch ( ser.mode() ) {
44 case serializer::MAP:
45 ser.mapper().map_hierarchy_start(ser.getMapName(), new ObjectMapContainer<T>(&v));
46
47 // For std::priority_queue, mark the underlying container read-only
48 if constexpr ( is_same_type_template_v<T, std::priority_queue> ) options |= SerOption::map_read_only;
49
50 // serialize the underlying container
51 SST_SER_NAME(static_cast<S&>(v).c, "container", options);
52
53 ser.mapper().map_hierarchy_end();
54 break;
55
56 default:
57 // serialize the underlying container
58 SST_SER(static_cast<S&>(v).c, options);
59 break;
60 }
61 }
62
63 SST_FRIEND_SERIALIZE();
64};
65
66template <typename T>
67class serialize_impl<T*, std::enable_if_t<is_adapter_v<T>>>
68{
69 void operator()(T*& obj, serializer& ser, ser_opt_t options)
70 {
71 if ( ser.mode() == serializer::UNPACK ) obj = new T;
72 SST_SER(*obj, options);
73 }
74 SST_FRIEND_SERIALIZE();
75};
76
77} // namespace SST::Core::Serialization
78
79#endif // SST_CORE_SERIALIZATION_IMPL_SERIALIZE_ADAPTER_H
Class used to map containers.
Definition objectMap.h:1420
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