sys-sage
Loading...
Searching...
No Matches
Public Member Functions | Public Attributes | Protected Member Functions | Protected Attributes | List of all members
sys_sage::Component Class Reference

Generic class for all hardware and logical components in sys-sage. More...

#include <Component.hpp>

Inheritance diagram for sys_sage::Component:
sys_sage::Cache sys_sage::Chip sys_sage::Core sys_sage::Memory sys_sage::Node sys_sage::QuantumBackend sys_sage::Qubit sys_sage::Storage sys_sage::Subdivision sys_sage::Thread sys_sage::Topology

Public Member Functions

 Component (int _id=0, std::string _name="unknown")
 Generic Component constructor (no automatic insertion in the Component Tree). Usually one of the derived subclasses for different Component Types will be created, not this one.
 
 Component (Component *parent, int _id=0, std::string _name="unknown")
 Generic Component constructor with insertion into the Component Tree as the parent's child. Usually one of the derived subclasses for different Component Types will be created.
 
void InsertChild (Component *child)
 Inserts a child component to this component (in the Component Tree). The child pointer will be inserted at the end of the children vector.
 
int InsertBetweenParentAndChild (Component *parent, Component *child, bool alreadyParentsChild)
 Inserts this component between a parent and one of its children. The parent component remains the parent, this Component becomes a new child of the parent, and the specified child becomes this component's child.
 
int InsertBetweenParentAndChildren (Component *parent, std::vector< Component * > children, bool alreadyParentsChild)
 Inserts this component between a parent and a (subset of) its children. The parent component remains parent, this Component becomes a new child, and the children become parent's grandchildren.
 
int RemoveChild (Component *child)
 Removes the passed component from the list of children, without completely deleting (and deallocating) the child itself.
 
void SetParent (Component *parent)
 Set a parent to the component. This is usually used when inserting a component in the tree (by calling InsertChild on the parent, and calling SetParent on the child).
 
void PrintSubtree () const
 Prints the whole subtree of this component (including the component itself) to stdout. The tree is printed in DFS order, so that the hierarchy can be easily seen. Each child is indented by " ". For each component in the subtree, the following is printed: "<string component type> (name <name>) id <id> - children: <num children>
 
void PrintAllDataPathsInSubtree ()
 Prints all DataPaths that go from or to components in the subtree.
 
void PrintAllRelationsInSubtree (RelationType::type RelationType=RelationType::Any)
 Prints all Relations in the subtree.
 
const std::string & GetName () const
 Returns name of the component.
 
void SetName (std::string _name)
 Sets name of the component.
 
int GetId () const
 Returns id of the component.
 
sys_sage::ComponentType::type GetComponentType () const
 Returns component type of the component. The component type denotes which class the instance is (often stored as Component*, even though they are a member of one of the child classes).
 
std::string GetComponentTypeStr () const
 Returns component type as a human-readable string, as defined in ComponentType::names.
 
const std::vector< Component * > & GetChildren () const
 Returns a const reference to std::vector containing all children of the component (empty vector if no children).
 
ComponentGetParent () const
 Returns Component pointer to parent (or NULL if this component is the root)
 
ComponentGetChild (int _id) const
 Retrieve a Component* to a child with child.id=_id. Identical to GetChildById
Should there be more children with the same id, the first match will be retrieved (i.e. the one with lower index in the children array.)
 
ComponentGetChildById (int _id) const
 Retrieve a Component* to a child with child.id=_id. Should there be more children with the same id, the first match will be retrieved (i.e. the one with lower index in the children array.)
 
ComponentGetChildByType (ComponentType::type _componentType) const
 Retrieve a Component* to a child matching the given component type. Should there be more children with the same type, the first match will be retrieved (i.e. the one with lower index in the children array.)
 
std::vector< Component * > GetAllChildrenByType (ComponentType::type _componentType) const
 Searches for all children matching the given component type.
 
void GetAllChildrenByType (std::vector< Component * > *_outArray, ComponentType::type _componentType) const
 Searches for all the children matching the given component type.
 
ComponentGetSubcomponentById (int _id, ComponentType::type _componentType)
 Searches the subtree to find a component with a matching id and componentType, i.e. looks for a certain component with a matching ID. The search is a DFS. The search starts with the calling component.
 
