Skip to main content

NodeRef Struct

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

Declaration

struct simaai::neat::graph::dsl::NodeRef { ... }

Included Headers

#include <GraphDsl.h>

Public Operators Index

operator NodeId () const

Implicit conversion to the underlying NodeId. More...

PortRefoperator[] (const std::string &name) const

Resolve a port by name; picks input or output unambiguously. More...

PortRefoperator[] (const char *name) const

operator[] overload accepting a C-string for convenience. More...

Public Member Functions Index

PortRefout () const

Get the node's sole output port; throws if the node has multiple outputs. More...

PortRefout (const std::string &name) const

Get the named output port. More...

PortRefin () const

Get the node's sole input port; throws if the node has multiple inputs. More...

PortRefin (const std::string &name) const

Get the named input port. More...

Public Member Attributes Index

Graph *g = nullptr

Non-owning pointer to the host graph. More...

NodeIdid = kInvalidNode

Underlying node id. More...

Description

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

Wraps a non-owning Graph* and a NodeId. Implicitly converts to NodeId and exposes in()/out()/operator[] to obtain PortRef handles for connection.

See Also

PortRef

Definition at line 43 of file GraphDsl.h.

Public Operators

operator NodeId()

simaai::neat::graph::dsl::NodeRef::operator NodeId ()
inline

Implicit conversion to the underlying NodeId.

Definition at line 48 of file GraphDsl.h.

48 operator NodeId() const {
49 return id;
50 }

operator[]()

PortRef simaai::neat::graph::dsl::NodeRef::operator[] (const std::string & name)
inline

Resolve a port by name; picks input or output unambiguously.

Definition at line 61 of file GraphDsl.h.

136inline PortRef NodeRef::operator[](const std::string& name) const {
137 const auto& node = get_node(g, id, "operator[]");
138 const auto in_ports = node->input_ports();
139 const auto out_ports = node->output_ports();
140 const bool has_in = has_port(in_ports, name);
141 const bool has_out = has_port(out_ports, name);
142
143 if (has_out && !has_in)
144 return out(name);
145 if (has_in && !has_out)
146 return in(name);
147
148 if (!has_in && !has_out) {
149 throw std::runtime_error("GraphDsl: unknown port: " + name);
150 }
151 throw std::runtime_error("GraphDsl: ambiguous port name (use .in or .out): " + name);
152}

operator[]()

PortRef simaai::neat::graph::dsl::NodeRef::operator[] (const char * name)
inline

operator[] overload accepting a C-string for convenience.

Definition at line 63 of file GraphDsl.h.

63 PortRef operator[](const char* name) const {
64 return (*this)[std::string(name)];
65 }

Public Member Functions

in()

PortRef simaai::neat::graph::dsl::NodeRef::in ()
inline

Get the node's sole input port; throws if the node has multiple inputs.

Definition at line 57 of file GraphDsl.h.

118inline PortRef NodeRef::in() const {
119 const auto& node = get_node(g, id, "in()");
120 const auto ports = node->input_ports();
121 if (ports.size() != 1) {
122 throw std::runtime_error("GraphDsl: in() requires exactly one input port");
123 }
124 return in(ports.front().name);
125}

in()

PortRef simaai::neat::graph::dsl::NodeRef::in (const std::string & name)
inline

Get the named input port.

Definition at line 59 of file GraphDsl.h.

127inline PortRef NodeRef::in(const std::string& name) const {
128 const auto& node = get_node(g, id, "in(name)");
129 const auto ports = node->input_ports();
130 if (!has_port(ports, name)) {
131 throw std::runtime_error("GraphDsl: unknown input port: " + name);
132 }
133 return PortRef{g, id, g->intern_port(name), false};
134}

out()

PortRef simaai::neat::graph::dsl::NodeRef::out ()
inline

Get the node's sole output port; throws if the node has multiple outputs.

Definition at line 53 of file GraphDsl.h.

100inline PortRef NodeRef::out() const {
101 const auto& node = get_node(g, id, "out()");
102 const auto ports = node->output_ports();
103 if (ports.size() != 1) {
104 throw std::runtime_error("GraphDsl: out() requires exactly one output port");
105 }
106 return out(ports.front().name);
107}

out()

PortRef simaai::neat::graph::dsl::NodeRef::out (const std::string & name)
inline

Get the named output port.

Definition at line 55 of file GraphDsl.h.

109inline PortRef NodeRef::out(const std::string& name) const {
110 const auto& node = get_node(g, id, "out(name)");
111 const auto ports = node->output_ports();
112 if (!has_port(ports, name)) {
113 throw std::runtime_error("GraphDsl: unknown output port: " + name);
114 }
115 return PortRef{g, id, g->intern_port(name), true};
116}

Public Member Attributes

g

Graph* simaai::neat::graph::dsl::NodeRef::g = nullptr

Non-owning pointer to the host graph.

Definition at line 44 of file GraphDsl.h.

44 Graph* g = nullptr;

id

NodeId simaai::neat::graph::dsl::NodeRef::id = kInvalidNode

Underlying node id.

Definition at line 45 of file GraphDsl.h.

45 NodeId id = kInvalidNode;

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


Generated via doxygen2docusaurus 2.0.0 by Doxygen 1.9.8.