SST  14.1.0
StructuralSimulationToolkit
mapper.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_MAPPER_H
13 #define SST_CORE_SERIALIZATION_IMPL_MAPPER_H
14 
15 #ifndef SST_INCLUDING_SERIALIZER_H
16 #warning \
17  "The header file sst/core/serialization/impl/mapper.h should not be directly included as it is not part of the stable public API. The file is included in sst/core/serialization/serializer.h"
18 #endif
19 
20 #include "sst/core/serialization/objectMap.h"
21 
22 #include <string>
23 #include <typeinfo>
24 #include <vector>
25 
26 namespace SST {
27 namespace Core {
28 namespace Serialization {
29 namespace pvt {
30 
32 {
33  std::vector<ObjectMap*> obj_;
34  bool next_item_read_only = false;
35 
36 public:
37  void map_primitive(const std::string& name, ObjectMap* map)
38  {
39  obj_.back()->addVariable(name, map);
40  if ( next_item_read_only ) {
41  next_item_read_only = false;
42  map->setReadOnly();
43  }
44  }
45 
46  void map_container(const std::string& name, ObjectMap* map)
47  {
48  obj_.back()->addVariable(name, map);
49  if ( next_item_read_only ) { next_item_read_only = false; }
50  }
51 
52  void map_existing_object(const std::string& name, ObjectMap* map)
53  {
54  map->incRefCount();
55  obj_.back()->addVariable(name, map);
56  if ( next_item_read_only ) { next_item_read_only = false; }
57  }
58 
59  void map_hierarchy_start(const std::string& name, ObjectMap* map)
60  {
61  obj_.back()->addVariable(name, map);
62  obj_.push_back(map);
63 
64  indent++;
65  if ( next_item_read_only ) { next_item_read_only = false; }
66  }
67 
68  void map_hierarchy_end()
69  {
70  obj_.pop_back();
71  indent--;
72  }
73 
74  void init(ObjectMap* object) { obj_.push_back(object); }
75 
76  void reset() { obj_.clear(); }
77 
78  /**
79  * @brief pack_buffer
80  * @param buf Must be non-null
81  * @param size Must be non-zero
82  */
83  void map_buffer(void* buf, int size);
84 
85  void setNextObjectReadOnly() { next_item_read_only = true; }
86 
87 private:
88  int indent = 0;
89 };
90 
91 } // namespace pvt
92 } // namespace Serialization
93 } // namespace Core
94 } // namespace SST
95 
96 #endif // SST_CORE_SERIALIZATION_IMPL_MAPPER_H
Definition: action.cc:18
Class created by the serializer mapping mode used to map the variables for objects.
Definition: objectMap.h:61
void incRefCount()
Increament the reference counter for this object map.
Definition: objectMap.h:167
void map_buffer(void *buf, int size)
pack_buffer