Shamrock 2025.10.0
Astrophysical Code
Loading...
Searching...
No Matches
shamrock::solvergraph::SolverGraph Class Reference

A graph container for managing solver nodes and edges with type-safe access. More...

#include <shamsolvergraph/include/shamsolvergraph/SolverGraph.hpp>

Inheritance diagram for shamrock::solvergraph::SolverGraph:

Public Member Functions

std::shared_ptr< INoderegister_node_ptr_base (const std::string &name, std::shared_ptr< INode > node)
 Register a node with the graph using a shared pointer.
std::shared_ptr< IEdgeregister_edge_ptr_base (const std::string &name, std::shared_ptr< IEdge > edge)
 Register an edge with the graph using a shared pointer.
std::shared_ptr< INode > & get_node_ptr_base (const std::string &name)
 Retrieve a node by name as a shared pointer to the base interface.
const std::shared_ptr< INode > & get_node_ptr_base (const std::string &name) const
 const variant
std::shared_ptr< IEdge > & get_edge_ptr_base (const std::string &name)
 Retrieve an edge by name as a shared pointer to the base interface.
const std::shared_ptr< IEdge > & get_edge_ptr_base (const std::string &name) const
 const variant
bool has_node (const std::string &name) const
 Check whether a node with the given name exists.
bool has_edge (const std::string &name) const
 Check whether an edge with the given name exists.
INodeget_node_ref_base (const std::string &name)
 Get a reference to a node by name through the base interface.
const INodeget_node_ref_base (const std::string &name) const
 const variant
IEdgeget_edge_ref_base (const std::string &name)
 Get a reference to an edge by name through the base interface.
const IEdgeget_edge_ref_base (const std::string &name) const
 const variant
template<class T>
std::shared_ptr< T > register_node (const std::string &name, T &&node)
 Register a node with automatic type deduction and shared pointer creation.
template<class T>
std::shared_ptr< T > register_edge (const std::string &name, T &&edge)
 Register an edge with automatic type deduction and shared pointer creation.
template<class T>
std::shared_ptr< T > get_node_ptr (const std::string &name)
 Get a typed shared pointer to a node by name.
template<class T>
std::shared_ptr< T > get_node_ptr (const std::string &name) const
 const variant
template<class T>
std::shared_ptr< T > get_edge_ptr (const std::string &name)
 Get a typed shared pointer to an edge by name.
template<class T>
std::shared_ptr< T > get_edge_ptr (const std::string &name) const
 const variant
template<class T>
T & get_node_ref (const std::string &name)
 Get a typed reference to a node by name.
template<class T>
const T & get_node_ref (const std::string &name) const
 const variant
template<class T>
T & get_edge_ref (const std::string &name)
 Get a typed reference to an edge by name.
template<class T>
const T & get_edge_ref (const std::string &name) const
 const variant
std::vector< std::string > get_edge_names () const
 Returns edge registration keys in lexicographic order (deterministic).
std::vector< std::string > get_node_names () const
 Returns node registration keys in lexicographic order (deterministic).

Static Public Member Functions

static SolverGraph with_constraint (SolverGraphConstraint graph_constraint)
 Create a solver graph with registration constraints.

Protected Member Functions

 SolverGraph (SolverGraphConstraint graph_constraint)

Detailed Description

A graph container for managing solver nodes and edges with type-safe access.

The SolverGraph class provides a centralized registry for solver graph components, allowing nodes and edges to be registered by name and retrieved with type safety. It supports both polymorphic access through base interfaces and templated access for specific derived types.

// Create a solver graph
SolverGraph graph;
// Register a node with automatic type deduction
MyNodeType node_instance;
graph.register_node("my_node", std::move(node_instance));
// Register an edge
MyEdgeType edge_instance;
graph.register_edge("my_edge", std::move(edge_instance));
// Retrieve typed references
auto& node_ref = graph.get_node_ref<MyNodeType>("my_node");
auto& edge_ref = graph.get_edge_ref<MyEdgeType>("my_edge");
// Or get shared pointers for polymorphic access
auto node_ptr = graph.get_node_ptr<MyNodeType>("my_node");
auto edge_ptr = graph.get_edge_ptr<MyEdgeType>("my_edge");
// Or create a graph with registration constraints under a single name
.name = "sph_solver_graph",
.node_check = [](const std::shared_ptr<INode> &n) { return true; },
.edge_check = [](const std::shared_ptr<IEdge> &e) { return true; },
});
T & get_edge_ref(const std::string &name)
Get a typed reference to an edge by name.
std::shared_ptr< T > get_edge_ptr(const std::string &name)
Get a typed shared pointer to an edge by name.
std::shared_ptr< T > register_edge(const std::string &name, T &&edge)
Register an edge with automatic type deduction and shared pointer creation.
std::shared_ptr< T > get_node_ptr(const std::string &name)
Get a typed shared pointer to a node by name.
std::shared_ptr< T > register_node(const std::string &name, T &&node)
Register a node with automatic type deduction and shared pointer creation.
T & get_node_ref(const std::string &name)
Get a typed reference to a node by name.
static SolverGraph with_constraint(SolverGraphConstraint graph_constraint)
Create a solver graph with registration constraints.

Definition at line 110 of file SolverGraph.hpp.

Constructor & Destructor Documentation

◆ SolverGraph()

shamrock::solvergraph::SolverGraph::SolverGraph ( SolverGraphConstraint graph_constraint)
inlineexplicitprotected

Definition at line 120 of file SolverGraph.hpp.

Member Function Documentation

◆ get_edge_names()

std::vector< std::string > shamrock::solvergraph::SolverGraph::get_edge_names ( ) const
inline

Returns edge registration keys in lexicographic order (deterministic).

Definition at line 456 of file SolverGraph.hpp.

◆ get_edge_ptr() [1/2]

template<class T>
std::shared_ptr< T > shamrock::solvergraph::SolverGraph::get_edge_ptr ( const std::string & name)
inline

Get a typed shared pointer to an edge by name.

This method performs a dynamic cast to the requested type and returns a shared pointer. Throw an exception if the cast fails.

Template Parameters
TType of the edge to retrieve
Parameters
nameUnique identifier for the edge
Returns
Shared pointer to the typed edge, or throw an exception if cast fails
Exceptions
std::invalid_argumentif no edge with the given name exists or cast fails

Definition at line 391 of file SolverGraph.hpp.

Here is the call graph for this function:

◆ get_edge_ptr() [2/2]

template<class T>
std::shared_ptr< T > shamrock::solvergraph::SolverGraph::get_edge_ptr ( const std::string & name) const
inline

const variant

Definition at line 402 of file SolverGraph.hpp.

Here is the call graph for this function:

◆ get_edge_ptr_base() [1/2]

std::shared_ptr< IEdge > & shamrock::solvergraph::SolverGraph::get_edge_ptr_base ( const std::string & name)
inline

Retrieve an edge by name as a shared pointer to the base interface.

Parameters
nameUnique identifier for the edge
Returns
Reference to shared pointer to the edge
Exceptions
std::invalid_argumentif no edge with the given name exists

Definition at line 228 of file SolverGraph.hpp.

Here is the call graph for this function:

◆ get_edge_ptr_base() [2/2]

const std::shared_ptr< IEdge > & shamrock::solvergraph::SolverGraph::get_edge_ptr_base ( const std::string & name) const
inline

const variant

Definition at line 238 of file SolverGraph.hpp.

Here is the call graph for this function:

◆ get_edge_ref() [1/2]

template<class T>
T & shamrock::solvergraph::SolverGraph::get_edge_ref ( const std::string & name)
inline

Get a typed reference to an edge by name.

This method performs a dynamic cast and returns a reference to the typed edge. Throws an exception if the cast fails.

