Skip to main content

PipelineNode.h File

Pipeline-backed graph node wrapper. More...

Included Headers

#include "builder/Node.h" #include "builder/NodeGroup.h" #include "graph/GraphTypes.h" #include "graph/Node.h" #include <memory> #include <string> #include <utility> #include <vector>

Namespaces Index

namespacesimaai
namespaceneat
namespacegraph
namespacenodes

Classes Index

classPipelineNode

Runtime-graph node that wraps a builder-side NodeGroup (or single Node) as a pipeline-backend node. More...

Description

Pipeline-backed graph node wrapper.

File Listing

The file content with the documentation metadata removed is:

1
6#pragma once
7
8#include "builder/Node.h"
9#include "builder/NodeGroup.h"
10#include "graph/GraphTypes.h"
11#include "graph/Node.h"
12
13#include <memory>
14#include <string>
15#include <utility>
16#include <vector>
17
19
34public:
36 explicit PipelineNode(const simaai::neat::NodeGroup& group, std::string label = {})
37 : group_(group), label_(std::move(label)) {
38 init_();
39 }
40
42 explicit PipelineNode(simaai::neat::NodeGroup&& group, std::string label = {})
43 : group_(std::move(group)), label_(std::move(label)) {
44 init_();
45 }
46
48 explicit PipelineNode(std::shared_ptr<simaai::neat::Node> node, std::string label = {})
49 : group_(std::vector<std::shared_ptr<simaai::neat::Node>>{std::move(node)}),
50 label_(std::move(label)) {
51 init_();
52 }
53
55 Backend backend() const override {
57 }
58
60 std::string kind() const override {
61 return kind_;
62 }
63
65 std::string user_label() const override {
66 if (!label_.empty())
67 return label_;
68 if (group_.size() == 1 && group_.nodes().front()) {
69 return group_.nodes().front()->user_label();
70 }
71 return "";
72 }
73
75 std::vector<PortDesc> input_ports() const override {
76 if (!requires_input_)
77 return {};
78 return {PortDesc{.name = "in", .spec = OutputSpec{}}};
79 }
80
82 std::vector<PortDesc> output_ports() const override {
83 return {PortDesc{.name = "out", .spec = OutputSpec{}}};
84 }
85
87 const simaai::neat::NodeGroup& group() const {
88 return group_;
89 }
90
92 bool is_source_like() const {
93 return is_source_like_;
94 }
96 bool requires_input() const {
97 return requires_input_;
98 }
99
100private:
101 void init_() {
102 bool has_source = false;
103 bool has_push = false;
104 const auto& nodes = group_.nodes();
105 if (nodes.size() == 1 && nodes.front()) {
106 kind_ = nodes.front()->kind();
107 } else {
108 kind_ = "PipelineGroup";
109 }
110
111 for (const auto& n : nodes) {
112 if (!n)
113 continue;
114 const InputRole role = n->input_role();
115 if (role == InputRole::Source)
116 has_source = true;
117 if (role == InputRole::Push)
118 has_push = true;
119 }
120
121 is_source_like_ = has_source && !has_push;
122 requires_input_ = !is_source_like_;
123 }
124
125 simaai::neat::NodeGroup group_;
126 std::string label_;
127 std::string kind_;
128 bool is_source_like_ = false;
129 bool requires_input_ = true;
130};
131
132} // namespace simaai::neat::graph::nodes

Generated via doxygen2docusaurus 2.0.0 by Doxygen 1.9.8.