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