The Gaudi Framework master (9cc87df9)
Loading...
Searching...
No Matches
Gaudi::Hive::Graph Class Reference

utilities to dump graphs in different formats More...

#include <GraphDumper.h>

Public Member Functions

 Graph (std::string_view fileName, FileType type=FileType::UNKNOWN)
 Creates a graph with given type and given file name.
 ~Graph ()
std::string const & fileName ()
void addNode (std::string_view id, std::string_view name)
void addEdge (std::string_view srcId, std::string_view tgtId, std::string_view label="")

Private Member Functions

void writeHeader ()
void writeTrailer ()

Private Attributes

std::string m_fileName
 name of the filed used for storing the graph
std::ofstream m_stream
 stream to the graph file
FileType m_type { FileType::UNKNOWN }
 type of file used

Detailed Description

utilities to dump graphs in different formats

supported right now : .dot, mermaid and graphml

Usage :

  • create a Graph calling the constructor with type and name of the output file
  • use then addNode and addEdge to specify the graph
  • on destruction, the Graph will be written to file

Definition at line 30 of file GraphDumper.h.

Constructor & Destructor Documentation

◆ Graph()

Gaudi::Hive::Graph::Graph ( std::string_view fileName,
FileType type = FileType::UNKNOWN )

Creates a graph with given type and given file name.

by default (and if UNKNOWN is provided) type is deduced from the file extension in case extension is not recognized, dot format is used and filename gets an extra ".dot" at the end

Definition at line 43 of file GraphDumper.cpp.

44 // find out type of file if not given
45 if ( type == FileType::UNKNOWN ) {
46 // Check file extension
47 if ( m_fileName.ends_with( ".dot" ) ) {
49 } else if ( m_fileName.ends_with( ".md" ) ) {
51 } else if ( m_fileName.ends_with( ".graphml" ) ) {
53 } else {
55 m_fileName += ".dot";
56 }
57 }
58 // open file
61 }
basic_ofstream< char > ofstream
static const openmode out
FileType m_type
type of file used
Definition GraphDumper.h:60
std::string m_fileName
name of the filed used for storing the graph
Definition GraphDumper.h:56
std::string const & fileName()
std::ofstream m_stream
stream to the graph file
Definition GraphDumper.h:58

◆ ~Graph()

Gaudi::Hive::Graph::~Graph ( )

Definition at line 63 of file GraphDumper.cpp.

63 {
66 }

Member Function Documentation

◆ addEdge()

void Gaudi::Hive::Graph::addEdge ( std::string_view srcId,
std::string_view tgtId,
std::string_view label = "" )

Definition at line 91 of file GraphDumper.cpp.

91 {
92 switch ( m_type ) {
93 case FileType::DOT:
94 m_stream << " " << srcId << " -> " << tgtId;
95 if ( label != "" ) m_stream << " [label=\"" << label << "\"]";
96 m_stream << ";\n";
97 break;
98 case FileType::MD:
99 m_stream << " " << srcId << " --> " << tgtId;
100 if ( label != "" ) m_stream << " : " << label;
101 m_stream << "\n";
102 break;
103 case FileType::ML:
104 if ( label != "" ) {
105 m_stream << " <edge source=\"" << srcId << "\" target=\"" << tgtId
106 << "\">\n"
107 " <data key=\"d1\">"
108 << escapeSpecialCharactersForMl( label )
109 << "</data>\n"
110 " </edge>\n";
111 } else {
112 m_stream << " <edge source=\"" << srcId << "\" target=\"" << tgtId << "\"/>\n";
113 }
114 break;
116 break;
117 }
118 };

◆ addNode()

void Gaudi::Hive::Graph::addNode ( std::string_view id,
std::string_view name )

Definition at line 70 of file GraphDumper.cpp.

70 {
71 switch ( m_type ) {
72 case FileType::DOT:
73 m_stream << " " << id << " [label=\"" << name << "\";shape=box];\n";
74 break;
75 case FileType::MD:
76 m_stream << " " << id << "{{" << name << "}}\n";
77 break;
78 case FileType::ML:
79 m_stream << " <node id=\"" << id
80 << "\">\n"
81 " <data key=\"d0\">"
82 << escapeSpecialCharactersForMl( name )
83 << "</data>\n"
84 " </node>\n";
85 break;
87 break;
88 }
89 };

◆ fileName()

std::string const & Gaudi::Hive::Graph::fileName ( )

Definition at line 68 of file GraphDumper.cpp.

68{ return m_fileName; }

◆ writeHeader()

void Gaudi::Hive::Graph::writeHeader ( )
private

Definition at line 122 of file GraphDumper.cpp.

122 {
123 switch ( m_type ) {
124 case FileType::DOT:
125 m_stream << "digraph datadeps {\n rankdir=\"LR\";\n";
126 break;
127 case FileType::MD:
128 m_stream << "```mermaid\ngraph LR;\n\n";
129 break;
130 case FileType::ML:
131 m_stream << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
132 "<graphml xmlns=\"http://graphml.graphdrawing.org/xmlns\"\n"
133 " xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n"
134 " xsi:schemaLocation=\"http://graphml.graphdrawing.org/xmlns "
135 "http://graphml.graphdrawing.org/xmlns/1.0/graphml.xsd\">\n"
136 " <key id=\"d1\" for=\"edge\" attr.name=\"label\" attr.type=\"string\"/>\n"
137 " <key id=\"d0\" for=\"node\" attr.name=\"label\" attr.type=\"string\"/>\n"
138 " <graph id=\"Dependencies\" edgedefault=\"directed\">\n";
139 break;
141 break;
142 }
143 }

◆ writeTrailer()

void Gaudi::Hive::Graph::writeTrailer ( )
private

Definition at line 145 of file GraphDumper.cpp.

145 {
146 switch ( m_type ) {
147 case FileType::DOT:
148 m_stream << "}\n";
149 break;
150 case FileType::MD:
151 m_stream << "```\n";
152 break;
153 case FileType::ML:
154 m_stream << " </graph>\n</graphml>";
155 break;
157 break;
158 }
159 }

Member Data Documentation

◆ m_fileName

std::string Gaudi::Hive::Graph::m_fileName
private

name of the filed used for storing the graph

Definition at line 56 of file GraphDumper.h.

◆ m_stream

std::ofstream Gaudi::Hive::Graph::m_stream
private

stream to the graph file

Definition at line 58 of file GraphDumper.h.

◆ m_type

FileType Gaudi::Hive::Graph::m_type { FileType::UNKNOWN }
private

type of file used

Definition at line 60 of file GraphDumper.h.


The documentation for this class was generated from the following files: