GraphDsl.h File
Lightweight DSL helpers for wiring graphs. More...
Included Headers
#include "graph/Graph.h"
#include <stdexcept>
#include <string>
#include <utility>
#include <vector>
Namespaces Index
| namespace | simaai |
| namespace | neat |
| namespace | graph |
| namespace | dsl |
Classes Index
| struct | PortRef |
|
Handle to a specific port on a node within a runtime Graph, used by the DSL. More... | |
| struct | NodeRef |
|
Handle to a node within a runtime Graph, used by the fluent DSL. More... | |
Description
Lightweight DSL helpers for wiring graphs.
File Listing
The file content with the documentation metadata removed is:
8#include "graph/Graph.h"
15namespace simaai::neat::graph::dsl {
49 return id;
61 PortRef operator[](const std::string& name) const;
63 PortRef operator[](const char* name) const {
70 return NodeRef{&g, id};
74inline NodeRef add(Graph& g, Graph::NodePtr node) {
88inline void ensure_graph(const Graph* g, const char* what) {
97 return g->node(id);
100inline PortRef NodeRef::out() const {
106 return out(ports.front().name);
109inline PortRef NodeRef::out(const std::string& name) const {
112 if (!has_port(ports, name)) {
115 return PortRef{g, id, g->intern_port(name), true};
118inline PortRef NodeRef::in() const {
124 return in(ports.front().name);
127inline PortRef NodeRef::in(const std::string& name) const {
130 if (!has_port(ports, name)) {
133 return PortRef{g, id, g->intern_port(name), false};
136inline PortRef NodeRef::operator[](const std::string& name) const {
140 const bool has_in = has_port(in_ports, name);
141 const bool has_out = has_port(out_ports, name);
144 return out(name);
146 return in(name);
155inline void connect_ports(const PortRef& from, const PortRef& to) {
156 ensure_graph(from.g, "connect_ports(from)");
157 ensure_graph(to.g, "connect_ports(to)");
161 if (!from.is_output) {
164 if (to.is_output) {
171inline NodeRef operator>>(const NodeRef& from, const NodeRef& to) {
172 connect_ports(from.out(), to.in());
177inline NodeRef operator>>(const PortRef& from, const NodeRef& to) {
178 connect_ports(from, to.in());
183inline NodeRef operator>>(const NodeRef& from, const PortRef& to) {
184 connect_ports(from.out(), to);
189inline NodeRef operator>>(const PortRef& from, const PortRef& to) {
190 connect_ports(from, to);
Generated via doxygen2docusaurus 2.0.0 by Doxygen 1.9.8.