|
GNode library (C++)
|
Abstract Node class that represents a basic building block in a graph-based system. More...
#include <node.hpp>

Public Member Functions | |
| Node ()=default | |
| Default constructor for Node. | |
| Node (std::string label) | |
| Construct a new Node object with a specific label. | |
| Node (std::string label, std::string id) | |
| Construct a new Node object with a specific label and identifier. | |
| virtual | ~Node ()=default |
| Virtual destructor for Node. | |
| template<typename T , typename... Args> | |
| void | add_port (PortType port_type, const std::string &port_label, Args &&...args) |
| Add a port to the node, specifying whether it is an input or output. | |
| virtual void | compute ()=0 |
| Pure virtual function that forces derived classes to implement the compute method, which updates the node's state. | |
| std::shared_ptr< BaseData > | get_base_data (int port_index) |
| Retrieves a shared pointer to the data associated with the port after downcasting. | |
| std::shared_ptr< BaseData > | get_base_data (const std::string &port_label) |
| Retrieves a shared pointer to the data associated with the port after downcasting. | |
| std::string | get_data_type (int port_index) const |
| Get the data type of a specific port (input or output). | |
| std::string | get_graph_id () const |
| Get the id of the graph. | |
| std::string | get_label () const |
| Get the label of the node. | |
| std::string | get_id () const |
| Get the ID of the node. | |
| int | get_nports () const |
| Get the total number of ports on the node. | |
| int | get_nports (PortType port_type) const |
| Get the number of ports of a specific type (input or output). | |
| std::shared_ptr< BaseData > | get_output_data (int port_index) const |
| Get the output data from a specific port index. | |
| Graph * | get_p_graph () const |
| Get the reference to the belonging graph. | |
| int | get_port_index (const std::string &port_label) const |
| Get the index of a port by its label. | |
| std::string | get_port_label (int port_index) const |
| Get the label of a port by its index. | |
| PortType | get_port_type (const std::string &port_label) const |
| Get the type of a port (input or output) by its label. | |
| const std::vector< std::shared_ptr< Port > > & | get_ports () |
| Get the ports. | |
| template<typename T > | |
| T * | get_value_ref (const std::string &port_label) const |
| Get a reference to the value stored in a port by its label. | |
| template<typename T > | |
| T * | get_value_ref (int port_index) const |
| Get a reference to the value stored in a port by its index. | |
| void * | get_value_ref_void (int port_index) const |
Get a void* reference to the value stored in a port by its index. | |
| bool | is_port_connected (int port_index) const |
| Check if a port is connected by its index. | |
| bool | is_port_connected (const std::string &port_label) const |
| Check if a port is connected by its label. | |
| void | set_id (std::string new_id) |
| Set a new identifier for the node. | |
| void | set_input_data (std::shared_ptr< BaseData > data, int port_index) |
| Set input data on a specific port by its index. | |
| void | set_p_graph (Graph *new_p_graph) |
| Set the reference to the belonging graph. | |
| template<typename T > | |
| void | set_value (const std::string &port_label, T new_value) |
| Set the value of a port by its label. | |
| void | update () |
| Update the node, which involves processing its input and output ports. | |
Public Attributes | |
| bool | is_dirty = false |
| Flag indicating whether the node is marked as dirty (requiring an update). | |
Private Attributes | |
| std::string | label |
| The label of the node. | |
| std::string | id |
| The ID of the node. | |
| std::vector< std::shared_ptr< Port > > | ports |
| A vector of shared pointers to the node's ports. | |
| Graph * | p_graph = nullptr |
| Reference to the graph the node belong to, if any. | |
Abstract Node class that represents a basic building block in a graph-based system.
Nodes contain ports, which can be connected to other nodes for data flow.
|
default |
Default constructor for Node.
|
inline |
Construct a new Node object with a specific label.
| label | The label for the node. |
|
inline |
Construct a new Node object with a specific label and identifier.
| label | The label for the node. |
| id | The unique identifier for the node. |
This constructor initializes a Node object with both a label and a unique identifier. The label is used to describe or name the node, while the id uniquely distinguishes the node from others in the system (storage in the node itself is generally optional but may be handy).
|
inline |
Add a port to the node, specifying whether it is an input or output.
| T | The data type for the port. |
| Args | Types of the arguments passed to the port constructor. |
| port_type | The type of port (input or output). |
| port_label | The label for the port. |
| args | Additional arguments passed to the output port constructor if the port type is output. |
This function adds a port of type T to the node. If the port type is PortType::IN, it creates an Input port with the given port_label. If the port type is PortType::OUT, it creates an Output port with the given port_label and forwards additional arguments to the Output port constructor.
Pure virtual function that forces derived classes to implement the compute method, which updates the node's state.
Retrieves a shared pointer to the data associated with the port after downcasting.
| port_label | The label of the port. |
Retrieves a shared pointer to the data associated with the port after downcasting.
| port_index | The index of the port. |
| std::string gnode::Node::get_data_type | ( | int | port_index | ) | const |
Get the data type of a specific port (input or output).
This function is pure virtual and must be implemented by derived classes.
| port_index | The index of the port. |
| std::string gnode::Node::get_graph_id | ( | ) | const |
Get the id of the graph.
|
inline |
Get the ID of the node.
|
inline |
Get the label of the node.
| int gnode::Node::get_nports | ( | ) | const |
Get the total number of ports on the node.
Get the number of ports of a specific type (input or output).
| port_type | The type of port to count (input or output). |
Get the output data from a specific port index.
| port_index | The index of the output port. |
|
inline |
Get the reference to the belonging graph.
Get the index of a port by its label.
| port_label | The label of the port. |
| std::string gnode::Node::get_port_label | ( | int | port_index | ) | const |
Get the label of a port by its index.
| port_index | The index of the port. |
Get the type of a port (input or output) by its label.
| port_label | The label of the port. |
|
inline |
Get a reference to the value stored in a port by its label.
| T | The type of the value. |
| port_label | The label of the port. |
| std::runtime_error | If the port with the given label is not found, or if casting the port to the appropriate type fails. |
|
inline |
Get a reference to the value stored in a port by its index.
| T | The type of the value. |
| port_index | The index of the port. |
| std::out_of_range | If the port index is invalid. |
Get a void* reference to the value stored in a port by its index.
| port_index | The index of the port. |
void* pointer to the value. | std::out_of_range | If the port index is invalid. |
Check if a port is connected by its label.
| port_label | Label of the port. |
Check if a port is connected by its index.
| port_index | Index of the port. |
|
inline |
Set a new identifier for the node.
| new_id | The new unique identifier to be assigned to the node. |
This method updates the node's identifier with the provided new_id. The identifier is used to uniquely distinguish the node from others in the system.
Set input data on a specific port by its index.
| data | The data to set on the port. |
| port_index | The index of the port. |
Set the reference to the belonging graph.
| new_p_graph | Graph reference. |
Set the value of a port by its label.
| T | The type of the value. |
| port_label | The label of the port. |
| new_value | The new value to set on the port. |
| void gnode::Node::update | ( | ) |
Update the node, which involves processing its input and output ports.
|
private |
The ID of the node.
Flag indicating whether the node is marked as dirty (requiring an update).
|
private |
The label of the node.
|
private |
A vector of shared pointers to the node's ports.