SST  12.0.0
StructuralSimulationToolkit
serialize_vector.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_VECTOR_H
13 #define SST_CORE_SERIALIZATION_SERIALIZE_VECTOR_H
14 
15 #include "sst/core/serialization/serializer.h"
16 
17 #include <vector>
18 
19 namespace SST {
20 namespace Core {
21 namespace Serialization {
22 
23 template <class T>
24 class serialize<std::vector<T>>
25 {
26  typedef std::vector<T> Vector;
27 
28 public:
29  void operator()(Vector& v, serializer& ser)
30  {
31  switch ( ser.mode() ) {
32  case serializer::SIZER:
33  {
34  size_t size = v.size();
35  ser.size(size);
36  break;
37  }
38  case serializer::PACK:
39  {
40  size_t size = v.size();
41  ser.pack(size);
42  break;
43  }
44  case serializer::UNPACK:
45  {
46  size_t s;
47  ser.unpack(s);
48  v.resize(s);
49  break;
50  }
51  }
52 
53  for ( size_t i = 0; i < v.size(); ++i ) {
54  serialize<T>()(v[i], ser);
55  }
56  }
57 };
58 
59 } // namespace Serialization
60 } // namespace Core
61 } // namespace SST
62 
63 #endif // SST_CORE_SERIALIZATION_SERIALIZE_VECTOR_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