SST  14.0.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_SERIALIZE_PRIORITY_QUEUE_H
13 #define SST_CORE_SERIALIZATION_SERIALIZE_PRIORITY_QUEUE_H
14 
15 #include "sst/core/serialization/serializer.h"
16 
17 #include <queue>
18 
19 namespace SST {
20 namespace Core {
21 namespace Serialization {
22 
23 
24 template <class T, class S, class C>
25 class serialize<std::priority_queue<T, S, C>>
26 {
27  typedef std::priority_queue<T, S, C> Pqueue;
28 
29 public:
30  S& getContainer(std::priority_queue<T, S, C>& q)
31  {
32  struct UnderlyingContainer : std::priority_queue<T, S, C>
33  {
34  static S& getUnderlyingContainer(std::priority_queue<T, S, C>& q) { return q.*&UnderlyingContainer::c; }
35  };
36  return UnderlyingContainer::getUnderlyingContainer(q);
37  }
38 
39  void operator()(Pqueue& v, serializer& ser)
40  {
41  switch ( ser.mode() ) {
42  case serializer::SIZER:
43  {
44  size_t size = v.size();
45  ser.size(size);
46 
47  auto container = getContainer(v);
48  for ( auto it = container.begin(); it != container.end(); ++it ) {
49  T& t = const_cast<T&>(*it);
50  ser& t;
51  }
52  break;
53  }
54  case serializer::PACK:
55  {
56  size_t size = v.size();
57  ser.pack(size);
58 
59  auto container = getContainer(v);
60  for ( auto it = container.begin(); it != container.end(); ++it ) {
61  T& t = const_cast<T&>(*it);
62  ser& t;
63  }
64  break;
65  }
66  case serializer::UNPACK:
67  {
68  size_t size;
69  ser.unpack(size);
70  for ( size_t i = 0; i < size; ++i ) {
71  T t = {};
72  ser& t;
73  v.push(t);
74  }
75  break;
76  }
77  }
78  }
79 };
80 
81 } // namespace Serialization
82 } // namespace Core
83 } // namespace SST
84 
85 #endif // SST_CORE_SERIALIZATION_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:35
Definition: action.cc:18
Serialization "gateway" object.
Definition: serialize.h:110