SST  15.1.0
StructuralSimulationToolkit
serialize_bitset.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_BITSET_H
13 #define SST_CORE_SERIALIZATION_IMPL_SERIALIZE_BITSET_H
14 
15 #ifndef SST_INCLUDING_SERIALIZE_H
16 #warning \
17  "The header file sst/core/serialization/impl/serialize_bitset.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 <bitset>
23 #include <cstddef>
24 #include <type_traits>
25 
26 namespace SST::Core::Serialization {
27 
28 // Serialize std::bitset
29 template <size_t N>
30 class serialize_impl<std::bitset<N>>
31 {
32  using T = std::bitset<N>;
33  void operator()(T& t, serializer& ser, ser_opt_t UNUSED(options))
34  {
35  switch ( ser.mode() ) {
36  case serializer::MAP:
37  {
38  // TODO: Should this be mapped as an array? It will have the same problems as std::vector<bool>
39  break;
40  }
41 
42  default:
43  static_assert(std::is_trivially_copyable_v<T> && std::is_standard_layout_v<T>);
44  ser.primitive(t);
45  break;
46  }
47  }
48  SST_FRIEND_SERIALIZE();
49 };
50 
51 template <size_t N>
52 class serialize_impl<std::bitset<N>*>
53 {
54  using T = std::bitset<N>;
55  void operator()(T*& t, serializer& ser, ser_opt_t UNUSED(options))
56  {
57  if ( ser.mode() == serializer::UNPACK ) t = new T {};
58  SST_SER(*t);
59  }
60  SST_FRIEND_SERIALIZE();
61 };
62 
63 } // namespace SST::Core::Serialization
64 
65 #endif // SST_CORE_SERIALIZATION_IMPL_SERIALIZE_BITSET_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