SST 16.1.0
Structural Simulation Toolkit
SST::Core::Serialization::ObjTreeCont Class Reference

The Object Tree (ObjTree) is intended to be a developer friendly interface to SST’s existing serialization infrastructure - ObjectMap. More...

#include <ObjTreeLeaves.h>

Inheritance diagram for SST::Core::Serialization::ObjTreeCont:
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 > SST::Core::Serialization::ObjTree< Obj_T >

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)

Protected Attributes

ObjTreeCont * parent_ = nullptr
std::vector< std::unique_ptr< ObjTreeCont > > children_
std::string name_ = "uninit"
std::string type_ = "uninit"
NodeKind kind_ = NodeKind::Generic
bool readOnly_ = false

Detailed Description

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

Member Function Documentation

◆ addChildObj()

void SST::Core::Serialization::ObjTreeCont::addChildObj ( ObjTreeCont * obj)
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)

Parameters
objnode to insert

Referenced by SST::Core::Serialization::ObjTree< Obj_T >::BuildTree(), and SST::Core::Serialization::ObjectMapToTree::serializeComponent().

◆ applyRecursive()

template<typename Func>
void SST::Core::Serialization::ObjTreeCont::applyRecursive ( Func && func)
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

Parameters
func- callable function (function pointer, lambda, etc)

Referenced by SST::Core::Serialization::ContainerObj::Dump(), and Dump().

◆ applyRecursiveByType()

template<typename ObjectType, typename Func>
void SST::Core::Serialization::ObjTreeCont::applyRecursiveByType ( Func && func)
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

Parameters
func- callable function (function pointer, lambda, etc)

Referenced by SST::Core::Serialization::ObjectMapToTree::serializeAllComponents().

◆ clear()

◆ Dump()

virtual void SST::Core::Serialization::ObjTreeCont::Dump ( const int verbosity,
std::ios_base::fmtflags base = std::ios_base::dec,
std::ostream & os = std::cout )
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.

Parameters
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
Returns
pointer to node, if found, nullptr otherwise

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().

◆ findByName()

ObjTreeCont * SST::Core::Serialization::ObjTreeCont::findByName ( const std::string name)
inline

Find the first instance of a child with name_ matching name.

Does not descend into the tree.

Parameters
name- name of the node you are searching for
Returns
pointer to node, if found, nullptr otherwise

◆ findByType()

template<typename ObjectType, typename Func>
ObjectType * SST::Core::Serialization::ObjTreeCont::findByType ( Func && predicate)
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; });

Parameters
predicate- callable function (function ptr, lambda, etc)
Returns
pointer to matched node, nullptr if not found

◆ hasChanged()

virtual bool SST::Core::Serialization::ObjTreeCont::hasChanged ( )
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.

Returns
true if the value in the live simulation differs from the stored node value. false otherwise

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.

◆ isRoot()

bool SST::Core::Serialization::ObjTreeCont::isRoot ( )
inline

Returns true if this is the top of the tree - determined by the parent pointer being nullptr.

Returns
true if parent == null, false otherwise

◆ makeReadOnly()

void SST::Core::Serialization::ObjTreeCont::makeReadOnly ( )
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.

◆ setFromString()

virtual bool SST::Core::Serialization::ObjTreeCont::setFromString ( const std::string & value)
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.

Parameters
value- string representing the value you want to wrtie to the live sim
Returns
- true if successful, false otherwise

Reimplemented in SST::Core::Serialization::BoolObj, SST::Core::Serialization::FloatObj, SST::Core::Serialization::GenericValObj, SST::Core::Serialization::IntegerObj, and SST::Core::Serialization::StringObj.

◆ setType()

void SST::Core::Serialization::ObjTreeCont::setType ( const std::string & type)
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::

Parameters
type- a string representing te C++ type of the node

◆ syncFromSim()

virtual void SST::Core::Serialization::ObjTreeCont::syncFromSim ( )
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.


The documentation for this class was generated from the following file: