]> granicus.if.org Git - graphviz/commitdiff
tests: SvgAnalyzer: add a graphvizGraph class
authorMagnus Jacobsson <Magnus.Jacobsson@berotec.se>
Wed, 17 Aug 2022 10:54:36 +0000 (12:54 +0200)
committerMagnus Jacobsson <Magnus.Jacobsson@berotec.se>
Tue, 23 Aug 2022 06:19:35 +0000 (08:19 +0200)
tests/CMakeLists.txt
tests/graphviz_graph.cpp [new file with mode: 0644]
tests/graphviz_graph.h [new file with mode: 0644]

index 9f48cd86efbf01c2ec1181ebea23b46a05741e0a..03d4b1a89bd701aba965f6cfed6ae03e28d3bb78 100644 (file)
@@ -14,6 +14,8 @@ add_library(test_common SHARED
             catch2_main.cpp
             graphviz_edge.cpp
             graphviz_edge.h
+            graphviz_graph.cpp
+            graphviz_graph.h
             graphviz_node.h
             graphviz_node.cpp
             test_utilities.cpp
diff --git a/tests/graphviz_graph.cpp b/tests/graphviz_graph.cpp
new file mode 100644 (file)
index 0000000..183a723
--- /dev/null
@@ -0,0 +1,24 @@
+#include "graphviz_graph.h"
+
+GraphvizGraph::GraphvizGraph(SVG::SVGElement &svg_g_element)
+    : m_svg_g_element(svg_g_element) {}
+
+void GraphvizGraph::add_node(SVG::SVGElement &svg_g_element) {
+  m_nodes.emplace_back(svg_g_element);
+}
+
+const std::vector<GraphvizNode> &GraphvizGraph::nodes() const {
+  return m_nodes;
+}
+
+const SVG::SVGElement &GraphvizGraph::svg_g_element() const {
+  return m_svg_g_element;
+}
+
+void GraphvizGraph::add_edge(SVG::SVGElement &svg_g_element) {
+  m_edges.emplace_back(svg_g_element);
+}
+
+const std::vector<GraphvizEdge> &GraphvizGraph::edges() const {
+  return m_edges;
+}
diff --git a/tests/graphviz_graph.h b/tests/graphviz_graph.h
new file mode 100644 (file)
index 0000000..e55551f
--- /dev/null
@@ -0,0 +1,42 @@
+#pragma once
+
+#include <stdexcept>
+#include <string>
+#include <vector>
+
+#include "graphviz_edge.h"
+#include "graphviz_node.h"
+
+/**
+ * @brief The GraphvizGraph class represents a Graphviz graph according to the
+ * DOT language
+ */
+
+class GraphvizGraph {
+public:
+  GraphvizGraph() = delete;
+  explicit GraphvizGraph(SVG::SVGElement &g_element);
+
+  /// Add a Graphviz edge to the graph
+  void add_edge(SVG::SVGElement &svg_g_element);
+  /// Add a Graphviz node to the graph
+  void add_node(SVG::SVGElement &svg_g_element);
+  /// Return a non-mutable reference to the list of Graphviz edges
+  const std::vector<GraphvizEdge> &edges() const;
+  /// Return a non-mutable reference to the list of Graphviz nodes
+  const std::vector<GraphvizNode> &nodes() const;
+  /// Return a non-mutable reference to the SVG `g` element corresponding to the
+  /// graph
+  const SVG::SVGElement &svg_g_element() const;
+
+private:
+  /// A list of edges belonging to this graph
+  std::vector<GraphvizEdge> m_edges;
+  /// The `ID` according to the DOT language specification. Note that this is
+  /// not the same as the `id` attribute of a graph
+  std::string m_graph_id;
+  /// A list of nodes belonging to this graph
+  std::vector<GraphvizNode> m_nodes;
+  /// The SVG `g` element corresponding to the graph
+  SVG::SVGElement &m_svg_g_element;
+};