SST  14.1.0
StructuralSimulationToolkit
serialize_string.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_STRING_H
13 #define SST_CORE_SERIALIZATION_IMPL_SERIALIZE_STRING_H
14 
15 #ifndef SST_INCLUDING_SERIALIZE_H
16 #warning \
17  "The header file sst/core/serialization/impl/serialize_string.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 namespace SST {
23 namespace Core {
24 namespace Serialization {
25 
26 class ObjectMapString : public ObjectMap
27 {
28 protected:
29  std::string* addr_;
30 
31 public:
32  /**
33  Get the address of the represented object
34 
35  @return address of represented object
36  */
37  void* getAddr() override { return addr_; }
38 
39  std::string get() override { return *addr_; }
40 
41  void set_impl(const std::string& value) override { *addr_ = value; }
42 
43  virtual bool isFundamental() override { return true; }
44 
45  /**
46  Get the list of child variables contained in this ObjectMap,
47  which in this case will be empty.
48 
49  @return Refernce to vector containing ObjectMaps for this
50  ObjectMap's child variables. This vector will be empty because
51  strings have no children
52  */
53  const std::vector<std::pair<std::string, ObjectMap*>>& getVariables() override { return emptyVars; }
54 
55  std::string getType() override
56  {
57  // The demangled name for std::string is ridiculously long, so
58  // just return "std::string"
59  return "std::string";
60  }
61 
62  ObjectMapString(std::string* addr) : ObjectMap(), addr_(addr) {}
63 };
64 
65 template <>
66 class serialize_impl<std::string>
67 {
68 public:
69  void operator()(std::string& str, serializer& ser) { ser.string(str); }
70  void operator()(std::string& str, serializer& ser, const char* name)
71  {
72  ObjectMapString* obj_map = new ObjectMapString(&str);
73  ser.mapper().map_primitive(name, obj_map);
74  }
75 };
76 
77 } // namespace Serialization
78 } // namespace Core
79 } // namespace SST
80 
81 #endif // SST_CORE_SERIALIZATION_IMPL_SERIALIZE_STRING_H
This class is basically a wrapper for objects to declare the order in which their members should be s...
Definition: serializer.h:43
std::string getType() override
Get the type of the variable represented by the ObjectMap.
Definition: serialize_string.h:55
static std::vector< std::pair< std::string, ObjectMap * > > emptyVars
Static empty variable vector for use by versions that don&#39;t have variables (i.e.
Definition: objectMap.h:70
Base serialize class.
Definition: serialize.h:45
Definition: action.cc:18
Class created by the serializer mapping mode used to map the variables for objects.
Definition: objectMap.h:61
Definition: serialize_string.h:26
void * getAddr() override
Get the address of the represented object.
Definition: serialize_string.h:37
virtual bool isFundamental() override
Check to see if this ObjectMap represents a fundamental or a class treated as a fundamental.
Definition: serialize_string.h:43
const std::vector< std::pair< std::string, ObjectMap * > > & getVariables() override
Get the list of child variables contained in this ObjectMap, which in this case will be empty...
Definition: serialize_string.h:53