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 |
| struct | Options |
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 {
19class GraphPrinter final {
22 bool show_index = true;
24 bool show_user_label = true;
25 bool show_backend = true;
26 bool show_ports = true;
28 std::size_t max_label_chars = 200;
31 bool dot_rankdir_lr = true;
32 std::string dot_graph_name = "sima_hybrid_graph";
34 bool mermaid_lr = true;
35 std::string mermaid_id_prefix = "n";
43 for (NodeId id = 0; id < g.node_count(); ++id) {
44 const auto& n = g.node(id);
48 if (opt.show_index)
50 if (opt.show_kind)
52 if (opt.show_backend) {
55 if (opt.show_user_label) {
58 oss << " '" << truncate_(label, opt.max_label_chars) << "'";
61 if (opt.show_ports) {
62 oss << "\n in: " << join_ports_(n->input_ports(), opt.max_ports);
63 oss << "\n out: " << join_ports_(n->output_ports(), opt.max_ports);
66 if (id + 1 < g.node_count())
77 oss << "digraph " << dot_id_(opt.dot_graph_name) << " {\n";
78 if (opt.dot_rankdir_lr)
82 for (NodeId id = 0; id < g.node_count(); ++id) {
83 const auto& n = g.node(id);
88 if (opt.show_ports) {
89 label += "\\n" + dot_escape_("in: " + join_ports_(n->input_ports(), opt.max_ports));
90 label += "\\n" + dot_escape_("out: " + join_ports_(n->output_ports(), opt.max_ports));
96 for (const auto& e : g.edges()) {
106 static std::string to_mermaid(const Graph& g) {
107 return to_mermaid(g, Options{});
109 static std::string to_mermaid(const Graph& g, const Options& opt) {
111 oss << "flowchart " << (opt.mermaid_lr ? "LR" : "TD") << "\n";
113 for (NodeId id = 0; id < g.node_count(); ++id) {
114 const auto& n = g.node(id);
119 if (opt.show_ports) {
120 label += "\n" + ("in: " + join_ports_(n->input_ports(), opt.max_ports));
121 label += "\n" + ("out: " + join_ports_(n->output_ports(), opt.max_ports));
127 for (const auto& e : g.edges()) {
137 static const char* backend_name_(Backend b) {
139 case Backend::Pipeline:
141 case Backend::Stage:
225 return "n" + std::to_string(id);
229 return opt.mermaid_id_prefix + std::to_string(id);
Generated via doxygen2docusaurus 2.0.0 by Doxygen 1.9.1.