EnTT 4.0.0
Loading...
Searching...
No Matches
dot.hpp
1#ifndef ENTT_GRAPH_DOT_HPP
2#define ENTT_GRAPH_DOT_HPP
3
4#include "../stl/concepts.hpp"
5#include "../stl/ostream.hpp"
6#include "fwd.hpp"
7
8namespace entt {
9
17template<typename Graph>
18requires stl::derived_from<typename Graph::graph_category, directed_tag>
19void dot(stl::ostream &out, const Graph &graph, stl::invocable<stl::ostream &, typename Graph::vertex_type> auto writer) {
20 if constexpr(stl::same_as<typename Graph::graph_category, undirected_tag>) {
21 out << "graph{";
22 } else {
23 out << "digraph{";
24 }
25
26 for(auto &&vertex: graph.vertices()) {
27 out << vertex << "[";
28 writer(out, vertex);
29 out << "];";
30 }
31
32 for(auto [lhs, rhs]: graph.edges()) {
33 if constexpr(stl::same_as<typename Graph::graph_category, undirected_tag>) {
34 out << lhs << "--" << rhs << ";";
35 } else {
36 out << lhs << "->" << rhs << ";";
37 }
38 }
39
40 out << "}";
41}
42
49template<typename Graph>
50void dot(stl::ostream &out, const Graph &graph) {
51 return dot(out, graph, [](auto &&...) {});
52}
53
54} // namespace entt
55
56#endif
EnTT default namespace.
Definition dense_map.hpp:25
void dot(stl::ostream &out, const Graph &graph, stl::invocable< stl::ostream &, typename Graph::vertex_type > auto writer)
Outputs a graph in dot format.
Definition dot.hpp:19