88 template <
typename T,
typename... Args>
90 const std::string &port_label,
96 this->
ports.push_back(
98 std::forward<Args>(args)...));
212 const std::vector<std::shared_ptr<Port>> &
get_ports()
const
227 for (
const auto &port : this->
ports)
228 if (port->get_label() == port_label)
232 auto inputPort = std::dynamic_pointer_cast<Input<T>>(port);
233 if (inputPort)
return inputPort->get_value_ref();
237 auto outputPort = std::dynamic_pointer_cast<Output<T>>(port);
238 if (outputPort)
return outputPort->get_value_ref();
258 auto port = std::dynamic_pointer_cast<Input<T>>(this->
ports[port_index]);
259 return port ? port->get_value_ref() :
nullptr;
263 auto port = std::dynamic_pointer_cast<Output<T>>(this->
ports[port_index]);
264 return port ? port->get_value_ref() :
nullptr;
278 if (port_index < 0 || port_index >=
static_cast<int>(this->
ports.size()))
281 return this->
ports[port_index]->get_value_ref_void();
289 bool has_port(
const std::string &port_label)
const;
298 template <
typename T>
bool has_port(
const std::string &port_label)
const
300 if (!this->
has_port(port_label))
return false;
351 template <
typename T>
356 throw std::runtime_error(
"set_value: port not found or type mismatch: " +
381 std::vector<std::shared_ptr<Port>>
ports;
The Graph class provides methods for manipulating nodes and connections in a directed graph structure...
Definition graph.hpp:36
Abstract Node class that represents a basic building block in a graph-based system.
Definition node.hpp:34
Node(std::string label)
Construct a new Node object with a specific label.
Definition node.hpp:52
Graph * get_p_graph() const
Get the reference to the belonging graph.
Definition node.hpp:183
std::vector< std::shared_ptr< Port > > ports
A vector of shared pointers to the node's ports.
Definition node.hpp:381
std::string get_graph_id() const
Get the id of the graph.
T * get_value_ref(int port_index) const
Get a reference to the value stored in a port by its index.
Definition node.hpp:252
std::string get_port_label(int port_index) const
Get the label of a port by its index.
Node()=default
Default constructor for Node.
std::string id
The ID of the node.
Definition node.hpp:376
int get_nports() const
Get the total number of ports on the node.
Graph * p_graph
Reference to the graph the node belong to, if any.
Definition node.hpp:386
void set_value(const std::string &port_label, T new_value)
Set the value of a port by its label.
Definition node.hpp:352
std::string get_data_type(int port_index) const
Get the data type of a specific port (input or output).
void update()
Update the node, which involves processing its input and output ports.
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::shared_ptr< BaseData > get_output_data(int port_index) const
Get the output data from a specific port index.
int get_port_index(const std::string &port_label) const
Get the index of a port by its label.
bool has_port(const std::string &port_label) const
Checks whether a port with the given label exists.
T * get_value_ref(const std::string &port_label) const
Get a reference to the value stored in a port by its label.
Definition node.hpp:224
std::shared_ptr< BaseData > get_base_data(int port_index)
Retrieves a shared pointer to the data associated with the port after downcasting.
std::string get_id() const
Get the ID of the node.
Definition node.hpp:153
PortType get_port_type(const std::string &port_label) const
Get the type of a port (input or output) by its label.
void set_p_graph(Graph *new_p_graph)
Set the reference to the belonging graph.
Definition node.hpp:342
std::string get_label() const
Get the label of the node.
Definition node.hpp:146
std::string label
The label of the node.
Definition node.hpp:371
void set_id(std::string new_id)
Set a new identifier for the node.
Definition node.hpp:327
bool is_dirty
Flag indicating whether the node is marked as dirty (requiring an update).
Definition node.hpp:40
virtual void compute()=0
Pure virtual function that forces derived classes to implement the compute method,...
virtual ~Node()=default
Virtual destructor for Node.
void set_input_data(std::shared_ptr< BaseData > data, int port_index)
Set input data on a specific port by its index.
bool has_port(const std::string &port_label) const
Checks whether a port exists and matches the requested type.
Definition node.hpp:298
Node(std::string label, std::string id)
Construct a new Node object with a specific label and identifier.
Definition node.hpp:65
void * get_value_ref_void(int port_index) const
Get a void* reference to the value stored in a port by its index.
Definition node.hpp:276
const std::vector< std::shared_ptr< Port > > & get_ports() const
Get the ports.
Definition node.hpp:212
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 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.
Definition node.hpp:89
int get_nports(PortType port_type) const
Get the number of ports of a specific type (input or output).
Template class for output ports, specialized by data type.
Definition port.hpp:211
Defines the BaseData and Data classes for handling typed data in the gnode namespace.
PortType
Enumeration for port types, indicating whether a port is an input or an output.
Definition port.hpp:33
@ IN
Represents an input port.
Definition port.hpp:34
Defines the Port, Input, and Output classes, along with the PortType enumeration for handling ports i...