SST  12.0.1
StructuralSimulationToolkit
serialize_list.h
1 // Copyright 2009-2022 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-2022, 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_LIST_H
13 #define SST_CORE_SERIALIZATION_SERIALIZE_LIST_H
14 
15 #include "sst/core/serialization/serializer.h"
16 
17 #include <list>
18 
19 namespace SST {
20 namespace Core {
21 namespace Serialization {
22 
23 template <class T>
24 class serialize<std::list<T>>
25 {
26  typedef std::list<T> List;
27 
28 public:
29  void operator()(List& v, serializer& ser)
30  {
31  typedef typename List::iterator iterator;
32  switch ( ser.mode() ) {
33  case serializer::SIZER:
34  {
35  size_t size = v.size();
36  ser.size(size);
37  iterator it, end = v.end();
38  for ( it = v.begin(); it != end; ++it ) {
39  T& t = *it;
40  serialize<T>()(t, ser);
41  }
42  break;
43  }
44  case serializer::PACK:
45  {
46  size_t size = v.size();
47  ser.pack(size);
48  iterator it, end = v.end();
49  for ( it = v.begin(); it != end; ++it ) {
50  T& t = *it;
51  serialize<T>()(t, ser);
52  }
53  break;
54  }
55  case serializer::UNPACK:
56  {
57  size_t size;
58  ser.unpack(size);
59  for ( size_t i = 0; i < size; ++i ) {
60  T t;
61  serialize<T>()(t, ser);
62  v.push_back(t);
63  }
64  break;
65  }
66  }
67  }
68 };
69 
70 } // namespace Serialization
71 } // namespace Core
72 } // namespace SST
73 
74 #endif // SST_CORE_SERIALIZATION_SERIALIZE_LIST_H
This class is basically a wrapper for objects to declare the order in which their members should be s...
Definition: serializer.h:34
Base serialize class.
Definition: serialize.h:31