Template Parameters
TType of the edge to retrieve
Parameters
nameUnique identifier for the edge
Returns
Reference to the typed edge
Exceptions
std::invalid_argumentif no edge with the given name exists or cast fails

Definition at line 445 of file SolverGraph.hpp.

Here is the call graph for this function:

◆ get_edge_ref() [2/2]

template<class T>
const T & shamrock::solvergraph::SolverGraph::get_edge_ref ( const std::string & name) const
inline

const variant

Definition at line 451 of file SolverGraph.hpp.

Here is the call graph for this function:

◆ get_edge_ref_base() [1/2]

IEdge & shamrock::solvergraph::SolverGraph::get_edge_ref_base ( const std::string & name)
inline

Get a reference to an edge by name through the base interface.

Parameters
nameUnique identifier for the edge
Returns
Reference to the edge through the base interface
Exceptions
std::invalid_argumentif no edge with the given name exists

Definition at line 294 of file SolverGraph.hpp.

Here is the call graph for this function:

◆ get_edge_ref_base() [2/2]

const IEdge & shamrock::solvergraph::SolverGraph::get_edge_ref_base ( const std::string & name) const
inline

const variant

Definition at line 299 of file SolverGraph.hpp.

Here is the call graph for this function:

◆ get_node_names()

std::vector< std::string > shamrock::solvergraph::SolverGraph::get_node_names ( ) const
inline

Returns node registration keys in lexicographic order (deterministic).

Definition at line 468 of file SolverGraph.hpp.

◆ get_node_ptr() [1/2]

template<class T>
std::shared_ptr< T > shamrock::solvergraph::SolverGraph::get_node_ptr ( const std::string & name)
inline

Get a typed shared pointer to a node by name.

This method performs a dynamic cast to the requested type and returns a shared pointer. Throw an exception if the cast fails.

Template Parameters
TType of the node to retrieve
Parameters
nameUnique identifier for the node
Returns
Shared pointer to the typed node, or throw an exception if cast fails
Exceptions
std::invalid_argumentif no node with the given name exists or cast fails

Definition at line 359 of file SolverGraph.hpp.

Here is the call graph for this function:

◆ get_node_ptr() [2/2]

template<class T>
std::shared_ptr< T > shamrock::solvergraph::SolverGraph::get_node_ptr ( const std::string & name) const
inline

const variant

Definition at line 370 of file SolverGraph.hpp.

Here is the call graph for this function:

◆ get_node_ptr_base() [1/2]

std::shared_ptr< INode > & shamrock::solvergraph::SolverGraph::get_node_ptr_base ( const std::string & name)
inline

Retrieve a node by name as a shared pointer to the base interface.

Parameters
nameUnique identifier for the node
Returns
Reference to shared pointer to the node
Exceptions
std::invalid_argumentif no node with the given name exists

Definition at line 202 of file SolverGraph.hpp.

Here is the call graph for this function:

◆ get_node_ptr_base() [2/2]

const std::shared_ptr< INode > & shamrock::solvergraph::SolverGraph::get_node_ptr_base ( const std::string & name) const
inline

const variant

Definition at line 212 of file SolverGraph.hpp.

Here is the call graph for this function:

◆ get_node_ref() [1/2]

template<class T>
T & shamrock::solvergraph::SolverGraph::get_node_ref ( const std::string & name)
inline

Get a typed reference to a node by name.

This method performs a dynamic cast and returns a reference to the typed node. Throws an exception if the cast fails.

Template Parameters
TType of the node to retrieve
Parameters
nameUnique identifier for the node
Returns
Reference to the typed node
Exceptions
std::invalid_argumentif no node with the given name exists or cast fails

Definition at line 423 of file SolverGraph.hpp.

Here is the call graph for this function:

◆ get_node_ref() [2/2]

template<class T>
const T & shamrock::solvergraph::SolverGraph::get_node_ref ( const std::string & name) const
inline

const variant

Definition at line 429 of file SolverGraph.hpp.

