SST 16.0.0
Structural Simulation Toolkit
serialize_bitset.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_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
25namespace SST::Core::Serialization {
26
27// Serialize std::bitset<N>
28template <size_t N>
29class serialize_impl<std::bitset<N>>
30{
31 void operator()(std::bitset<N>& t, serializer& ser, ser_opt_t UNUSED(options))
32 {
33 switch ( ser.mode() ) {
34 case serializer::MAP:
35 {
36 ser.mapper().map_hierarchy_start(ser.getMapName(), new ObjectMapContainer<std::bitset<N>>(&t));
37
38 // Serialize reference wrappers to each bit
39 for ( size_t i = 0; i < N; ++i )
40 SST_SER_NAME(pvt::bit_reference_wrapper<std::bitset<N>>(t[i]), std::to_string(i).c_str());
41
42 ser.mapper().map_hierarchy_end();
43 break;
44 }
45
46 default:
47 ser.primitive(t);
48 break;
49 }
50 }
51 SST_FRIEND_SERIALIZE();
52};
53
54// Serialize std::bitset<N>*
55template <size_t N>
56class serialize_impl<std::bitset<N>*>
57{
58 void operator()(std::bitset<N>*& t, serializer& ser, ser_opt_t UNUSED(options))
59 {
60 if ( ser.mode() == serializer::UNPACK ) t = new std::bitset<N>;
61 SST_SER(*t);
62 }
63 SST_FRIEND_SERIALIZE();
64};
65
66// Serialize a std::bitset<N> bit using the pvt::bit_reference_wrapper<std::bitset<N>>
67// This is only used in mapping mode
68template <size_t N>
69class serialize_impl<pvt::bit_reference_wrapper<std::bitset<N>>>
70{
71 void operator()(pvt::bit_reference_wrapper<std::bitset<N>>& t, serializer& ser, ser_opt_t UNUSED(options))
72 {
73 ser.mapper().map_hierarchy_start(
74 ser.getMapName(), new ObjectMapFundamentalReference<bool, typename std::bitset<N>::reference>(t.ref));
75 ser.mapper().map_hierarchy_end();
76 }
77 SST_FRIEND_SERIALIZE();
78};
79
80} // namespace SST::Core::Serialization
81
82#endif // SST_CORE_SERIALIZATION_IMPL_SERIALIZE_BITSET_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