SST 16.0.0
Structural Simulation Toolkit
objectMapDeferred.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_OBJECTMAPDEFERRED_H
13#define SST_CORE_SERIALIZATION_OBJECTMAPDEFERRED_H
14
15#include "sst/core/serialization/serializer.h"
16
17#include <map>
18#include <string>
19#include <vector>
20
21namespace SST::Core::Serialization {
22
23/**
24 ObjectMap version that will delay building the internal data
25 structures until the object is "selected". Also, once the object's
26 parent is selected, the internal data will be deleted.
27 */
28template <typename T>
29class ObjectMapDeferred : public ObjectMap
30{
31public:
32 /**
33 Returns type of the deferred object
34
35 @return empty type of object
36 */
37 std::string getType() const final override { return type_; }
38
39 /**
40 Returns nullptr since there is no underlying object being
41 represented
42
43 @return nullptr
44 */
45 void* getAddr() const final override { return addr_; }
46
47
48 /**
49 Get the list of child variables contained in this ObjectMap
50
51 @return Reference to map containing ObjectMaps for this
52 ObjectMap's child variables. pair.first is the name of the
53 variable in the context of this object.
54 */
55 const ObjectMultimap& getVariables() const final override { return obj_->getVariables(); }
56
57 /**
58 For the Deferred Build, the only variable that gets added will
59 be the "real" ObjectMap.
60
61 @param name Name of the object
62 @param obj ObjectMap to add as a variable
63 */
64 void addVariable(const std::string& name, ObjectMap* obj) final override
65 {
66 // This should be the real ObjectMap for the class we are
67 // representing. We will check it by making sure the name
68 // matches what is passed in in the activate_callback()
69 // function.
70 if ( name == "!proxy!" ) {
71 obj_ = obj;
72 }
73 else {
74 printf("WARNING:: ObjectMapDeferred not built properly. No mapping will be available\n");
75 }
76 }
77
78 ObjectMapDeferred(T* addr, const std::string& type) :
79 ObjectMap(),
80 addr_(addr),
81 type_(demangle_name(type.c_str()))
82 {}
83
84 ~ObjectMapDeferred() override { delete obj_; }
85
86protected:
87 void activate_callback() final override
88 {
89 // On activate, we need to create the ObjectMap data structure
90 if ( obj_ ) return;
91
93 ser.enable_pointer_tracking();
94 ser.start_mapping(this);
95
96 SST_SER_NAME(addr_, "!proxy!");
97 }
98
99 void deactivate_callback() final override
100 {
101 // On deactivate, need to delete obj_;
102 obj_->decRefCount();
103 obj_ = nullptr;
104 }
105
106
107private:
108 /**
109 ObjectMap for the real data
110 */
111 ObjectMap* obj_ = nullptr;
112
113 /**
114 Object this ObjectMap represents
115 */
116 T* addr_ = nullptr;
117
118 /**
119 Type of the variable as given by the demangled version of
120 typeid(T).name() for the type.
121 */
122 std::string type_ = "";
123};
124
125} // namespace SST::Core::Serialization
126
127#endif // SST_CORE_SERIALIZATION_OBJECTMAPDEFERRED_H
ObjectMap version that will delay building the internal data structures until the object is "selected...
Definition objectMapDeferred.h:30
void deactivate_callback() final override
Function that will get called when this object is deactivated (i.e selectParent() is called).
Definition objectMapDeferred.h:99
const ObjectMultimap & getVariables() const final override
Get the list of child variables contained in this ObjectMap.
Definition objectMapDeferred.h:55
std::string getType() const final override
Returns type of the deferred object.
Definition objectMapDeferred.h:37
void addVariable(const std::string &name, ObjectMap *obj) final override
For the Deferred Build, the only variable that gets added will be the "real" ObjectMap.
Definition objectMapDeferred.h:64
void * getAddr() const final override
Returns nullptr since there is no underlying object being represented.
Definition objectMapDeferred.h:45
void activate_callback() final override
Function that will get called when this object is selected.
Definition objectMapDeferred.h:87
Base class for objects created by the serializer mapping mode used to map the variables for objects.
Definition objectMap.h:188
ObjectMap()=default
Default constructor primarily used for the "top" object in the hierarchy.
static std::string demangle_name(const char *name)
Static function to demangle type names returned from typeid(T).name().
Definition objectMap.cc:152
This class is basically a wrapper for objects to declare the order in which their members should be s...
Definition serializer.h:43