Skip to main content

Fragments.h File

Reusable public Graph fragments for named endpoint routing. More...

Included Headers

#include "nodes/common/Output.h" #include "nodes/io/Input.h" #include "pipeline/Graph.h" #include <stdexcept> #include <string> #include <string_view> #include <unordered_set> #include <utility> #include <vector>

Namespaces Index

namespacesimaai
namespaceneat
namespacegraphs
namespacedetail

Description

Reusable public Graph fragments for named endpoint routing.

These helpers intentionally return ordinary simaai::neat::Graph objects. They do not expose low-level runtime graph nodes, port handles, or node IDs. Users can inspect, compose, save, and build the returned fragments exactly like any other Graph.

File Listing

The file content with the documentation metadata removed is:

1
9#pragma once
10
12#include "nodes/io/Input.h"
13#include "pipeline/Graph.h"
14
15#include <stdexcept>
16#include <string>
17#include <string_view>
18#include <unordered_set>
19#include <utility>
20#include <vector>
21
23namespace detail {
24
25inline void require_unique_endpoint_name(std::unordered_set<std::string>* used,
26 std::string_view name, const char* helper) {
27 if (!used) {
28 return;
29 }
30 if (name.empty()) {
31 throw std::runtime_error(std::string(helper) + ": endpoint name must not be empty");
32 }
33 if (!used->insert(std::string(name)).second) {
34 throw std::runtime_error(std::string(helper) + ": duplicate endpoint name '" +
35 std::string(name) + "'");
36 }
37}
38
39} // namespace detail
40
62inline Graph Branch(std::string input, std::vector<std::string> outputs) {
63 if (outputs.empty()) {
64 throw std::runtime_error("graphs::Branch: at least one output endpoint is required");
65 }
66
67 std::unordered_set<std::string> used;
68 detail::require_unique_endpoint_name(&used, input, "graphs::Branch");
69 for (const auto& output : outputs) {
70 detail::require_unique_endpoint_name(&used, output, "graphs::Branch");
71 }
72
73 Graph g(input);
74 g.add(nodes::Input(input));
75 for (const auto& output : outputs) {
76 g.add(nodes::Output(output));
77 }
78 for (const auto& output : outputs) {
79 g.connect(input, output);
80 }
81 return g;
82}
83
102inline Graph Combine(std::vector<std::string> inputs, std::string output,
104 if (inputs.empty()) {
105 throw std::runtime_error("graphs::Combine: at least one input endpoint is required");
106 }
107
108 std::unordered_set<std::string> used;
109 for (const auto& input : inputs) {
110 detail::require_unique_endpoint_name(&used, input, "graphs::Combine");
111 }
112 detail::require_unique_endpoint_name(&used, output, "graphs::Combine");
113
114 Graph g(output);
115 for (const auto& input : inputs) {
116 g.add(nodes::Input(input));
117 }
118 OutputOptions opt;
119 opt.combine_policy = policy;
120 g.add(nodes::Output(output, opt));
121 for (const auto& input : inputs) {
122 g.connect(input, output);
123 }
124 return g;
125}
126
127} // namespace simaai::neat::graphs

Generated via doxygen2docusaurus 2.0.0 by Doxygen 1.9.8.