GraphPrinter.h File
STL-only pretty printers for hybrid graphs. More...
Included Headers
#include "graph/Graph.h"
#include <cstddef>
#include <memory>
#include <sstream>
#include <string>
#include <utility>
#include <vector>
Namespaces Index
| namespace | simaai |
| namespace | neat |
| namespace | graph |
Classes Index
| class | GraphPrinter |
|
Pretty-printer for runtime Graph instances; emits text, dot, or mermaid. More... | |
| struct | Options |
|
Render options controlling which fields and labels are emitted. More... | |
Description
STL-only pretty printers for hybrid graphs.
File Listing
The file content with the documentation metadata removed is:
8#include "graph/Graph.h"
17namespace simaai::neat::graph {
28class GraphPrinter final {
36 bool show_index = true;
38 bool show_user_label = true;
39 bool show_backend = true;
40 bool show_ports = true;
42 std::size_t max_label_chars = 200;
45 bool dot_rankdir_lr = true;
46 std::string dot_graph_name = "sima_hybrid_graph";
48 bool mermaid_lr = true;
49 std::string mermaid_id_prefix = "n";
59 for (NodeId id = 0; id < g.node_count(); ++id) {
60 const auto& n = g.node(id);
64 if (opt.show_index)
66 if (opt.show_kind)
68 if (opt.show_backend) {
71 if (opt.show_user_label) {
74 oss << " '" << truncate_(label, opt.max_label_chars) << "'";
77 if (opt.show_ports) {
78 oss << "\n in: " << join_ports_(n->input_ports(), opt.max_ports);
79 oss << "\n out: " << join_ports_(n->output_ports(), opt.max_ports);
82 if (id + 1 < g.node_count())
95 oss << "digraph " << dot_id_(opt.dot_graph_name) << " {\n";
96 if (opt.dot_rankdir_lr)
100 for (NodeId id = 0; id < g.node_count(); ++id) {
101 const auto& n = g.node(id);
106 if (opt.show_ports) {
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));
114 for (const auto& e : g.edges()) {
125 static std::string to_mermaid(const Graph& g) {
126 return to_mermaid(g, Options{});
129 static std::string to_mermaid(const Graph& g, const Options& opt) {
131 oss << "flowchart " << (opt.mermaid_lr ? "LR" : "TD") << "\n";
133 for (NodeId id = 0; id < g.node_count(); ++id) {
134 const auto& n = g.node(id);
139 if (opt.show_ports) {
140 label += "\n" + ("in: " + join_ports_(n->input_ports(), opt.max_ports));
141 label += "\n" + ("out: " + join_ports_(n->output_ports(), opt.max_ports));
147 for (const auto& e : g.edges()) {
157 static const char* backend_name_(Backend b) {
159 case Backend::Pipeline:
161 case Backend::Stage:
Generated via doxygen2docusaurus 2.0.0 by Doxygen 1.9.8.