2
2
3
3
#include < mutable/util/fn.hpp>
4
4
#include < mutable/util/macro.hpp>
5
- #include < cstdio>
6
5
#include < fstream>
7
- #include < graphviz/gvc.h>
8
6
#include < iostream>
9
7
#include < sstream>
10
8
19
17
20
18
using namespace m ;
21
19
20
+ // POD type forward declarations
21
+ struct GVC_t ;
22
+ struct Agraph_t ;
23
+ struct graph_t ;
24
+
25
+ // function declarations: add the functions that you need here and to the `SYMBOLS` X macro
26
+ static int (*agclose)(Agraph_t*);
27
+ static Agraph_t*(*agmemread)(const char *);
28
+ static GVC_t*(*gvContext)();
29
+ static int (*gvFreeContext)(GVC_t*);
30
+ static int (*gvFreeLayout)(GVC_t*, graph_t *);
31
+ static int (*gvLayout)(GVC_t*, graph_t *, const char *);
32
+ static int (*gvRenderFilename)(GVC_t*, graph_t *, const char *, const char *);
22
33
23
34
#define SYMBOLS (X ) \
24
35
X (agclose) \
@@ -29,18 +40,16 @@ using namespace m;
29
40
X(gvLayout) \
30
41
X(gvRenderFilename)
31
42
32
- #define DECLSYM (SYM ) static decltype (SYM) *sym_##SYM;
33
- #define LOADSYM (SYM ) { \
34
- sym_##SYM = (decltype (SYM)*)(dlsym (libgraphviz, #SYM)); \
35
- }
43
+ #define LOADSYM (SYM ) SYM = (decltype (SYM))(dlsym(libgraphviz, #SYM));
44
+
36
45
#if __linux
37
46
static constexpr const char * LIB_GRAPHVIZ = " libgvc.so" ;
38
47
#elif __APPLE__
39
48
static constexpr const char * LIB_GRAPHVIZ = " libgvc.dylib" ;
40
49
#endif
50
+
41
51
static void *libgraphviz;
42
52
static GVC_t *gvc;
43
- SYMBOLS (DECLSYM);
44
53
45
54
DotTool::DotTool (Diagnostic &diag)
46
55
: diag(diag)
@@ -54,7 +63,7 @@ DotTool::DotTool(Diagnostic &diag)
54
63
if (libgraphviz) {
55
64
/* Load the required symbols from the shared object. */
56
65
SYMBOLS (LOADSYM);
57
- gvc = sym_gvContext ();
66
+ gvc = gvContext ();
58
67
}
59
68
}
60
69
#endif
@@ -64,11 +73,11 @@ int DotTool::render_to_pdf(const char *path_to_pdf, const char *algo)
64
73
{
65
74
/* ----- Render the dot graph with graphviz. ----------------------------------------------------------------------*/
66
75
auto dotstr = stream_.str ();
67
- Agraph_t *G = M_notnull (sym_agmemread (dotstr.c_str ()));
68
- sym_gvLayout (gvc, G, algo);
69
- auto ret = sym_gvRenderFilename (gvc, G, " pdf" , path_to_pdf);
70
- sym_gvFreeLayout (gvc, G);
71
- sym_agclose (G);
76
+ Agraph_t *G = M_notnull (agmemread (dotstr.c_str ()));
77
+ gvLayout (gvc, ( graph_t *) G, algo);
78
+ auto ret = gvRenderFilename (gvc, ( graph_t *) G, " pdf" , path_to_pdf);
79
+ gvFreeLayout (gvc, ( graph_t *) G);
80
+ agclose (G);
72
81
return ret;
73
82
}
74
83
0 commit comments