|
SST 16.1.0
Structural Simulation Toolkit
|
The Object Tree (ObjTree) is intended to be a developer friendly interface to SST’s existing serialization infrastructure - ObjectMap. More...
#include <ObjTreeLeaves.h>
Public Types | |
| enum class | NodeKind { Generic , Integer , Float , String , Bool , Component , Container , FRef , GenericVal } |
Public Member Functions | |
| ObjTreeCont (const std::string &name, const std::string &type, NodeKind kind=NodeKind::Generic) | |
| ObjTreeCont (const ObjTreeCont &rhs) | |
| ObjTreeCont & | operator= (const ObjTreeCont &rhs) |
| virtual ObjTreeCont * | clone () const |
| void | addChildObj (ObjTreeCont *obj) |
| Adds a child node to the current node. | |
| void | setParent (ObjTreeCont *p) |
| ObjTreeCont * | getParent () const |
| const std::vector< std::unique_ptr< ObjTreeCont > > & | getChildren () const |
| const std::string & | getObjName () const |
| const std::string & | getType () const |
| void | setName (const std::string &name) |
| void | setType (const std::string &type) |
| Set the type of the node - this comes from ObjectMap/Serialization. | |
| bool | isRoot () |
| Returns true if this is the top of the tree - determined by the parent pointer being nullptr. | |
| void | makeReadOnly () |
| Function that will be called if during conversion from ObjectMap the node has been marked as ReadOnly. | |
| bool | isReadOnly () |
| template<typename Func> | |
| void | applyRecursive (Func &&func) |
| Apply a function to all children of this node regardless of type, etc. | |
| template<typename ObjectType, typename Func> | |
| void | applyRecursiveByType (Func &&func) |
| Apply a function to all children of this node of a specific type. | |
| template<typename ObjectType, typename Func> | |
| ObjectType * | findByType (Func &&predicate) |
| Find the first instance of a particular type in this node's children_ that matches criteria set by predicate. | |
| ObjTreeCont * | findByName (const std::string name) |
| Find the first instance of a child with name_ matching name. | |
| virtual void | apply () |
| virtual std::string | getTypeName () const |
| virtual void | Dump (const int verbosity, std::ios_base::fmtflags base=std::ios_base::dec, std::ostream &os=std::cout) |
| Print the contents of the node to the stream specified by os. | |
| virtual bool | setFromString (const std::string &value) |
| Set the value stored in the node from a string. | |
| virtual void | syncFromSim () |
| This function will update the local stored node value with the live value in the sst simulation. | |
| virtual bool | hasChanged () |
| This function will compare the stored the node value with the live simulation value. | |
| NodeKind | getKind () const |
| bool | isComponent () const |
| bool | isLeaf () const |
| virtual void | clear () |
| Clears the entire Object Tree and frees all nodes. | |
Static Protected Member Functions | |
| static void | replaceAll (std::string &s, std::string_view from, std::string_view to) |
| static std::string | prettifyType (std::string t) |
The Object Tree (ObjTree) is intended to be a developer friendly interface to SST’s existing serialization infrastructure - ObjectMap.
This is the base class container from which the type-specific nodes derive. All nodes stored in a std::vector of std::unique_ptr
|
inline |
Adds a child node to the current node.
obj ownership managed by std::unique_ptr. Sets the parent of obj to the current node (this)
| obj | node to insert |
Referenced by SST::Core::Serialization::ObjTree< Obj_T >::BuildTree(), and SST::Core::Serialization::ObjectMapToTree::serializeComponent().
|
inline |
Apply a function to all children of this node regardless of type, etc.
Depending on the nature of func, it may descend to the next level (children's children) of the tree. An example being the Dump() in ContainerObj
| func | - callable function (function pointer, lambda, etc) |
Referenced by SST::Core::Serialization::ContainerObj::Dump(), and Dump().
|
inline |
Apply a function to all children of this node of a specific type.
Type is determined through a successful dynamic_cast to ObjectType Depending on the nature of func, it may descend to the next level (children's children) of the tree. An example being the Dump() in ContainerObj
| func | - callable function (function pointer, lambda, etc) |
Referenced by SST::Core::Serialization::ObjectMapToTree::serializeAllComponents().
|
inlinevirtual |
Clears the entire Object Tree and frees all nodes.
Reimplemented in SST::Core::Serialization::ObjTree< Obj_T >, SST::Core::Serialization::ObjTree< BoolObj >, SST::Core::Serialization::ObjTree< ComponentObj >, SST::Core::Serialization::ObjTree< ContainerObj >, SST::Core::Serialization::ObjTree< FloatObj >, SST::Core::Serialization::ObjTree< GenericValObj >, SST::Core::Serialization::ObjTree< IntegerObj >, and SST::Core::Serialization::ObjTree< StringObj >.
Referenced by SST::Core::Serialization::ObjTree< Obj_T >::clear().
|
inlinevirtual |
Print the contents of the node to the stream specified by os.
Verbosity Level 0 will only print "/" - applicable to the root node only. Any higher Verbosity will trigger a call to Dump() to all children.
| verbosity | - Level 0: Print this node only, which for the base class is "/" Level > 0: Call Dump on all children_ |
| base | - Control the base (dec, hex, oct) to print numerical values in. Default dec. |
| os | - Stream to send the output. Default std::cout |
Reimplemented in SST::Core::Serialization::BoolObj, SST::Core::Serialization::ComponentObj, SST::Core::Serialization::ContainerObj, SST::Core::Serialization::FloatObj, SST::Core::Serialization::GenericValObj, SST::Core::Serialization::IntegerObj, SST::Core::Serialization::ObjTree< Obj_T >, SST::Core::Serialization::ObjTree< BoolObj >, SST::Core::Serialization::ObjTree< ComponentObj >, SST::Core::Serialization::ObjTree< ContainerObj >, SST::Core::Serialization::ObjTree< FloatObj >, SST::Core::Serialization::ObjTree< GenericValObj >, SST::Core::Serialization::ObjTree< IntegerObj >, SST::Core::Serialization::ObjTree< StringObj >, and SST::Core::Serialization::StringObj.
References applyRecursive(), and Dump().
Referenced by SST::Core::Serialization::ContainerObj::Dump(), and Dump().
|
inline |
Find the first instance of a child with name_ matching name.
Does not descend into the tree.
| name | - name of the node you are searching for |
|
inline |
Find the first instance of a particular type in this node's children_ that matches criteria set by predicate.
Examples: Find a ComponentObj whose BaseComponent has a specific name auto* router = root->findByType<ComponentObj>([](ComponentObj* c) { return c->getVal()->getName() == "router"; });
Find the first IntegerObj with value greater than 100 auto* big = root->findByType<IntegerObj>([](IntegerObj* i) { return i->visit([](auto val) { return static_cast<int64_t>(val) > 100; }); });
Find any StringObj (predicate always returns true) auto* anyStr = root->findByType<StringObj>([](StringObj*) { return true; });
Find a ContainerObj that's a vector auto* vec = root->findByType<ContainerObj>([](ContainerObj* c) { return c->getContainerType().find("vector") != std::string::npos; });
| predicate | - callable function (function ptr, lambda, etc) |
|
inlinevirtual |
This function will compare the stored the node value with the live simulation value.
This function will NOT modify the stored value - an independent call to syncFromSim() is required.
Reimplemented in SST::Core::Serialization::BoolObj, SST::Core::Serialization::ContainerObj, SST::Core::Serialization::FloatObj, SST::Core::Serialization::GenericValObj, SST::Core::Serialization::IntegerObj, and SST::Core::Serialization::StringObj.
|
inline |
Returns true if this is the top of the tree - determined by the parent pointer being nullptr.
|
inline |
Function that will be called if during conversion from ObjectMap the node has been marked as ReadOnly.
Once a node is marked ReadOnly it cannont be made writeable.
|
inlinevirtual |
Set the value stored in the node from a string.
This function will be called when the user wants to update the live value in the SST simulation. The function will convert value into the correct type based on the tree node type.
| value | - string representing the value you want to wrtie to the live sim |
Reimplemented in SST::Core::Serialization::BoolObj, SST::Core::Serialization::FloatObj, SST::Core::Serialization::GenericValObj, SST::Core::Serialization::IntegerObj, and SST::Core::Serialization::StringObj.
|
inline |
Set the type of the node - this comes from ObjectMap/Serialization.
The type will be slightly demangled by the prettifyType() function in that std::__1:: and std::__cxx11:: are replaced with just std::
| type | - a string representing te C++ type of the node |
|
inlinevirtual |
This function will update the local stored node value with the live value in the sst simulation.
Reimplemented in SST::Core::Serialization::BoolObj, SST::Core::Serialization::ContainerObj, SST::Core::Serialization::FloatObj, SST::Core::Serialization::IntegerObj, and SST::Core::Serialization::StringObj.