13#include <boost/algorithm/string/replace.hpp>
16 std::string escapeSpecialCharactersForMl( std::string_view view ) {
18 result.reserve( view.size() * 6 );
19 for (
char c : view ) {
34 result.push_back( c );
39 return std::string{ result };
53 }
else if (
m_fileName.ends_with(
".graphml" ) ) {
75 m_stream <<
" " <<
id <<
" [label=\"" << name <<
"\";shape=box];\n";
78 m_stream <<
" " <<
id <<
"{{" << name <<
"}}\n";
84 << escapeSpecialCharactersForMl( name )
93 void Graph::addEdge( std::string_view srcId, std::string_view tgtId, std::string_view label ) {
96 m_stream <<
" " << srcId <<
" -> " << tgtId;
97 if ( label !=
"" )
m_stream <<
" [label=\"" << label <<
"\"]";
101 m_stream <<
" " << srcId <<
" --> " << tgtId;
102 if ( label !=
"" )
m_stream <<
" : " << label;
107 m_stream <<
" <edge source=\"" << srcId <<
"\" target=\"" << tgtId
110 << escapeSpecialCharactersForMl( label )
114 m_stream <<
" <edge source=\"" << srcId <<
"\" target=\"" << tgtId <<
"\"/>\n";
127 m_stream <<
"digraph datadeps {\n rankdir=\"LR\";\n";
130 m_stream <<
"```mermaid\ngraph LR;\n\n";
133 m_stream <<
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
134 "<graphml xmlns=\"http://graphml.graphdrawing.org/xmlns\"\n"
135 " xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n"
136 " xsi:schemaLocation=\"http://graphml.graphdrawing.org/xmlns "
137 "http://graphml.graphdrawing.org/xmlns/1.0/graphml.xsd\">\n"
138 " <key id=\"d1\" for=\"edge\" attr.name=\"label\" attr.type=\"string\"/>\n"
139 " <key id=\"d0\" for=\"node\" attr.name=\"label\" attr.type=\"string\"/>\n"
140 " <graph id=\"Dependencies\" edgedefault=\"directed\">\n";
156 m_stream <<
" </graph>\n</graphml>";
void addNode(std::string_view id, std::string_view name)
FileType m_type
type of file used
void addEdge(std::string_view srcId, std::string_view tgtId, std::string_view label="")
std::string m_fileName
name of the filed used for storing the graph
std::string const & fileName()
Graph(std::string_view fileName, FileType type=FileType::UNKNOWN)
Creates a graph with given type and given file name.
std::ofstream m_stream
stream to the graph file