void GetAllSubcomponentsByType (std::vector< Component * > *outArray, ComponentType::type _componentType)
 Searches for all the subcomponents (children, their children and so on) matching the given component type.
 
std::vector< Component * > GetAllSubcomponentsByType (ComponentType::type _componentType)
 Searches for all the subcomponents (children, their children and so on) matching the given component type.
 
int CountAllSubcomponents () const
 Counts number of subcomponents (children, grandchildren, etc.).
 
int CountAllSubcomponentsByType (ComponentType::type _componentType) const
 Counts number of subcomponents (children, their children and so on) matching the requested component type.
 
int CountAllChildrenByType (ComponentType::type _componentType) const
 Counts number of children matching the requested component type.
 
ComponentGetAncestorByType (ComponentType::type _componentType)
 Moves up the tree until a parent of the given type is found.
 
int GetSubtreeDepth () const
 Retrieves maximal distance to a leaf (i.e. the depth of the subtree). 0=leaf, 1=children are leaves, 2=at most children's children are leaves .....
 
ComponentGetNthAncestor (int n)
 Retrieves Nth ancestor, which resides N levels above. E.g. if n=1, the parent is retrieved; if n=2, the grandparent is retrieved and so on.
 
void GetNthDescendents (std::vector< Component * > *outArray, int depth)
 Retrieves a std::vector of Component pointers, which reside 'depth' levels deeper. The tree is traversed in order as the children are stored in std::vector children. E.g. if depth=1, only children of the current are retrieved; if depth=2, only children of the children are retrieved..
 
std::vector< Component * > GetNthDescendents (int depth)
 Retrieves a std::vector of Component pointers, which reside 'depth' levels deeper. The tree is traversed in order as the children are stored in the std::vector. E.g. if depth=1, only children of the current are retrieved; if depth=2, only children of the children are retrieved..
 
void GetSubcomponentsByType (std::vector< Component * > *outArray, int componentType)
 Retrieves a std::vector of Component pointers, which reside in the subtree and have a matching type. The tree is traversed DFS in order as the children are stored in each std::vector children.
 
std::vector< Component * > GetSubcomponentsByType (ComponentType::type _componentType)
 Retrieves a std::vector of Component pointers, which reside in the subtree and have a matching type. The tree is traversed DFS in order as the children are stored in the std::vector.
 
void GetComponentsInSubtree (std::vector< Component * > *outArray)
 Retrieves a std::vector of Component pointers, which form the subtree (current node and all the subcomponents) of this.
 
std::vector< Component * > GetComponentsInSubtree ()
 Retrieves a std::vector of Component pointers, which form the subtree (current node and all the subcomponents) of this.
 
const std::vector< Relation * > & GetRelations (RelationType::type relationType) const
 Returns a (const) reference to the internal vector of relations for a given type.
 
std::vector< Relation * > GetAllRelationsBy (RelationType::type relationType=RelationType::Any, int thisComponentPosition=-1) const
 Returns a newly-constructed vector of all relations of a given type and position.
 
DataPathGetDataPathByType (DataPathType::type dp_type, DataPathDirection::type direction=DataPathDirection::Any) const
 Retrieves a DataPath* from the list of this component's data paths with matching DataPathType and DataPathDirection. The first match is returned.
 
void GetAllDataPaths (std::vector< DataPath * > *outDpArr, DataPathType::type dp_type=DataPathType::Any, DataPathDirection::type direction=DataPathDirection::Any) const
 Retrieves all DataPath* from the list of this component's data paths with matching type and orientation. Results are returned in std::vector<DataPath*>* outDpArr, where first the matching data paths in dp_outgoing are pushed back, then the ones in dp_incoming.
 
std::vector< DataPath * > GetAllDataPaths (DataPathType::type dp_type=DataPathType::Any, DataPathDirection::type direction=DataPathDirection::Any) const
 Retrieves all DataPath* from the list of this component's data paths with matching type and orientation/direction. Results are returned in a std::vector<DataPath*>*.
 
int CheckComponentTreeConsistency () const
 Checks the consistency of the component tree starting from this component.
 
int GetTopologySize (unsigned *out_component_size, unsigned *out_dataPathSize) const
 Calculates approximate memory footprint of the subtree of this element (including the relevant Relations).
 
int GetDepth (bool refresh)
 Retrieves the depth (level) of a component in the topology.
 
