Skip to main content

dsl Namespace

Definition

namespace simaai::neat::graph::dsl { ... }

Classes Index

structNodeRef

Handle to a node within a runtime Graph, used by the fluent DSL. More...

structPortRef

Handle to a specific port on a node within a runtime Graph, used by the DSL. More...

Operators Index

NodeRefoperator>> (const NodeRef &from, const NodeRef &to)

DSL connector: a >> b connects a's sole output to b's sole input and returns b. More...

NodeRefoperator>> (const PortRef &from, const NodeRef &to)

DSL connector: connect a specific output port to to's sole input. More...

NodeRefoperator>> (const NodeRef &from, const PortRef &to)

DSL connector: connect from's sole output to a specific input port. More...

NodeRefoperator>> (const PortRef &from, const PortRef &to)

DSL connector: connect a specific output port to a specific input port. More...

Functions Index

NodeRefref (Graph &g, NodeId id)

Build a NodeRef for an existing node id in the given graph. More...

NodeRefadd (Graph &g, Graph::NodePtr node)

Add a node to the graph and return a NodeRef to the newly inserted node. More...

boolhas_port (const std::vector< PortDesc > &ports, const std::string &name)

Returns true iff ports contains a PortDesc whose name matches name. More...

voidensure_graph (const Graph *g, const char *what)

Throws if g is null; used to validate DSL preconditions. More...

const std::shared_ptr< Node > &get_node (const Graph *g, NodeId id, const char *what)

Resolve a node handle from a graph + id, throwing on null graph. More...

voidconnect_ports (const PortRef &from, const PortRef &to)

Connect an output PortRef to an input PortRef. Throws on type/graph mismatches. More...

Operators

operator>>()

NodeRef simaai::neat::graph::dsl::operator>> (const NodeRef & from, const NodeRef & to)
inline

DSL connector: a >> b connects a's sole output to b's sole input and returns b.

Definition at line 171 of file GraphDsl.h.

171inline NodeRef operator>>(const NodeRef& from, const NodeRef& to) {
172 connect_ports(from.out(), to.in());
173 return to;
174}

operator>>()

NodeRef simaai::neat::graph::dsl::operator>> (const PortRef & from, const NodeRef & to)
inline

DSL connector: connect a specific output port to to's sole input.

Definition at line 177 of file GraphDsl.h.

177inline NodeRef operator>>(const PortRef& from, const NodeRef& to) {
178 connect_ports(from, to.in());
179 return to;
180}

operator>>()

NodeRef simaai::neat::graph::dsl::operator>> (const NodeRef & from, const PortRef & to)
inline

DSL connector: connect from's sole output to a specific input port.

Definition at line 183 of file GraphDsl.h.

183inline NodeRef operator>>(const NodeRef& from, const PortRef& to) {
184 connect_ports(from.out(), to);
185 return NodeRef{to.g, to.node};
186}

operator>>()

NodeRef simaai::neat::graph::dsl::operator>> (const PortRef & from, const PortRef & to)
inline

DSL connector: connect a specific output port to a specific input port.

Definition at line 189 of file GraphDsl.h.

189inline NodeRef operator>>(const PortRef& from, const PortRef& to) {
190 connect_ports(from, to);
191 return NodeRef{to.g, to.node};
192}

Functions

add()

NodeRef simaai::neat::graph::dsl::add (Graph & g, Graph::NodePtr node)
inline

Add a node to the graph and return a NodeRef to the newly inserted node.

Definition at line 74 of file GraphDsl.h.

74inline NodeRef add(Graph& g, Graph::NodePtr node) {
75 return NodeRef{&g, g.add(std::move(node))};
76}

connect_ports()

void simaai::neat::graph::dsl::connect_ports (const PortRef & from, const PortRef & to)
inline

Connect an output PortRef to an input PortRef. Throws on type/graph mismatches.

Definition at line 155 of file GraphDsl.h.

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)");
158 if (from.g != to.g) {
159 throw std::runtime_error("GraphDsl: cannot connect ports from different graphs");
160 }
161 if (!from.is_output) {
162 throw std::runtime_error("GraphDsl: left side is not an output port");
163 }
164 if (to.is_output) {
165 throw std::runtime_error("GraphDsl: right side is not an input port");
166 }
167 from.g->connect(from.node, to.node, from.g->port_name(from.port), to.g->port_name(to.port));
168}

ensure_graph()

void simaai::neat::graph::dsl::ensure_graph (const Graph * g, const char * what)
inline

Throws if g is null; used to validate DSL preconditions.

Definition at line 88 of file GraphDsl.h.

88inline void ensure_graph(const Graph* g, const char* what) {
89 if (!g)
90 throw std::runtime_error(std::string("GraphDsl: null graph in ") + what);
91}

get_node()

const std::shared_ptr< Node > & simaai::neat::graph::dsl::get_node (const Graph * g, NodeId id, const char * what)
inline

Resolve a node handle from a graph + id, throwing on null graph.

Definition at line 94 of file GraphDsl.h.

94inline const std::shared_ptr<Node>& get_node(const Graph* g, NodeId id, const char* what) {
95 if (!g)
96 throw std::runtime_error(std::string("GraphDsl: null graph in ") + what);
97 return g->node(id);
98}

has_port()

bool simaai::neat::graph::dsl::has_port (const std::vector< PortDesc > & ports, const std::string & name)
inline

Returns true iff ports contains a PortDesc whose name matches name.

Definition at line 79 of file GraphDsl.h.

79inline bool has_port(const std::vector<PortDesc>& ports, const std::string& name) {
80 for (const auto& p : ports) {
81 if (p.name == name)
82 return true;
83 }
84 return false;
85}

ref()

NodeRef simaai::neat::graph::dsl::ref (Graph & g, NodeId id)
inline

Build a NodeRef for an existing node id in the given graph.

Definition at line 69 of file GraphDsl.h.

69inline NodeRef ref(Graph& g, NodeId id) {
70 return NodeRef{&g, id};
71}

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


Generated via doxygen2docusaurus 2.0.0 by Doxygen 1.9.8.