|
GNode library (C++)
|
The Graph class provides methods for manipulating nodes and connections in a directed graph structure. More...
#include <graph.hpp>
Public Member Functions | |
| Graph ()=default | |
| Construct a new Graph object. | |
| Graph (const std::string &id) | |
| Construct a new Graph object. | |
| virtual | ~Graph ()=default |
| Destroy the Graph object. | |
| virtual std::string | add_node (const std::shared_ptr< Node > &p_node, const std::string &id="") |
| Add a new node to the graph. | |
| template<typename U , typename... Args> | |
| std::string | add_node (Args... args) |
| Add a new node of a specific type to the graph. | |
| void | clear () |
| Clear the graph, remove all the nodes and the links. | |
| std::vector< Point > | compute_graph_layout_sugiyama () |
| Compute the layout of the graph using the Sugiyama algorithm. | |
| std::string | get_id () const |
| Return the graph ID. | |
| bool | new_link (const std::string &from, int port_from, const std::string &to, int port_to) |
| Connect two nodes in the graph using port indices. | |
| bool | new_link (const std::string &from, const std::string &port_label_from, const std::string &to, const std::string &port_label_to) |
| Connect two nodes in the graph using port labels. | |
| bool | remove_link (const std::string &from, int port_from, const std::string &to, int port_to) |
| Disconnect two nodes in the graph using port indices. | |
| bool | remove_link (const std::string &from, const std::string &port_label_from, const std::string &to, const std::string &port_label_to) |
| Disconnect two nodes in the graph using port labels. | |
| void | export_to_graphviz (const std::string &fname="export.dot", const std::string &graph_label="graph") |
| Export the graph to a Graphviz DOT file. | |
| void | export_to_mermaid (const std::string &fname="export.mmd", const std::string &graph_label="graph") |
| Export the graph to a Mermaid file. | |
| std::map< std::string, std::vector< std::string > > | get_connectivity_downstream () |
| Get the downstream connectivity of the graph. | |
| std::map< std::string, std::vector< std::string > > | get_connectivity_upstream () |
| Get the upstream connectivity of the graph. | |
| uint | get_id_count () const |
| Get the current count of unique identifiers. | |
| uint * | get_id_count_ref () |
| const std::vector< Link > & | get_links () const |
| Get the link storage. | |
| template<typename T = Node> | |
| T * | get_node_ref_by_id (const std::string &node_id) const |
| Get a pointer to a node by its ID. | |
| const std::map< std::string, std::shared_ptr< Node > > & | get_nodes () |
| Get a reference to the nodes map. | |
| std::vector< std::string > | get_nodes_to_update (const std::string &node_id) |
| Get node list for update priority. | |
| bool | is_node_id_available (const std::string &node_id) |
| Check if a node ID is available in the graph. | |
| virtual void | post_update () |
| Method called after the graph update process is completed. | |
| void | print () |
| Print the current graph structure. | |
| virtual void | remove_node (const std::string &id) |
| Remove a node from the graph by its ID. | |
| void | set_id (const std::string &new_id) |
| Set the graph ID. | |
| void | set_id_count (uint new_id_count) |
| Set the current count of unique identifiers. | |
| void | set_update_callback (std::function< void(const std::string &, const std::vector< std::string > &, bool)> new_callback) |
| std::vector< std::string > | topological_sort (const std::vector< std::string > &dirty_node_ids) |
| Kahn's algorithm for node sorting for update priority. | |
| virtual void | update () |
| Mark all nodes as dirty and update the entire graph. | |
| virtual void | update (const std::string &node_id) |
| Update a specific node by its ID. | |
Protected Attributes | |
| std::map< std::string, std::shared_ptr< Node > > | nodes |
| A map of node IDs to shared pointers of Node objects. | |
| std::vector< Link > | links |
| A list of links between nodes in the graph. | |
Private Attributes | |
| uint | id_count = 0 |
| Keep track of unique identifiers. | |
| std::string | id = "" |
| Graph id. | |
| std::function< void(const std::string ¤t_id, const std::vector< std::string > &sorted_ids, bool before_update)> | update_callback = nullptr |
The Graph class provides methods for manipulating nodes and connections in a directed graph structure.
|
default |
Construct a new Graph object.
|
inline |
|
virtualdefault |
Destroy the Graph object.
|
inline |
|
virtual |
Add a new node to the graph.
| p_node | Shared pointer to the node to be added. |
| id | Optional ID for the node. If empty, an ID will be generated. |
| void gnode::Graph::clear | ( | ) |
Clear the graph, remove all the nodes and the links.
| std::vector< Point > gnode::Graph::compute_graph_layout_sugiyama | ( | ) |
Compute the layout of the graph using the Sugiyama algorithm.
| void gnode::Graph::export_to_graphviz | ( | const std::string & | fname = "export.dot", |
| const std::string & | graph_label = "graph" |
||
| ) |
Export the graph to a Graphviz DOT file.
| fname | Filename of the DOT file. |
| graph_label | Label for the graph. |
| void gnode::Graph::export_to_mermaid | ( | const std::string & | fname = "export.mmd", |
| const std::string & | graph_label = "graph" |
||
| ) |
Export the graph to a Mermaid file.
| fname | Filename of the Mermaid file. |
| graph_label | Label for the graph. |
| std::map< std::string, std::vector< std::string > > gnode::Graph::get_connectivity_downstream | ( | ) |
Get the downstream connectivity of the graph.
| std::map< std::string, std::vector< std::string > > gnode::Graph::get_connectivity_upstream | ( | ) |
Get the upstream connectivity of the graph.
|
inline |
Return the graph ID.
|
inline |
Get the current count of unique identifiers.
|
inline |
|
inline |
Get the link storage.
|
inline |
|
inline |
Get a reference to the nodes map.
| std::vector< std::string > gnode::Graph::get_nodes_to_update | ( | const std::string & | node_id | ) |
Get node list for update priority.
| bool gnode::Graph::is_node_id_available | ( | const std::string & | node_id | ) |
Check if a node ID is available in the graph.
| id | Node ID to check. |
| bool gnode::Graph::new_link | ( | const std::string & | from, |
| const std::string & | port_label_from, | ||
| const std::string & | to, | ||
| const std::string & | port_label_to | ||
| ) |
Connect two nodes in the graph using port labels.
| from | ID of the source node. |
| port_label_from | Label of the source node's output port. |
| to | ID of the destination node. |
| port_label_to | Label of the destination node's input port. |
| bool gnode::Graph::new_link | ( | const std::string & | from, |
| int | port_from, | ||
| const std::string & | to, | ||
| int | port_to | ||
| ) |
Connect two nodes in the graph using port indices.
| from | ID of the source node. |
| port_from | Index of the source node's output port. |
| to | ID of the destination node. |
| port_to | Index of the destination node's input port. |
|
inlinevirtual |
Method called after the graph update process is completed.
This method can be overridden in derived classes for custom post-update behavior.
| void gnode::Graph::print | ( | ) |
Print the current graph structure.
| bool gnode::Graph::remove_link | ( | const std::string & | from, |
| const std::string & | port_label_from, | ||
| const std::string & | to, | ||
| const std::string & | port_label_to | ||
| ) |
Disconnect two nodes in the graph using port labels.
| from | The label of the source node. |
| port_label_from | The label of the source node's output port. |
| to | The label of the destination node. |
| port_label_to | The label of the destination node's input port. |
| bool gnode::Graph::remove_link | ( | const std::string & | from, |
| int | port_from, | ||
| const std::string & | to, | ||
| int | port_to | ||
| ) |
Disconnect two nodes in the graph using port indices.
| from | ID of the source node. |
| port_from | Index of the source node's output port. |
| to | ID of the destination node. |
| port_to | Index of the destination node's input port. |
|
virtual |
Remove a node from the graph by its ID.
| id | ID of the node to remove. |
|
inline |
Set the graph ID.
| new_id | ID. |
|
inline |
Set the current count of unique identifiers.
| new_id | An available unique identifier. |
|
inline |
| std::vector< std::string > gnode::Graph::topological_sort | ( | const std::vector< std::string > & | dirty_node_ids | ) |
Kahn's algorithm for node sorting for update priority.
|
virtual |
Mark all nodes as dirty and update the entire graph.
This method forces a complete update of the graph, which may be inefficient for large graphs.
|
virtual |
Update a specific node by its ID.
| id | ID of the node to update. |
|
private |
Graph id.
|
private |
Keep track of unique identifiers.
|
protected |
A list of links between nodes in the graph.
|
protected |
A map of node IDs to shared pointers of Node objects.
|
private |