void DeleteRelation (Relation *r)
 Deletes a Relation from this component as well as the Relation itself.
 
void DeleteDataPath (DataPath *dp)
 Deletes and deallocates the DataPath pointer from the list of outgoing/incoming DataPaths.
 
void DeleteAllRelations (RelationType::type relationType=RelationType::Any)
 Deletes all relations of this component (optionally filtered by type).
 
void DeleteAllDataPaths ()
 Deletes all DataPaths of this component.
 
void DeleteSubtree () const
 
void Delete (bool withSubtree=true)
 Deletes a component, its children (if withSubtree = true), and all associated Relations. If only the component itself is deleted, its children are inserted into its parent's children list.
 

Public Attributes

std::map< std::string, void * > attrib
 

Protected Member Functions

 Component (int _id, std::string _name, ComponentType::type _componentType)
 Protected constructor for derived classes (no automatic insertion in the Component Tree).
 
 Component (Component *parent, int _id, std::string _name, ComponentType::type _componentType)
 Protected constructor for derived classes with insertion into the Component Tree.
 

Protected Attributes

int id
 
int depth
 
std::string name
 
int count {-1}
 
const ComponentType::type componentType
 
std::vector< Component * > children
 
Componentparent { nullptr }
 
std::array< std::vector< Relation * > *, RelationType::_num_relation_types > * relations = nullptr
 

Detailed Description

Generic class for all hardware and logical components in sys-sage.

All components inherit from this class, which defines attributes and methods common to all components. This enables a unified interface for tree traversal, querying, and manipulation. Usually, a Component instance is one of the derived subclasses, but a generic Component is also possible.

Constructor & Destructor Documentation

◆ Component() [1/4]

sys_sage::Component::Component ( int _id = 0,
std::string _name = "unknown" )

Generic Component constructor (no automatic insertion in the Component Tree). Usually one of the derived subclasses for different Component Types will be created, not this one.

Parameters
_idNumeric ID of the component (default 0)
_nameName of the component (default "unknown")

Sets componentType to sys_sage::ComponentType::None.

◆ Component() [2/4]

sys_sage::Component::Component ( Component * parent,
int _id = 0,
std::string _name = "unknown" )

Generic Component constructor with insertion into the Component Tree as the parent's child. Usually one of the derived subclasses for different Component Types will be created.

Parameters
parentPointer to the parent component
_idNumeric ID of the component (default 0)
_nameName of the component (default "unknown")

Sets componentType to sys_sage::ComponentType::None.

◆ Component() [3/4]

sys_sage::Component::Component ( int _id,
std::string _name,
ComponentType::type _componentType )
protected

Protected constructor for derived classes (no automatic insertion in the Component Tree).

Parameters
_idNumeric ID of the component
_nameName of the component
_componentTypeComponent type (of type sys_sage::ComponentType::type)

◆ Component() [4/4]

sys_sage::Component::Component ( Component * parent,
int _id,
std::string _name,
ComponentType::type _componentType )
protected

Protected constructor for derived classes with insertion into the Component Tree.

Parameters
parentPointer to the parent component
_idNumeric ID of the component
_nameName of the component
_componentTypeComponent type (of type sys_sage::ComponentType::type)

Member Function Documentation

◆ CheckComponentTreeConsistency()

int sys_sage::Component::CheckComponentTreeConsistency ( ) const

Checks the consistency of the component tree starting from this component.

This function verifies that each child component has this component set as its parent. It logs an error message for each child that has an incorrect parent and increments the error count. The function then recursively checks the consistency of the entire subtree rooted at each child component.

Returns
The total number of inconsistencies found in the component tree.

The function returns the total number of errors found in the component tree, including errors in the direct children and any nested descendants.

◆ CountAllChildrenByType()

int sys_sage::Component::CountAllChildrenByType ( ComponentType::type _componentType) const

Counts number of children matching the requested component type.

Parameters
_componentType- ComponentType to look for.
Returns
Returns number of children matching the requested component type.

◆ CountAllSubcomponents()

int sys_sage::Component::CountAllSubcomponents ( ) const

Counts number of subcomponents (children, grandchildren, etc.).

Returns
Number of subcomponents

◆ CountAllSubcomponentsByType()

int sys_sage::Component::CountAllSubcomponentsByType ( ComponentType::type _componentType) const

