EnTT 3.14.0
Loading...
Searching...
No Matches
dot.hpp
1#ifndef ENTT_GRAPH_DOT_HPP
2#define ENTT_GRAPH_DOT_HPP
3
4#include <ostream>
5#include <type_traits>
6#include "fwd.hpp"
7
8namespace entt {
9
18template<typename Graph, typename Writer>
19void dot(std::ostream &out, const Graph &graph, Writer writer) {
20 static_assert(std::is_base_of_v<directed_tag, typename Graph::graph_category>, "Invalid graph category");
21
22 if constexpr(std::is_same_v<typename Graph::graph_category, undirected_tag>) {
23 out << "graph{";
24 } else {
25 out << "digraph{";
26 }
27
28 for(auto &&vertex: graph.vertices()) {
29 out << vertex << "[";
30 writer(out, vertex);
31 out << "];";
32 }
33
34 for(auto [lhs, rhs]: graph.edges()) {
35 if constexpr(std::is_same_v<typename Graph::graph_category, undirected_tag>) {
36 out << lhs << "--" << rhs << ";";
37 } else {
38 out << lhs << "->" << rhs << ";";
39 }
40 }
41
42 out << "}";
43}
44
51template<typename Graph>
52void dot(std::ostream &out, const Graph &graph) {
53 return dot(out, graph, [](auto &&...) {});
54}
55
56} // namespace entt
57
58#endif
EnTT default namespace.
Definition dense_map.hpp:22
constexpr Type make_obj_using_allocator(const Allocator &allocator, Args &&...args)
Uses-allocator construction utility (waiting for C++20).
Definition memory.hpp:219
void dot(std::ostream &out, const Graph &graph, Writer writer)
Outputs a graph in dot format.
Definition dot.hpp:19