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