SST 16.1.0
Structural Simulation Toolkit
objectMapTreeBuilder.h
1#ifndef SST_CORE_SERIALIZATION_OBJECTMAP_TREE_BUILDERS_H
2#define SST_CORE_SERIALIZATION_OBJECTMAP_TREE_BUILDERS_H
3
4#include "sst/core/serialization/ObjTreeLeaves.h"
5#include "sst/core/serialization/objectMap.h"
6
7namespace SST::Core::Serialization {
8
9template <typename T, typename REF, typename PTYPE>
10SST::Core::Serialization::ObjTreeCont*
11ObjectMapFundamentalReference<T, REF, PTYPE>::buildTreeNode(const std::string& name)
12{
13 using namespace SST::Core::Serialization;
14
15 // Capture the proxy by value. The proxy holds a back-pointer
16 // into the live storage (bitset/vector<bool>/atomic), so reads
17 // and writes on the captured copy reflect live state.
18
19 REF proxy = ref;
20 ObjTreeCont* node = nullptr;
21
22 // if order matters here - check bool first as is_integral may also match on bool
23 if constexpr ( std::is_same_v<T, bool> ) {
24 node =
25 new BoolObj([proxy]() mutable { return static_cast<bool>(proxy); }, [proxy](bool v) mutable { proxy = v; });
26 }
27 else if constexpr ( std::is_integral_v<T> ) {
28 node = new IntegerObj([proxy]() mutable { return static_cast<int64_t>(static_cast<T>(proxy)); },
29 [proxy](int64_t v) mutable { proxy = static_cast<T>(v); });
30 }
31 else if constexpr ( std::is_floating_point_v<T> ) {
32 node = new FloatObj([proxy]() mutable { return static_cast<long double>(static_cast<T>(proxy)); },
33 [proxy](long double v) mutable { proxy = static_cast<T>(v); });
34 }
35 else {
36 return nullptr;
37 }
38
39 node->setName(name);
40 node->setType(this->getType());
41 if ( this->isReadOnly() ) {
42 if ( auto* b = dynamic_cast<BoolObj*>(node) ) b->makeReadOnly();
43 if ( auto* i = dynamic_cast<IntegerObj*>(node) ) i->makeReadOnly();
44 if ( auto* f = dynamic_cast<FloatObj*>(node) ) f->makeReadOnly();
45 }
46 return node;
47}
48
49} // namespace SST::Core::Serialization
50
51#endif
Definition ObjTreeLeaves.h:941
Definition ObjTreeLeaves.h:572
Definition ObjTreeLeaves.h:405
The Object Tree (ObjTree) is intended to be a developer friendly interface to SST’s existing serializ...
Definition ObjTreeLeaves.h:41
void setType(const std::string &type)
Set the type of the node - this comes from ObjectMap/Serialization.
Definition ObjTreeLeaves.h:124