SST  14.1.0
StructuralSimulationToolkit
serialize_priority_queue.h
1 // Copyright 2009-2024 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-2024, 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_PRIORITY_QUEUE_H
13 #define SST_CORE_SERIALIZATION_IMPL_SERIALIZE_PRIORITY_QUEUE_H
14 
15 #ifndef SST_INCLUDING_SERIALIZE_H
16 #warning \
17  "The header file sst/core/serialization/impl/serialize_priority_queue.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 
24 namespace SST {
25 namespace Core {
26 namespace Serialization {
27 
28 
29 template <class T, class S, class C>
30 class serialize<std::priority_queue<T, S, C>>
31 {
32  typedef std::priority_queue<T, S, C> Pqueue;
33 
34 public:
35  S& getContainer(std::priority_queue<T, S, C>& q)
36  {
37  struct UnderlyingContainer : std::priority_queue<T, S, C>
38  {
39  static S& getUnderlyingContainer(std::priority_queue<T, S, C>& q) { return q.*&UnderlyingContainer::c; }
40  };
41  return UnderlyingContainer::getUnderlyingContainer(q);
42  }
43 
44  void operator()(Pqueue& v, serializer& ser)
45  {
46  switch ( ser.mode() ) {
47  case serializer::SIZER:
48  {
49  size_t size = v.size();
50  ser.size(size);
51 
52  auto container = getContainer(v);
53  for ( auto it = container.begin(); it != container.end(); ++it ) {
54  T& t = const_cast<T&>(*it);
55  ser& t;
56  }
57  break;
58  }
59  case serializer::PACK:
60  {
61  size_t size = v.size();
62  ser.pack(size);
63 
64  auto container = getContainer(v);
65  for ( auto it = container.begin(); it != container.end(); ++it ) {
66  T& t = const_cast<T&>(*it);
67  ser& t;
68  }
69  break;
70  }
71  case serializer::UNPACK:
72  {
73  size_t size;
74  ser.unpack(size);
75  for ( size_t i = 0; i < size; ++i ) {
76  T t = {};
77  ser& t;
78  v.push(t);
79  }
80  break;
81  }
82  case serializer::MAP:
83  // The version of function not called in mapping mode
84  break;
85  }
86  }
87 
88  void operator()(Pqueue& UNUSED(v), serializer& UNUSED(ser), const char* UNUSED(name))
89  {
90  // TODO: Add support for mapping mode
91  }
92 };
93 
94 } // namespace Serialization
95 } // namespace Core
96 } // namespace SST
97 
98 #endif // SST_CORE_SERIALIZATION_IMPL_SERIALIZE_PRIORITY_QUEUE_H
This class is basically a wrapper for objects to declare the order in which their members should be s...
Definition: serializer.h:43
Definition: action.cc:18
Serialization "gateway" object.
Definition: serialize.h:133