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 |
| struct | NodeRef |
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 {
29 return id;
36 PortRef operator[](const std::string& name) const;
37 PortRef operator[](const char* name) const {
43 return NodeRef{&g, id};
46inline NodeRef add(Graph& g, Graph::NodePtr node) {
58inline void ensure_graph(const Graph* g, const char* what) {
66 return g->node(id);
69inline PortRef NodeRef::out() const {
75 return out(ports.front().name);
78inline PortRef NodeRef::out(const std::string& name) const {
81 if (!has_port(ports, name)) {
84 return PortRef{g, id, g->intern_port(name), true};
87inline PortRef NodeRef::in() const {
93 return in(ports.front().name);
96inline PortRef NodeRef::in(const std::string& name) const {
99 if (!has_port(ports, name)) {
102 return PortRef{g, id, g->intern_port(name), false};
105inline PortRef NodeRef::operator[](const std::string& name) const {
109 const bool has_in = has_port(in_ports, name);
110 const bool has_out = has_port(out_ports, name);
113 return out(name);
115 return in(name);
123inline void connect_ports(const PortRef& from, const PortRef& to) {
124 ensure_graph(from.g, "connect_ports(from)");
125 ensure_graph(to.g, "connect_ports(to)");
129 if (!from.is_output) {
132 if (to.is_output) {
138inline NodeRef operator>>(const NodeRef& from, const NodeRef& to) {
139 connect_ports(from.out(), to.in());
143inline NodeRef operator>>(const PortRef& from, const NodeRef& to) {
144 connect_ports(from, to.in());
148inline NodeRef operator>>(const NodeRef& from, const PortRef& to) {
149 connect_ports(from.out(), to);
153inline NodeRef operator>>(const PortRef& from, const PortRef& to) {
154 connect_ports(from, to);
Generated via doxygen2docusaurus 2.0.0 by Doxygen 1.9.1.