Counts number of subcomponents (children, their children and so on) matching the requested component type.

Parameters
_componentType- ComponentType to look for.
Returns
Returns number of subcomponents matching the requested component type.

◆ Delete()

void sys_sage::Component::Delete ( bool withSubtree = true)

Deletes a component, its children (if withSubtree = true), and all associated Relations. If only the component itself is deleted, its children are inserted into its parent's children list.

Parameters
withSubtreeIf true, the whole subtree is deleted; otherwise only the component itself.

◆ DeleteAllDataPaths()

void sys_sage::Component::DeleteAllDataPaths ( )

Deletes all DataPaths of this component.

Deprecated
Use void DeleteAllRelations(int32_t relationType = sys_sage::RelationType::Any) instead.

◆ DeleteAllRelations()

void sys_sage::Component::DeleteAllRelations ( RelationType::type relationType = RelationType::Any)

Deletes all relations of this component (optionally filtered by type).

Parameters
relationTypeRelation type to delete (default: Any)

◆ DeleteDataPath()

void sys_sage::Component::DeleteDataPath ( DataPath * dp)

Deletes and deallocates the DataPath pointer from the list of outgoing/incoming DataPaths.

Deprecated
Use void DeleteRelation(Relation * r) instead.
Parameters
dpDataPath to delete

◆ DeleteRelation()

void sys_sage::Component::DeleteRelation ( Relation * r)

Deletes a Relation from this component as well as the Relation itself.

Parameters
rPointer to the relation to delete
See also
Relation/DataPath/QuantumGate Delete()

◆ DeleteSubtree()

void sys_sage::Component::DeleteSubtree ( ) const

Deletes the whole subtree (all the children) of the component.

◆ GetAllChildrenByType() [1/2]

std::vector< Component * > sys_sage::Component::GetAllChildrenByType ( ComponentType::type _componentType) const

Searches for all children matching the given component type.

Parameters
_componentTypeRequired type of components
Returns
Vector of all matching children

◆ GetAllChildrenByType() [2/2]

void sys_sage::Component::GetAllChildrenByType ( std::vector< Component * > * _outArray,
ComponentType::type _componentType ) const

Searches for all the children matching the given component type.

Parameters
_componentType- Required type of components
outArray- output parameter (vector with results)
An input is pointer to a std::vector<Component *>, in which the elements will be pushed. It must be allocated before the call (but does not have to be empty).
The method pushes back the found elements – i.e. the elements(pointers) can be found in this array after the method returns. (If no found, nothing will be pushed into the vector.)

◆ GetAllDataPaths() [1/2]

std::vector< sys_sage::DataPath * > sys_sage::Component::GetAllDataPaths ( DataPathType::type dp_type = DataPathType::Any,
DataPathDirection::type direction = DataPathDirection::Any ) const

Retrieves all DataPath* from the list of this component's data paths with matching type and orientation/direction. Results are returned in a std::vector<DataPath*>*.

Parameters
dp_typeDataPath type to search for (default: Any)
directionOrientation (default: Any)
Returns
Vector of matching DataPaths

◆ GetAllDataPaths() [2/2]

void sys_sage::Component::GetAllDataPaths ( std::vector< DataPath * > * outDpArr,
DataPathType::type dp_type = DataPathType::Any,
DataPathDirection::type direction = DataPathDirection::Any ) const

Retrieves all DataPath* from the list of this component's data paths with matching type and orientation. Results are returned in std::vector<DataPath*>* outDpArr, where first the matching data paths in dp_outgoing are pushed back, then the ones in dp_incoming.

Parameters
outDpArr- output parameter (vector with results) An input is pointer to a std::vector<DataPath *>, in which the data paths will be pushed. It must be allocated before the call (but does not have to be empty). The method pushes back the found data paths – i.e. the data paths(pointers) can be found in this array after the method returns. (If no found, the vector is not changed.)
dp_typeDataPath type to search for (default: Any)
directionOrientation/direction of a DataPath (default: Any)

◆ GetAllRelationsBy()

std::vector< sys_sage::Relation * > sys_sage::Component::GetAllRelationsBy ( RelationType::type relationType = RelationType::Any,
int thisComponentPosition = -1 ) const

Returns a newly-constructed vector of all relations of a given type and position.

