-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
graphviz.cpp
42 lines (30 loc) · 884 Bytes
/
graphviz.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include <stdio.h>
#include "graphviz.h"
#include "utils.h"
graphviz::graphviz(const std::string & filename) : filename(filename)
{
}
graphviz::~graphviz()
{
if (filename.empty() == false) {
FILE *fh = fopen(filename.c_str(), "w");
if (!fh)
error_exit(true, "Failed creating %s", filename.c_str());
fprintf(fh, "digraph {\n");
for(auto & node: nodes)
fprintf(fh, "\t\"%s\" [label=\"%s\"]\n", node.first.c_str(), node.second.c_str());
for(auto & connection: connections)
fprintf(fh, "\t\"%s\" -> \"%s\"\n", connection.first.c_str(), connection.second.c_str());
fprintf(fh, "}\n");
fclose(fh);
}
}
std::string graphviz::add_node(const std::string & name, const std::string & meta)
{
nodes.insert({ name, meta });
return name;
}
void graphviz::add_connection(const std::string & from, const std::string & to)
{
connections.insert({ from, to });
}