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

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
21public:
22 explicit PipelineNode(const simaai::neat::NodeGroup& group, std::string label = {})
23 : group_(group), label_(std::move(label)) {
24 init_();
25 }
26
27 explicit PipelineNode(simaai::neat::NodeGroup&& group, std::string label = {})
28 : group_(std::move(group)), label_(std::move(label)) {
29 init_();
30 }
31
32 explicit PipelineNode(std::shared_ptr<simaai::neat::Node> node, std::string label = {})
33 : group_(std::vector<std::shared_ptr<simaai::neat::Node>>{std::move(node)}),
34 label_(std::move(label)) {
35 init_();
36 }
37
38 Backend backend() const override {
40 }
41
42 std::string kind() const override {
43 return kind_;
44 }
45
46 std::string user_label() const override {
47 if (!label_.empty())
48 return label_;
49 if (group_.size() == 1 && group_.nodes().front()) {
50 return group_.nodes().front()->user_label();
51 }
52 return "";
53 }
54
55 std::vector<PortDesc> input_ports() const override {
56 if (!requires_input_)
57 return {};
58 return {PortDesc{.name = "in", .spec = OutputSpec{}}};
59 }
60
61 std::vector<PortDesc> output_ports() const override {
62 return {PortDesc{.name = "out", .spec = OutputSpec{}}};
63 }
64
65 const simaai::neat::NodeGroup& group() const {
66 return group_;
67 }
68
69 bool is_source_like() const {
70 return is_source_like_;
71 }
72 bool requires_input() const {
73 return requires_input_;
74 }
75
76private:
77 void init_() {
78 bool has_source = false;
79 bool has_push = false;
80 const auto& nodes = group_.nodes();
81 if (nodes.size() == 1 && nodes.front()) {
82 kind_ = nodes.front()->kind();
83 } else {
84 kind_ = "PipelineGroup";
85 }
86
87 for (const auto& n : nodes) {
88 if (!n)
89 continue;
90 const InputRole role = n->input_role();
91 if (role == InputRole::Source)
92 has_source = true;
93 if (role == InputRole::Push)
94 has_push = true;
95 }
96
97 is_source_like_ = has_source && !has_push;
98 requires_input_ = !is_source_like_;
99 }
100
101 simaai::neat::NodeGroup group_;
102 std::string label_;
103 std::string kind_;
104 bool is_source_like_ = false;
105 bool requires_input_ = true;
106};
107
108} // namespace simaai::neat::graph::nodes

Generated via doxygen2docusaurus 2.0.0 by Doxygen 1.9.1.