SST 16.0.0
Structural Simulation Toolkit
mapper.h
1// Copyright 2009-2026 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-2026, 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 <cstdint>
23#include <deque>
24#include <string>
25#include <unordered_map>
26
27namespace SST::Core::Serialization::pvt {
28
29class ser_mapper
30{
31 std::unordered_map<uintptr_t, uintptr_t> pointer_map_;
32 std::deque<ObjectMap*> obj_;
33
34public:
35 explicit ser_mapper(ObjectMap* object) :
36 obj_ { object }
37 {}
38
39 ObjectMap* get_top() const { return obj_.back(); }
40
41 void map_object(const std::string& name, ObjectMap* map) { obj_.back()->addVariable(name, map); }
42
43 void map_existing_object(const std::string& name, ObjectMap* map)
44 {
45 map->incRefCount();
46 obj_.back()->addVariable(name, map);
47 }
48
49 void map_hierarchy_start(const std::string& name, ObjectMap* map)
50 {
51 obj_.back()->addVariable(name, map);
52 obj_.push_back(map);
53 }
54
55 void map_hierarchy_end() { obj_.pop_back(); }
56
57 void report_object_map(ObjectMap* ptr)
58 {
59 pointer_map_.insert_or_assign(reinterpret_cast<uintptr_t>(ptr->getAddr()), reinterpret_cast<uintptr_t>(ptr));
60 }
61
62 ObjectMap* check_pointer_map(uintptr_t ptr)
63 {
64 auto it = pointer_map_.find(ptr);
65 return it != pointer_map_.end() ? reinterpret_cast<ObjectMap*>(it->second) : nullptr;
66 }
67
68}; // class ser_wrapper
69
70} // namespace SST::Core::Serialization::pvt
71
72#endif // SST_CORE_SERIALIZATION_IMPL_MAPPER_H
Base class for objects created by the serializer mapping mode used to map the variables for objects.
Definition objectMap.h:188
virtual void addVariable(const std::string &UNUSED(name), ObjectMap *UNUSED(obj))
Adds a variable to this ObjectMap.
Definition objectMap.h:403
void incRefCount()
Increment the reference counter for this ObjectMap.
Definition objectMap.h:332
virtual void * getAddr() const =0
Get the address of the variable represented by the ObjectMap.