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