Parameters
relationTypeType of relation (default: Any)
thisComponentPositionPosition of this component in the relation (default: -1 = do NOT care about position)
Returns
Vector of matching relations (copy, not reference)
See also
getRelations(RelationType::type relationType) const as an alternative that returns a reference to the internal structure, i.e. has less overhead.

◆ GetAllSubcomponentsByType() [1/2]

std::vector< Component * > sys_sage::Component::GetAllSubcomponentsByType ( ComponentType::type _componentType)

Searches for all the subcomponents (children, their children and so on) matching the given component type.

Parameters
_componentType- Required type of components.
Returns
A vector of all the subcomponents matching the _componentType.

◆ GetAllSubcomponentsByType() [2/2]

void sys_sage::Component::GetAllSubcomponentsByType ( std::vector< Component * > * outArray,
ComponentType::type _componentType )

Searches for all the subcomponents (children, their children and so on) matching the given component type.

Parameters
_componentType- Required type of components
outArray- output parameter (vector with results)
An input is pointer to a std::std::vector<Component *>, in which the elements will be pushed. It must be allocated before the call (but does not have to be empty).
The method pushes back the found elements – i.e. the elements(pointers) can be found in this array after the method returns. (If no found, nothing will be pushed into the vector.)

◆ GetAncestorByType()

sys_sage::Component * sys_sage::Component::GetAncestorByType ( ComponentType::type _componentType)

Moves up the tree until a parent of the given type is found.

Parameters
_componentTypeDesired component type
Returns
Pointer to the ancestor, or nullptr if not found

◆ GetChild()

sys_sage::Component * sys_sage::Component::GetChild ( int _id) const

Retrieve a Component* to a child with child.id=_id. Identical to GetChildById
Should there be more children with the same id, the first match will be retrieved (i.e. the one with lower index in the children array.)

See also
GetChildById

◆ GetChildByType()

sys_sage::Component * sys_sage::Component::GetChildByType ( ComponentType::type _componentType) const

Retrieve a Component* to a child matching the given component type. Should there be more children with the same type, the first match will be retrieved (i.e. the one with lower index in the children array.)

Parameters
_componentTypeComponent type to match
Returns
Pointer to the first matching child, or nullptr if not found

◆ GetChildren()

const std::vector< sys_sage::Component * > & sys_sage::Component::GetChildren ( ) const

Returns a const reference to std::vector containing all children of the component (empty vector if no children).

Returns
const std::vector<Component *> & with children

◆ GetComponentsInSubtree() [1/2]

std::vector< sys_sage::Component * > sys_sage::Component::GetComponentsInSubtree ( )

Retrieves a std::vector of Component pointers, which form the subtree (current node and all the subcomponents) of this.

Returns
A std::vector<Component*> with the results.

◆ GetComponentsInSubtree() [2/2]

void sys_sage::Component::GetComponentsInSubtree ( std::vector< Component * > * outArray)

Retrieves a std::vector of Component pointers, which form the subtree (current node and all the subcomponents) of this.

Parameters
outArray- output parameter (vector with results) An input is pointer to a std::vector<Component *>, in which the elements will be pushed. It must be allocated before the call (but does not have to be empty). The method pushes back the found elements – i.e. the elements(pointers) can be found in this array after the method returns. (If no found, the vector is not changed.)

◆ GetComponentType()

sys_sage::ComponentType::type sys_sage::Component::GetComponentType ( ) const

Returns component type of the component. The component type denotes which class the instance is (often stored as Component*, even though they are a member of one of the child classes).

Returns
componentType (of type sys_sage::ComponentType::type)
See also
componentType

◆ GetComponentTypeStr()

std::string sys_sage::Component::GetComponentTypeStr ( ) const

Returns component type as a human-readable string, as defined in ComponentType::names.

Returns
String representation of the component type.
See also
componentType

◆ GetDataPathByType()

sys_sage::DataPath * sys_sage::Component::GetDataPathByType ( DataPathType::type dp_type,
DataPathDirection::type direction = DataPathDirection::Any ) const

Retrieves a DataPath* from the list of this component's data paths with matching DataPathType and DataPathDirection. The first match is returned.

Parameters
dp_typeDataPath type to search for
directionOrientation (default: Any)
Returns
Pointer to the found DataPath, or nullptr if not found

◆ GetDepth()

int sys_sage::Component::GetDepth ( bool refresh)

