summaryrefslogtreecommitdiffstats
path: root/deps/include/entt/graph/dot.hpp
diff options
context:
space:
mode:
authoruntodesu <kirill@untode.su>2025-03-15 16:22:09 +0500
committeruntodesu <kirill@untode.su>2025-03-15 16:22:09 +0500
commit3bf42c6ff3805a0d42bbc661794a95ff31bedc26 (patch)
tree05049955847504808d6bed2bb7b155f8b03807bb /deps/include/entt/graph/dot.hpp
parent02294547dcde0d4ad76e229106702261e9f10a51 (diff)
downloadvoxelius-3bf42c6ff3805a0d42bbc661794a95ff31bedc26.tar.bz2
voxelius-3bf42c6ff3805a0d42bbc661794a95ff31bedc26.zip
Add whatever I was working on for the last month
Diffstat (limited to 'deps/include/entt/graph/dot.hpp')
-rw-r--r--deps/include/entt/graph/dot.hpp58
1 files changed, 58 insertions, 0 deletions
diff --git a/deps/include/entt/graph/dot.hpp b/deps/include/entt/graph/dot.hpp
new file mode 100644
index 0000000..4671aa8
--- /dev/null
+++ b/deps/include/entt/graph/dot.hpp
@@ -0,0 +1,58 @@
+#ifndef ENTT_GRAPH_DOT_HPP
+#define ENTT_GRAPH_DOT_HPP
+
+#include <ostream>
+#include <type_traits>
+#include "fwd.hpp"
+
+namespace entt {
+
+/**
+ * @brief Outputs a graph in dot format.
+ * @tparam Graph Graph type, valid as long as it exposes edges and vertices.
+ * @tparam Writer Vertex decorator type.
+ * @param out A standard output stream.
+ * @param graph The graph to output.
+ * @param writer Vertex decorator object.
+ */
+template<typename Graph, typename Writer>
+void dot(std::ostream &out, const Graph &graph, Writer writer) {
+ static_assert(std::is_base_of_v<directed_tag, typename Graph::graph_category>, "Invalid graph category");
+
+ if constexpr(std::is_same_v<typename Graph::graph_category, undirected_tag>) {
+ out << "graph{";
+ } else {
+ out << "digraph{";
+ }
+
+ for(auto &&vertex: graph.vertices()) {
+ out << vertex << "[";
+ writer(out, vertex);
+ out << "];";
+ }
+
+ for(auto [lhs, rhs]: graph.edges()) {
+ if constexpr(std::is_same_v<typename Graph::graph_category, undirected_tag>) {
+ out << lhs << "--" << rhs << ";";
+ } else {
+ out << lhs << "->" << rhs << ";";
+ }
+ }
+
+ out << "}";
+}
+
+/**
+ * @brief Outputs a graph in dot format.
+ * @tparam Graph Graph type, valid as long as it exposes edges and vertices.
+ * @param out A standard output stream.
+ * @param graph The graph to output.
+ */
+template<typename Graph>
+void dot(std::ostream &out, const Graph &graph) {
+ return dot(out, graph, [](auto &&...) {});
+}
+
+} // namespace entt
+
+#endif