SST  14.1.0
StructuralSimulationToolkit
objectMapDeferred.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_OBJECTMAPDEFERRED_H
13 #define SST_CORE_SERIALIZATION_OBJECTMAPDEFERRED_H
14 
15 #include "sst/core/serialization/serializer.h"
16 
17 
18 namespace SST {
19 namespace Core {
20 namespace Serialization {
21 
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  */
28 template <typename T>
30 {
31 public:
32  /**
33  Returns type of the deferred object
34 
35  @return empty type of object
36  */
37  std::string getType() 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() override { return static_cast<void*>(addr_); }
46 
47 
48  /**
49  Get the list of child variables contained in this ObjectMap
50 
51  @return Refernce to vector 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 std::vector<std::pair<std::string, ObjectMap*>>& getVariables() 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) 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!" ) { obj_ = obj; }
71  else {
72  printf("WARNING:: ObjectMapDeferred no built properly. No mapping will be available\n");
73  }
74  }
75 
76  ObjectMapDeferred(T* addr, const std::string& type) : ObjectMap(), addr_(addr), type_(demangle_name(type.c_str()))
77  {}
78 
80  {
81  if ( obj_ != nullptr ) delete obj_;
82  }
83 
84 protected:
85  void activate_callback() override
86  {
87  // On activate, we need to create the ObjectMap data structure
88  if ( obj_ != nullptr ) return;
89 
91  ser.enable_pointer_tracking();
92  ser.start_mapping(this);
93 
94  sst_map_object(ser, addr_, "!proxy!");
95  }
96 
97  void deactivate_callback() override
98  {
99  // On deactivate, need to delete obj_;
100  obj_->decRefCount();
101  obj_ = nullptr;
102  }
103 
104 
105 private:
106  /**
107  ObjectMap for the real data
108  */
109  ObjectMap* obj_ = nullptr;
110 
111  /**
112  Object this ObjectMap represents
113  */
114  T* addr_ = nullptr;
115 
116  /**
117  Type of the variable as given by the demangled version of
118  typeif<T>.name() for the type.
119  */
120  std::string type_ = "";
121 };
122 
123 
124 } // namespace Serialization
125 } // namespace Core
126 } // namespace SST
127 
128 #endif // SST_CORE_SERIALIZATION_OBJECTMAPDEFERRED_H
This class is basically a wrapper for objects to declare the order in which their members should be s...
Definition: serializer.h:43
void activate_callback() override
Function that will get called when this object is selected.
Definition: objectMapDeferred.h:85
ObjectMap version that will delay building the internal data structures until the object is "selected...
Definition: objectMapDeferred.h:29
virtual const std::vector< std::pair< std::string, ObjectMap * > > & getVariables()
Get the list of child variables contained in this ObjectMap.
Definition: objectMap.h:161
Definition: action.cc:18
Class created by the serializer mapping mode used to map the variables for objects.
Definition: objectMap.h:61
const std::vector< std::pair< std::string, ObjectMap * > > & getVariables() override
Get the list of child variables contained in this ObjectMap.
Definition: objectMapDeferred.h:55
std::string getType() override
Returns type of the deferred object.
Definition: objectMapDeferred.h:37
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:64
void * getAddr() override
Returns nullptr since there is no underlying object being represented.
Definition: objectMapDeferred.h:45
static std::string demangle_name(const char *name)
Static function to demangle type names returned from typeid<T>.name()
Definition: objectMap.cc:139
void decRefCount()
Decreament the reference counter for this object map.
Definition: objectMap.h:175