sys-sage
|
Abstract base class representing a multi-way connection among Components. More...
#include <Relation.hpp>
Public Member Functions | |
Relation (const std::vector< Component * > &components, int _id=0, bool _ordered=true) | |
Construct a new Relation object. | |
void | SetId (int _id) |
Sets the id of the relationship. | |
int | GetId () const |
Gets the id of the relationship. | |
RelationType::type | GetType () const |
Get the type of the relation. | |
std::string | GetTypeStr () const |
Return a human-readable name of the relation type. | |
bool | IsOrdered () const |
Check if this relation treats component order as meaningful. | |
bool | ContainsComponent (Component *c) const |
Check whether the given component is part of this relation. | |
Component * | GetComponent (int index) const |
Get the component at a specific position. | |
const std::vector< Component * > & | GetComponents () const |
Access the list of components. | |
virtual void | Print () const |
Virtual function to print the details of the relationship. | |
void | AddComponent (Component *c) |
Add a new component to the relation. | |
int | UpdateComponent (int index, Component *_new_component) |
Replace a component at the given index. | |
int | UpdateComponent (Component *_old_component, Component *_new_component) |
Replace the first occurrence of a given component. | |
virtual void | Delete () |
Virtual function to delete the relation. | |
~Relation ()=default | |
Destructor for the Relation class. | |
Public Attributes | |
std::map< std::string, void * > | attrib |
Protected Attributes | |
bool | ordered |
Whether order in the component list is meaningful. | |
int | id |
The id of the relationship. | |
RelationType::type | type |
The type of the relationship (see RelationType::type). | |
std::vector< Component * > | components |
A vector of components associated with the relationship. | |
Abstract base class representing a multi-way connection among Components.
A Relation models a relationship among one or more Components, such as a data path, logical gate, or any other connectivity construct. Derived classes define the specific type and semantics.
Key Features:
components
vector holds participating components. The ordered
flag determines whether their order is semantically meaningful.id
and name
identify the relation.type
indicates the specific kind of relation (e.g. data path, gate).attrib
.Clients can use this interface generically or extend it with domain-specific semantics.
sys_sage::Relation::Relation | ( | const std::vector< Component * > & | components, |
int | _id = 0, | ||
bool | _ordered = true ) |
Construct a new Relation object.
components | List of pointers to participating Components. |
_id | Optional unique ID for the relation. |
_ordered | Whether the order of components carries semantic meaning. |
The type of the relation is set to sys_sage::RelationType::Relation.
|
default |
Destructor for the Relation class.
This is a virtual destructor to ensure proper cleanup of derived classes.
void sys_sage::Relation::AddComponent | ( | Component * | c | ) |
Add a new component to the relation.
c | Component to append to the internal list. |
bool sys_sage::Relation::ContainsComponent | ( | Component * | c | ) | const |
Check whether the given component is part of this relation.
c | Pointer to the Component to check. |
c
is found in the components vector.
|
virtual |
Virtual function to delete the relation.
Should be overridden in subclasses if custom destruction logic is needed.
Reimplemented in sys_sage::CouplingMap, and sys_sage::DataPath.
sys_sage::Component * sys_sage::Relation::GetComponent | ( | int | index | ) | const |
Get the component at a specific position.
index | Index in the component list. |
const std::vector< sys_sage::Component * > & sys_sage::Relation::GetComponents | ( | ) | const |
Access the list of components.
This avoids copying and prevents direct modification.
int sys_sage::Relation::GetId | ( | ) | const |
Gets the id of the relationship.
sys_sage::RelationType::type sys_sage::Relation::GetType | ( | ) | const |
Get the type of the relation.
std::string sys_sage::Relation::GetTypeStr | ( | ) | const |
Return a human-readable name of the relation type.
bool sys_sage::Relation::IsOrdered | ( | ) | const |
Check if this relation treats component order as meaningful.
|
virtual |
Virtual function to print the details of the relationship.
Derived classes may implement this function to provide specific printing behavior.
Reimplemented in sys_sage::DataPath, and sys_sage::QuantumGate.
void sys_sage::Relation::SetId | ( | int | _id | ) |
Sets the id of the relationship.
_id | The id of the relationship to set. |
Replace the first occurrence of a given component.
Uses std::find to locate _old_component
and replaces it with _new_component
.
_old_component | The component to replace. |
_new_component | The replacement component. |
int sys_sage::Relation::UpdateComponent | ( | int | index, |
Component * | _new_component ) |
Replace a component at the given index.
index | The index of the component to replace. |
_new_component | New component to insert. |
std::map<std::string, void*> sys_sage::Relation::attrib |
A map for storing arbitrary pieces of information or data.
key
denotes the name of the attribute.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:
Note:
void*
pointers. Always ensure that dynamically allocated memory is freed when no longer needed.
|
protected |
A vector of components associated with the relationship.
This member variable holds pointers to components that are part of the relationship.
|
protected |
The id of the relationship.
This member variable stores the unique identifier for the relationship.
|
protected |
The type of the relationship (see RelationType::type).
This member variable stores the type or category of the relationship.