SST 16.1.0
Structural Simulation Toolkit
ObjTree.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_OBJECTTREE_DEBUGGER_H
13#define SST_CORE_SERIALIZATION_OBJECTTREE_DEBUGGER_H
14
15#include "sst/core/baseComponent.h"
16#include "sst/core/componentInfo.h"
17#include "sst/core/from_string.h"
18#include "sst/core/serialization/ObjTreeLeaves.h"
19#include "sst/core/serialization/objectMapDeferred.h"
20#include "sst/core/warnmacros.h"
21
22#include <algorithm>
23#include <any>
24#include <cassert>
25#include <cctype>
26#include <cerrno>
27#include <cstddef>
28#include <cstdint>
29#include <cstdio>
30#include <cstdlib>
31#include <cstring>
32#include <exception>
33#include <functional>
34#include <iostream>
35#include <map>
36#include <memory>
37#include <ostream>
38#include <stdexcept>
39#include <string>
40#include <type_traits>
41#include <typeinfo>
42#include <unordered_set>
43#include <utility>
44#include <vector>
45
46namespace SST::Core::Serialization {
47
48
49class ComponentObj : public ObjTree<ComponentObj>
50{
51
52private:
53 BaseComponent* val_ = nullptr;
54 ComponentInfo* compInfo_ = nullptr;
55
56public:
57 ComponentObj() = default;
58 ComponentObj(BaseComponent* v, ComponentInfo* ci) :
59 ObjTree<ComponentObj>(NodeKind::Component),
60 val_(v),
61 compInfo_(ci)
62 {
63 setName(v->getName());
64 }
65
66 ComponentObj(const ComponentObj& rhs) :
67 ObjTree<ComponentObj>(rhs),
68 val_(rhs.val_),
69 compInfo_(rhs.compInfo_)
70 {}
71
72 ComponentObj& operator=(const ComponentObj& rhs)
73 {
74 if ( this == &rhs ) return *this;
75 ObjTree<ComponentObj>::operator=(rhs);
76 val_ = rhs.val_;
77 compInfo_ = rhs.compInfo_;
78 return *this;
79 }
80
81 ObjTreeCont* clone() const override { return new ComponentObj(*this); }
82
83 BaseComponent* getVal() const { return val_; }
84 ComponentInfo* getInfo() const { return compInfo_; }
85
86 void setVal(BaseComponent* v) { val_ = v; }
87
88 void apply() override { std::cout << "Processing component: " << val_->getName() << std::endl; }
89 void Dump([[maybe_unused]] const int verbosity, [[maybe_unused]] std::ios_base::fmtflags base = std::ios_base::dec,
90 std::ostream& os = std::cout) override
91 {
92 if ( verbosity < 3 ) {
93 os << val_->getName() << "/" << std::endl;
94 }
95 else {
96 os << val_->getName() << "/ (" << compInfo_->getType() << ")" << std::endl;
97 }
98 }
99
100 ComponentObj* find(const std::string name)
101 {
102 ComponentObj* result = nullptr;
103 applyRecursiveByType<ComponentObj>([&result, &name](ComponentObj* obj) {
104 if ( obj->getVal()->getName() == name ) {
105 result = obj;
106 }
107 });
108 return result;
109 }
110};
111
112template <typename Obj_T>
113void
115{
116 if ( !children_.empty() ) {
117 std::cout << "WARNING: Calling BuildTree on non-empty ObjTree" << std::endl;
118 }
119 for ( auto comp = compMap.begin(); comp != compMap.end(); comp++ ) {
120 ComponentInfo* compinfo = *comp;
121 BaseComponent* bc = compinfo->getComponent();
122 ComponentObj* c = new ComponentObj(bc, compinfo);
123 addChildObj(c);
124 }
125
126 std::sort(children_.begin(), children_.end(),
127 [](const std::unique_ptr<ObjTreeCont>& a, const std::unique_ptr<ObjTreeCont>& b) {
128 return a->getObjName() < b->getObjName();
129 });
130}
131
132
133} // namespace SST::Core::Serialization
134
135#endif
Main component object for the simulation.
Definition baseComponent.h:98
const std::string & getName() const
Get the name of the BaseComponent.
Definition baseComponent.h:151
Definition componentInfo.h:285
Definition componentInfo.h:45
void Dump(const int verbosity, std::ios_base::fmtflags base=std::ios_base::dec, std::ostream &os=std::cout) override
Print the contents of the node to the stream specified by os.
Definition ObjTree.h:89
The Object Tree (ObjTree) is intended to be a developer friendly interface to SST’s existing serializ...
Definition ObjTreeLeaves.h:41
void addChildObj(ObjTreeCont *obj)
Adds a child node to the current node.
Definition ObjTreeLeaves.h:103
void BuildTree(const ComponentInfoMap &compMap)
Each time we break into the debugger we rebuild the ObjectTree based on the current ComponentInfoMap.
Definition ObjTree.h:114