Retrieves the depth (level) of a component in the topology.

Parameters
refreshIf true, recalculate the position (depth) of the component in the tree; if false, return the already stored value
Returns
Depth (level) of the component in the topology
See also
depth

◆ GetId()

int sys_sage::Component::GetId ( ) const

Returns id of the component.

Returns
id
See also
id

◆ GetName()

const std::string & sys_sage::Component::GetName ( ) const

Returns name of the component.

Returns
Name
See also
name

◆ GetNthAncestor()

sys_sage::Component * sys_sage::Component::GetNthAncestor ( int n)

Retrieves Nth ancestor, which resides N levels above. E.g. if n=1, the parent is retrieved; if n=2, the grandparent is retrieved and so on.

Parameters
n- how many levels above the tree should be looked.
Returns
The ancestor residing N levels above.

◆ GetNthDescendents() [1/2]

std::vector< sys_sage::Component * > sys_sage::Component::GetNthDescendents ( int depth)

Retrieves a std::vector of Component pointers, which reside 'depth' levels deeper. The tree is traversed in order as the children are stored in the std::vector. E.g. if depth=1, only children of the current are retrieved; if depth=2, only children of the children are retrieved..

Parameters
depth- how many levels down the tree should be looked
Returns
A std::vector<Component*> with the results.

◆ GetNthDescendents() [2/2]

void sys_sage::Component::GetNthDescendents ( std::vector< Component * > * outArray,
int depth )

Retrieves a std::vector of Component pointers, which reside 'depth' levels deeper. The tree is traversed in order as the children are stored in std::vector children. E.g. if depth=1, only children of the current are retrieved; if depth=2, only children of the children are retrieved..

Parameters
depth- how many levels down the tree should be looked
outArray- output parameter (vector with results) An input is pointer to a std::vector<Component *>, in which the elements will be pushed. It must be allocated before the call (but does not have to be empty). The method pushes back the found elements – i.e. the elements(pointers) can be found in this array after the method returns. (If no found, nothing will be pushed into the vector.)

◆ GetRelations()

const std::vector< sys_sage::Relation * > & sys_sage::Component::GetRelations ( RelationType::type relationType) const

Returns a (const) reference to the internal vector of relations for a given type.

Parameters
relationTypeType of relation (see RelationType for available types). Only use specific Relation Types, not RelationType::Any (you will get an empty vector).
Returns
const std::vector<Relation*>& (reference to internal structure)
Note
The vector is const so that the Relations of a Component cannot be manipulated this way. Use new Relation()/DeleteRelation() to modify the list of Relations, or access the Relations' API directly.
See also
FindAllRelationsBy(RelationType::type relationType = RelationType::Any, int thisComponentPosition = -1) as an alternative offering more flexibility at the price of increased overhead through generating a new output vector.

◆ GetSubcomponentById()

sys_sage::Component * sys_sage::Component::GetSubcomponentById ( int _id,
ComponentType::type _componentType )

Searches the subtree to find a component with a matching id and componentType, i.e. looks for a certain component with a matching ID. The search is a DFS. The search starts with the calling component.

Returns
Returns first occurence that matches these criteria.
Parameters
_id- the id to look for
_componentType- the component type where to look for the id
Returns
Component * matching the criteria. Returns the first match. NULL if no match found

◆ GetSubcomponentsByType() [1/2]

std::vector< Component * > sys_sage::Component::GetSubcomponentsByType ( ComponentType::type _componentType)

Retrieves a std::vector of Component pointers, which reside in the subtree and have a matching type. The tree is traversed DFS in order as the children are stored in the std::vector.

Parameters
componentType- componentType
Returns
A std::vector<Component*> with the results.

◆ GetSubcomponentsByType() [2/2]

void sys_sage::Component::GetSubcomponentsByType ( std::vector< Component * > * outArray,
int componentType )

Retrieves a std::vector of Component pointers, which reside in the subtree and have a matching type. The tree is traversed DFS in order as the children are stored in each std::vector children.

Parameters
componentType- componentType
outArray- output parameter (vector with results) An input is pointer to a std::vector<Component *>, in which the elements will be pushed. It must be allocated before the call (but does not have to be empty). The method pushes back the found elements – i.e. the elements(pointers) can be found in this array after the method returns. (If no found, the vector is not changed.)

