Pretty-printer for runtime Graph instances; emits text, dot, or mermaid. More...
Declaration
class simaai::neat::graph::GraphPrinter { ... }
Public Static Functions Index
| static std::string | to_text (const Graph &g) |
|
Render g to a text outline using default options. More...
|
|
| static std::string | to_text (const Graph &g, const Options &opt) |
|
Render g to a text outline using the provided options. More...
|
|
| static std::string | to_dot (const Graph &g) |
|
Render g to a Graphviz dot string using default options. More...
|
|
| static std::string | to_dot (const Graph &g, const Options &opt) |
|
Render g to a Graphviz dot string using the provided options. More...
|
|
| static std::string | to_mermaid (const Graph &g) |
|
Render g to a Mermaid flowchart string using default options. More...
|
|
| static std::string | to_mermaid (const Graph &g, const Options &opt) |
|
Render g to a Mermaid flowchart string using the provided options. More...
|
|
Private Static Functions Index
| static const char * | backend_name_ (Backend b) |
|
|
|
| static std::string | node_label_ (const std::shared_ptr< Node > &n, std::size_t id, const Options &opt) |
|
|
|
| static std::string | join_ports_ (const std::vector< PortDesc > &ports, std::size_t max_ports) |
|
|
|
| static std::string | truncate_ (const std::string &s, std::size_t max_len) |
|
|
|
| static std::string | dot_escape_ (const std::string &s) |
|
|
|
| static std::string | mermaid_escape_ (const std::string &s) |
|
|
|
| static std::string | dot_id_ (const std::string &s) |
|
|
|
| static std::string | dot_node_id_ (std::size_t id) |
|
|
|
| static std::string | mermaid_node_id_ (std::size_t id, const Options &opt) |
|
|
|
Description
Pretty-printer for runtime Graph instances; emits text, dot, or mermaid.
Used for diagnostics and design-time visualisation: takes a runtime Graph and renders it as a human-readable text outline, a Graphviz dot string, or a Mermaid flowchart.
- See Also
Graph
Definition at line 28 of file GraphPrinter.h.
Public Static Functions
to_dot()
| std::string simaai::neat::graph::GraphPrinter::to_dot (const Graph & g) |
|
inline
static
|
Render g to a Graphviz dot string using default options.
Definition at line 89 of file GraphPrinter.h.
to_dot()
| std::string simaai::neat::graph::GraphPrinter::to_dot (const Graph & g, const Options & opt) |
|
inline
static
|
Render g to a Graphviz dot string using the provided options.
Definition at line 93 of file GraphPrinter.h.
94 std::ostringstream oss;
97 oss << " rankdir=LR;\n";
98 oss << " node [shape=box];\n";
99
101 const auto& n = g.node(id);
102 if (!n)
103 continue;
104
105 std::string label = node_label_(n, id, opt);
107 label += "\\n" + dot_escape_("in: " + join_ports_(n->input_ports(), opt.max_ports));
108 label += "\\n" + dot_escape_("out: " + join_ports_(n->output_ports(), opt.max_ports));
109 }
110
111 oss << " " << dot_node_id_(id) << " [label=\"" << dot_escape_(label) << "\"];\n";
112 }
113
114 for (const auto& e : g.edges()) {
116 oss << " " << dot_node_id_(e.from) << " -> " << dot_node_id_(e.to) << " [label=\""
117 << dot_escape_(label) << "\"];\n";
118 }
119
120 oss << "}\n";
121 return oss.str();
122 }
to_mermaid()
| std::string simaai::neat::graph::GraphPrinter::to_mermaid (const Graph & g) |
|
inline
static
|
Render g to a Mermaid flowchart string using default options.
Definition at line 125 of file GraphPrinter.h.
to_mermaid()
| std::string simaai::neat::graph::GraphPrinter::to_mermaid (const Graph & g, const Options & opt) |
|
inline
static
|
Render g to a Mermaid flowchart string using the provided options.
Definition at line 129 of file GraphPrinter.h.
130 std::ostringstream oss;
131 oss << "flowchart " << (opt.mermaid_lr ? "LR" : "TD") << "\n";
132
134 const auto& n = g.node(id);
135 if (!n)
136 continue;
137
138 std::string label = node_label_(n, id, opt);
140 label += "\n" + ("in: " + join_ports_(n->input_ports(), opt.max_ports));
141 label += "\n" + ("out: " + join_ports_(n->output_ports(), opt.max_ports));
142 }
143
144 oss << " " << mermaid_node_id_(id, opt) << "[\"" << mermaid_escape_(label) << "\"]\n";
145 }
146
147 for (const auto& e : g.edges()) {
149 oss << " " << mermaid_node_id_(e.from, opt) << " -->|" << mermaid_escape_(label) << "| "
150 << mermaid_node_id_(e.to, opt) << "\n";
151 }
152
153 return oss.str();
154 }
to_text()
| std::string simaai::neat::graph::GraphPrinter::to_text (const Graph & g) |
|
inline
static
|
Render g to a text outline using default options.
Definition at line 53 of file GraphPrinter.h.
to_text()
| std::string simaai::neat::graph::GraphPrinter::to_text (const Graph & g, const Options & opt) |
|
inline
static
|
Render g to a text outline using the provided options.
Definition at line 57 of file GraphPrinter.h.
58 std::ostringstream oss;
60 const auto& n = g.node(id);
61 if (!n)
62 continue;
63
65 oss << id << ") ";
67 oss << n->kind();
69 oss << " [" << backend_name_(n->backend()) << "]";
70 }
72 const std::string label = n->user_label();
73 if (!label.empty())
75 }
76
78 oss << "\n in: " << join_ports_(n->input_ports(), opt.max_ports);
79 oss << "\n out: " << join_ports_(n->output_ports(), opt.max_ports);
80 }
81
83 oss << "\n";
84 }
85 return oss.str();
86 }
Private Static Functions
backend_name_()
| const char * simaai::neat::graph::GraphPrinter::backend_name_ (Backend b) |
|
inline
static
|
Definition at line 157 of file GraphPrinter.h.
157 static const char* backend_name_(Backend b) {
158 switch (b) {
160 return "pipeline";
162 return "stage";
163 }
164 return "unknown";
165 }
dot_escape_()
| std::string simaai::neat::graph::GraphPrinter::dot_escape_ (const std::string & s) |
|
inline
static
|
Definition at line 212 of file GraphPrinter.h.
212 static std::string dot_escape_(const std::string& s) {
213 std::string out;
214 out.reserve(s.size());
215 for (char c : s) {
216 if (c == '"')
217 out += "\\\"";
218 else if (c == '\\')
219 out += "\\\\";
220 else
221 out += c;
222 }
223 return out;
224 }
dot_id_()
| std::string simaai::neat::graph::GraphPrinter::dot_id_ (const std::string & s) |
|
inline
static
|
Definition at line 238 of file GraphPrinter.h.
238 static std::string dot_id_(const std::string& s) {
239 if (s.empty())
240 return "graph";
241 return s;
242 }
dot_node_id_()
| std::string simaai::neat::graph::GraphPrinter::dot_node_id_ (std::size_t id) |
|
inline
static
|
Definition at line 244 of file GraphPrinter.h.
244 static std::string dot_node_id_(std::size_t id) {
245 return "n" + std::to_string(id);
246 }
join_ports_()
| std::string simaai::neat::graph::GraphPrinter::join_ports_ (const std::vector< PortDesc > & ports, std::size_t max_ports) |
|
inline
static
|
Definition at line 184 of file GraphPrinter.h.
184 static std::string join_ports_(const std::vector<PortDesc>& ports, std::size_t max_ports) {
185 if (ports.empty())
186 return "<none>";
187 std::ostringstream oss;
188 std::size_t count = 0;
189 for (const auto& p : ports) {
190 if (count++ > 0)
191 oss << ", ";
192 oss << p.name;
193 if (p.optional)
194 oss << "?";
195 if (count >= max_ports) {
196 if (ports.size() > max_ports)
197 oss << ", ...";
198 break;
199 }
200 }
201 return oss.str();
202 }
mermaid_escape_()
| std::string simaai::neat::graph::GraphPrinter::mermaid_escape_ (const std::string & s) |
|
inline
static
|
Definition at line 226 of file GraphPrinter.h.
226 static std::string mermaid_escape_(const std::string& s) {
227 std::string out;
228 out.reserve(s.size());
229 for (char c : s) {
230 if (c == '"')
231 out += "\\\"";
232 else
233 out += c;
234 }
235 return out;
236 }
mermaid_node_id_()
| std::string simaai::neat::graph::GraphPrinter::mermaid_node_id_ (std::size_t id, const Options & opt) |
|
inline
static
|
Definition at line 248 of file GraphPrinter.h.
248 static std::string mermaid_node_id_(std::size_t id, const Options& opt) {
249 return opt.mermaid_id_prefix + std::to_string(id);
250 }
node_label_()
| std::string simaai::neat::graph::GraphPrinter::node_label_ (const std::shared_ptr< Node > & n, std::size_t id, const Options & opt) |
|
inline
static
|
Definition at line 167 of file GraphPrinter.h.
167 static std::string node_label_(const std::shared_ptr<Node>& n, std::size_t id,
168 const Options& opt) {
169 std::ostringstream oss;
170 if (opt.show_index)
171 oss << id << ") ";
172 if (opt.show_kind)
173 oss << n->kind();
174 if (opt.show_backend)
175 oss << " [" << backend_name_(n->backend()) << "]";
176 if (opt.show_user_label) {
177 const std::string label = n->user_label();
178 if (!label.empty())
179 oss << " '" << truncate_(label, opt.max_label_chars) << "'";
180 }
181 return oss.str();
182 }
truncate_()
| std::string simaai::neat::graph::GraphPrinter::truncate_ (const std::string & s, std::size_t max_len) |
|
inline
static
|
Definition at line 204 of file GraphPrinter.h.
204 static std::string truncate_(const std::string& s, std::size_t max_len) {
205 if (s.size() <= max_len)
206 return s;
207 if (max_len < 3)
208 return s.substr(0, max_len);
209 return s.substr(0, max_len - 3) + "...";
210 }
The documentation for this class was generated from the following file:
Generated via doxygen2docusaurus 2.0.0 by Doxygen 1.9.8.