Here is the call graph for this function:

◆ get_node_ref_base() [1/2]

INode & shamrock::solvergraph::SolverGraph::get_node_ref_base ( const std::string & name)
inline

Get a reference to a node by name through the base interface.

Parameters
nameUnique identifier for the node
Returns
Reference to the node through the base interface
Exceptions
std::invalid_argumentif no node with the given name exists

Definition at line 278 of file SolverGraph.hpp.

Here is the call graph for this function:

◆ get_node_ref_base() [2/2]

const INode & shamrock::solvergraph::SolverGraph::get_node_ref_base ( const std::string & name) const
inline

const variant

Definition at line 283 of file SolverGraph.hpp.

Here is the call graph for this function:

◆ has_edge()

bool shamrock::solvergraph::SolverGraph::has_edge ( const std::string & name) const
inline

Check whether an edge with the given name exists.

Parameters
nameUnique identifier for the edge
Returns
true if an edge with that name is registered

Definition at line 263 of file SolverGraph.hpp.

◆ has_node()

bool shamrock::solvergraph::SolverGraph::has_node ( const std::string & name) const
inline

Check whether a node with the given name exists.

Parameters
nameUnique identifier for the node
Returns
true if a node with that name is registered

Definition at line 253 of file SolverGraph.hpp.

◆ register_edge()

template<class T>
std::shared_ptr< T > shamrock::solvergraph::SolverGraph::register_edge ( const std::string & name,
T && edge )
inline

Register an edge with automatic type deduction and shared pointer creation.

This method creates a shared pointer from the provided edge instance and registers it with the graph. The edge type is automatically deduced from the template parameter.

Template Parameters
TType of the edge (must derive from IEdge)
Parameters
nameUnique identifier for the edge
edgeEdge instance to register (will be moved)
Exceptions
std::invalid_argumentif constraint validation fails or an edge with the same name already exists

Definition at line 341 of file SolverGraph.hpp.

Here is the call graph for this function:

◆ register_edge_ptr_base()

std::shared_ptr< IEdge > shamrock::solvergraph::SolverGraph::register_edge_ptr_base ( const std::string & name,
std::shared_ptr< IEdge > edge )
inline

Register an edge with the graph using a shared pointer.

Parameters
nameUnique identifier for the edge
edgeShared pointer to the edge instance
Exceptions
std::invalid_argumentif constraint validation fails or an edge with the same name already exists

Definition at line 175 of file SolverGraph.hpp.

Here is the call graph for this function:

◆ register_node()

template<class T>
std::shared_ptr< T > shamrock::solvergraph::SolverGraph::register_node ( const std::string & name,
T && node )
inline

Register a node with automatic type deduction and shared pointer creation.

This method creates a shared pointer from the provided node instance and registers it with the graph. The node type is automatically deduced from the template parameter.

Template Parameters
TType of the node (must derive from INode)
Parameters
nameUnique identifier for the node
nodeNode instance to register (will be moved)
Exceptions
std::invalid_argumentif constraint validation fails or a node with the same name already exists

Definition at line 321 of file SolverGraph.hpp.

Here is the call graph for this function:

◆ register_node_ptr_base()

std::shared_ptr< INode > shamrock::solvergraph::SolverGraph::register_node_ptr_base ( const std::string & name,
std::shared_ptr< INode > node )
inline

Register a node with the graph using a shared pointer.

Parameters
nameUnique identifier for the node
nodeShared pointer to the node instance
Exceptions
std::invalid_argumentif constraint validation fails or a node with the same name already exists

Definition at line 147 of file SolverGraph.hpp.

Here is the call graph for this function:

◆ with_constraint()

SolverGraph shamrock::solvergraph::SolverGraph::with_constraint ( SolverGraphConstraint graph_constraint)
inlinestatic

Create a solver graph with registration constraints.

Parameters
graph_constraintNamed constraint with optional node and edge checks

Definition at line 135 of file SolverGraph.hpp.


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