◆ GetSubtreeDepth()

int sys_sage::Component::GetSubtreeDepth ( ) const

Retrieves maximal distance to a leaf (i.e. the depth of the subtree). 0=leaf, 1=children are leaves, 2=at most children's children are leaves .....

Returns
maximal distance to a leaf

◆ GetTopologySize()

int sys_sage::Component::GetTopologySize ( unsigned * out_component_size,
unsigned * out_dataPathSize ) const

Calculates approximate memory footprint of the subtree of this element (including the relevant Relations).

Parameters
out_component_sizeoutput parameter (contains the footprint of the component tree elements); an already allocated unsigned * is the input, the value is expected to be 0 (the result is accumulated here)
out_dataPathSizeoutput parameter (contains the footprint of the data-path graph elements); an already allocated unsigned * is the input, the value is expected to be 0 (the result is accumulated here)
Returns
The total size in bytes

◆ InsertBetweenParentAndChild()

int sys_sage::Component::InsertBetweenParentAndChild ( Component * parent,
Component * child,
bool alreadyParentsChild )

Inserts this component between a parent and one of its children. The parent component remains the parent, this Component becomes a new child of the parent, and the specified child becomes this component's child.

Parameters
parentThe parent component to which this component will be inserted as a child.
childThe child component that will become the child of this component and will remain a descendant of the original parent.
alreadyParentsChildA boolean flag indicating whether this component is already a child of the parent.
If true, the function assumes that this component is already present as a child of the parent and only needs to reassign the specified child.
If false, the function will add this component as a new child of the parent after reassigning the specified child.
Returns
0 on success; 1 if the child and parent are not child and parent in the component tree; 2 if the component tree is corrupt (parent is a parent of child but child is not in the parent's children list); 3 if the component tree is corrupt (parent is not a parent of child but child is in the parent's children list).

◆ InsertBetweenParentAndChildren()

int sys_sage::Component::InsertBetweenParentAndChildren ( Component * parent,
std::vector< Component * > children,
bool alreadyParentsChild )

Inserts this component between a parent and a (subset of) its children. The parent component remains parent, this Component becomes a new child, and the children become parent's grandchildren.

