SST 15.0
Structural Simulation Toolkit
serialize_adapter.h
1// Copyright 2009-2025 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-2025, 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/impl/serialize_utility.h"
21#include "sst/core/serialization/serializer.h"
22
23#include <queue>
24#include <stack>
25#include <type_traits>
26
27namespace SST::Core::Serialization {
28
29template <typename T>
30constexpr bool is_adapter_v = is_same_type_template_v<T, std::stack> || is_same_type_template_v<T, std::queue> ||
31 is_same_type_template_v<T, std::priority_queue>;
32
33// Serialize adapter classes std::stack, std::queue, std::priority_queue
34template <typename T>
35class serialize_impl<T, std::enable_if_t<is_adapter_v<std::remove_pointer_t<T>>>>
36{
37 struct S : std::remove_pointer_t<T>
38 {
39 using std::remove_pointer_t<T>::c; // access protected container
40 };
41
42 void operator()(T& v, serializer& ser, ser_opt_t options)
43 {
44 if constexpr ( std::is_pointer_v<T> ) {
45 if ( ser.mode() == serializer::UNPACK ) v = new std::remove_pointer_t<T>;
46 SST_SER(static_cast<S&>(*v).c, options); // serialize the underlying container
47 }
48 else {
49 SST_SER(static_cast<S&>(v).c, options); // serialize the underlying container
50 }
51 }
52 SST_FRIEND_SERIALIZE();
53};
54
55} // namespace SST::Core::Serialization
56
57#endif // SST_CORE_SERIALIZATION_IMPL_SERIALIZE_ADAPTER_H
Base serialize class.
Definition serialize.h:110
This class is basically a wrapper for objects to declare the order in which their members should be s...
Definition serializer.h:45