1 #ifndef NOM_CONVERTERS_DOT_H 2 #define NOM_CONVERTERS_DOT_H 4 #include "nomnigraph/Graph/Graph.h" 5 #include "nomnigraph/Support/Casting.h" 13 template <
typename T,
typename U = T>
class DotGenerator {
15 using NodePrinter = std::function<std::map<std::string, std::string>(
17 using EdgePrinter = std::function<std::map<std::string, std::string>(
20 static std::map<std::string, std::string>
22 std::map<std::string, std::string> labelMap;
28 std::string convert(NodePrinter nodePrinter, EdgePrinter edgePrinter) {
29 std::ostringstream output;
30 output <<
"digraph G {\n\ 31 bgcolor=\"#ffffff00\"\n\ 33 node[fontcolor=white,color=white];\n\ 34 edge[fontcolor=white,color=white];\n\ 36 for (
const auto &node : g_->getMutableNodes()) {
37 output << (uint64_t)node;
39 for (
const auto &attrib : nodePrinter(node)) {
40 output << attrib.first <<
"=\"" << attrib.second <<
"\",";
43 for (
const auto &edge : node->getOutEdges()) {
44 output << (uint64_t)edge->tail() <<
" -> " << (uint64_t)edge->head();
46 for (
const auto &attrib : edgePrinter(edge)) {
47 output << attrib.first <<
"=\"" << attrib.second <<
"\",";
52 for (
auto i = 0; i < subgraphs_.size(); ++i) {
53 const auto &subgraph = subgraphs_[i];
54 output <<
"subgraph cluster" << i <<
" {\n";
55 output <<
"style=dotted;\n";
56 for (
const auto &node : subgraph->getNodes()) {
57 output << static_cast<uint64_t>(node);
70 typename std::vector<const nom::Subgraph<T, U> *> subgraphs_;
76 namespace converters {
78 template <
typename T,
typename U = T>
81 typename DotGenerator<T, U>::NodePrinter nodePrinter,
82 typename DotGenerator<T, U>::EdgePrinter edgePrinter =
83 DotGenerator<T, U>::defaultEdgePrinter) {
84 auto d = DotGenerator<T, U>(g);
85 return d.convert(nodePrinter, edgePrinter);
88 template <
typename T,
typename U = T>
92 typename DotGenerator<T, U>::NodePrinter nodePrinter,
93 typename DotGenerator<T, U>::EdgePrinter edgePrinter =
94 DotGenerator<T, U>::defaultEdgePrinter) {
95 auto d = DotGenerator<T, U>(g);
96 for (
const auto &subgraph : subgraphs) {
97 d.addSubgraph(&subgraph);
99 return d.convert(nodePrinter, edgePrinter);
105 #endif // NOM_CONVERTERS_DOT_H Effectively a constant reference to a graph.
A simple graph implementation.