Parameters
parentThe parent component to which this component will be inserted as a child.
childrenA vector of child components that will become the children of this component and the grandchildren of the original parent.
alreadyParentsChildA boolean flag indicating whether this component is already a child of the parent.
If true, the function assumes that this component is already present as a child of the parent and only needs to reassign the specified children.
If false, the function will add this component as a new child of the parent after reassigning the specified children.
Returns
0 on success
1 on incompatible parent-children components (one or more children are not parent's children);
2 on corrupt component tree (parent is a parent of child but child is NOT in children list of parent);
3 on corrupt component tree (parent is NOT a parent of child but child is in children list of parent)

◆ InsertChild()

void sys_sage::Component::InsertChild ( Component * child)

Inserts a child component to this component (in the Component Tree). The child pointer will be inserted at the end of the children vector.

Parameters
childPointer to a Component (or any class instance that inherits from Component).
See also
GetChildren()
GetChild(int _id)

◆ PrintAllDataPathsInSubtree()

void sys_sage::Component::PrintAllDataPathsInSubtree ( )

Prints all DataPaths that go from or to components in the subtree.

Deprecated
Use PrintAllRelationsInSubtree instead. This function will be removed in the future.
See also
PrintAllRelationsInSubtree( RelationType::type RelationType = RelationType::Any)
Note
This function is deprecated and will be removed in the future. Use PrintAllRelationsInSubtree instead.

◆ PrintAllRelationsInSubtree()

void sys_sage::Component::PrintAllRelationsInSubtree ( RelationType::type RelationType = RelationType::Any)

Prints all Relations in the subtree.

Parameters
RelationTypeFilter by relation type (default: Any)

◆ RemoveChild()

int sys_sage::Component::RemoveChild ( Component * child)

Removes the passed component from the list of children, without completely deleting (and deallocating) the child itself.

Removes the passed component from the list of children, without completely deleting (and deallocating) the child itself

Parameters
child- child to remove
Returns
how many elements were deleted (normally, 0 or 1 should be possible)
Parameters
childChild to remove
Returns
Number of elements deleted (normally 0 or 1)

◆ SetName()

void sys_sage::Component::SetName ( std::string _name)

Sets name of the component.

Parameters
_nameName of the component
See also
name

◆ SetParent()

void sys_sage::Component::SetParent ( Component * parent)

Set a parent to the component. This is usually used when inserting a component in the tree (by calling InsertChild on the parent, and calling SetParent on the child).

Parameters
parentPointer to a Component (or any class instance that inherits from Component).
See also
InsertChild()

Member Data Documentation

◆ attrib

std::map<std::string, void*> sys_sage::Component::attrib

A map for storing arbitrary pieces of information or data.

  • The key denotes the name of the attribute.
  • The value points to the data, stored as a void*.

This data structure is designed to store a wide variety of data types by utilizing pointers to void. Due to its flexibility, it is essential to manage the types and memory allocation/deallocation carefully to avoid issues such as memory leaks or undefined behavior.

Usage:

  1. Adding a new key-value pair:
std::string key = "exampleKey";
int* value = new int(42); // Dynamically allocate memory for the value
attrib[key] = static_cast<void*>(value); // Store the value in the map
std::map< std::string, void * > attrib
Definition Component.hpp:567
  1. Retrieving data from an existing key:
std::string key = "exampleKey";
if (attrib.find(key) != attrib.end()) {
int* retrievedValue = static_cast<int*>(attrib[key]);
std::cout << "Value: " << *retrievedValue << std::endl;
} else {
std::cout << "Key not found." << std::endl;
}
  1. Checking for the existence of a key:
std::string key = "exampleKey";
if (attrib.find(key) != attrib.end()) {
std::cout << "Key exists." << std::endl;
} else {
std::cout << "Key does not exist." << std::endl;
}
  1. Removing a key-value pair and freeing memory:
std::string key = "exampleKey";
if (attrib.find(key) != attrib.end()) {
int* value = static_cast<int*>(attrib[key]);
delete value; // Free the dynamically allocated memory
attrib.erase(key); // Remove the key-value pair from the map
}
  1. Updating the value for an existing key:
std::string key = "exampleKey";
if (attrib.find(key) != attrib.end()) {
int* oldValue = static_cast<int*>(attrib[key]);
delete oldValue; // Free the old value
int* newValue = new int(100); // Allocate new value
attrib[key] = static_cast<void*>(newValue); // Update the map
}

Note:

  • Proper memory management is crucial when using void* pointers. Always ensure that dynamically allocated memory is freed when no longer needed.
  • Type safety is not enforced, so it is important to cast pointers to the correct type when retrieving values from the map.

◆ children

std::vector<Component*> sys_sage::Component::children
protected

Contains the list (std::vector) of pointers to children of the component in the component tree.

◆ componentType

const ComponentType::type sys_sage::Component::componentType
protected

Component type of the component. The component type denotes of which class the instance is (often the components are stored as Component*, even though they are a member of one of the child classes) Component type is constant, set by constructor, readonly. It can be of types as listed in ComponentType::type (which is user-extensible).

◆ count

int sys_sage::Component::count {-1}
protected

Can be used to represent multiple Components with the same properties. By default, it represents only 1 component, and is set to -1.

◆ depth

int sys_sage::Component::depth
protected

Depth (level) of the Component in the Component Tree

◆ id

int sys_sage::Component::id
protected

Numeric ID of the component. There is no requirement for uniqueness of the ID, however it is advised to have unique IDs at least in the realm of parent's children (siblings). Some tree search functions, which take the id as a search parameter search for first match, so the user is responsible to manage uniqueness in the realm of the search subtree (or should be aware of the consequences of not doing so). Component's ID is set by the constructor, and is retrieved via int GetId();

◆ name

std::string sys_sage::Component::name
protected

Name of the component (as a std::string).

◆ parent

Component* sys_sage::Component::parent { nullptr }
protected

Contains pointer to the parent component in the component tree. If this component is the root, parent will be nullptr.

◆ relations

std::array<std::vector<Relation*>*, RelationType::_num_relation_types>* sys_sage::Component::relations = nullptr
protected

Contains a list (std::array) of different Relation types. Initially nullptr, it is allocated on the first call to AddRelation() or new Relation(). The array size is RelationType::_num_relation_types, which is defined in RelationType. Each element of the array is a pointer to a std::vector<Relation*> that contains all Relations of that type. (also lazy-allocated)


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