From a82f9a8f994b4be486e8e9145d9a61491a27cc4d Mon Sep 17 00:00:00 2001 From: Oliver Hamlet Date: Fri, 6 Jan 2023 17:18:10 +0000 Subject: [PATCH] Return vertex from PluginGraph::AddVertex() --- src/api/sorting/plugin_graph.cpp | 4 +- src/api/sorting/plugin_graph.h | 2 +- .../api/internals/sorting/plugin_graph_test.h | 70 ++++++------------- 3 files changed, 24 insertions(+), 52 deletions(-) diff --git a/src/api/sorting/plugin_graph.cpp b/src/api/sorting/plugin_graph.cpp index 19b61d0f..1f35be15 100644 --- a/src/api/sorting/plugin_graph.cpp +++ b/src/api/sorting/plugin_graph.cpp @@ -577,9 +577,11 @@ void PluginGraph::AddEdge(const vertex_t& fromVertex, pathsCache_.CachePath(fromVertex, toVertex); } -void PluginGraph::AddVertex(const PluginSortingData& plugin) { +vertex_t PluginGraph::AddVertex(const PluginSortingData& plugin) { const auto vertex = boost::add_vertex(plugin, graph_); pluginNameVertexMap.emplace(plugin.GetName(), vertex); + + return vertex; } void PluginGraph::AddSpecificEdges() { diff --git a/src/api/sorting/plugin_graph.h b/src/api/sorting/plugin_graph.h index c65a2a3b..45d4a03a 100644 --- a/src/api/sorting/plugin_graph.h +++ b/src/api/sorting/plugin_graph.h @@ -88,7 +88,7 @@ public: void AddEdge(const vertex_t& fromVertex, const vertex_t& toVertex, EdgeType edgeType); - void AddVertex(const PluginSortingData& plugin); + vertex_t AddVertex(const PluginSortingData& plugin); void AddSpecificEdges(); void AddHardcodedPluginEdges( diff --git a/src/tests/api/internals/sorting/plugin_graph_test.h b/src/tests/api/internals/sorting/plugin_graph_test.h index 9e72f77c..1d595e62 100644 --- a/src/tests/api/internals/sorting/plugin_graph_test.h +++ b/src/tests/api/internals/sorting/plugin_graph_test.h @@ -151,11 +151,8 @@ TEST_F(PluginGraphTest, addOverlapEdgesShouldNotAddEdgesBetweenNonOverlappingPlugins) { PluginGraph graph; - graph.AddVertex(CreatePluginSortingData("1.esp")); - graph.AddVertex(CreatePluginSortingData("2.esp")); - - const auto v1 = graph.GetVertexByName("1.esp").value(); - const auto v2 = graph.GetVertexByName("2.esp").value(); + const auto v1 = graph.AddVertex(CreatePluginSortingData("1.esp")); + const auto v2 = graph.AddVertex(CreatePluginSortingData("2.esp")); graph.AddOverlapEdges(); @@ -175,11 +172,8 @@ TEST_F( PluginGraph graph; - graph.AddVertex(CreatePluginSortingData("1.esp")); - graph.AddVertex(CreatePluginSortingData("2.esp")); - - const auto v1 = graph.GetVertexByName("1.esp").value(); - const auto v2 = graph.GetVertexByName("2.esp").value(); + const auto v1 = graph.AddVertex(CreatePluginSortingData("1.esp")); + const auto v2 = graph.AddVertex(CreatePluginSortingData("2.esp")); graph.AddOverlapEdges(); @@ -199,11 +193,8 @@ TEST_F( PluginGraph graph; - graph.AddVertex(CreatePluginSortingData("1.esp")); - graph.AddVertex(CreatePluginSortingData("2.esp")); - - const auto v1 = graph.GetVertexByName("1.esp").value(); - const auto v2 = graph.GetVertexByName("2.esp").value(); + const auto v1 = graph.AddVertex(CreatePluginSortingData("1.esp")); + const auto v2 = graph.AddVertex(CreatePluginSortingData("2.esp")); graph.AddOverlapEdges(); @@ -222,11 +213,8 @@ TEST_F( PluginGraph graph; - graph.AddVertex(CreatePluginSortingData("1.esp")); - graph.AddVertex(CreatePluginSortingData("2.esp")); - - const auto v1 = graph.GetVertexByName("1.esp").value(); - const auto v2 = graph.GetVertexByName("2.esp").value(); + const auto v1 = graph.AddVertex(CreatePluginSortingData("1.esp")); + const auto v2 = graph.AddVertex(CreatePluginSortingData("2.esp")); graph.AddOverlapEdges(); @@ -246,11 +234,8 @@ TEST_F( PluginGraph graph; - graph.AddVertex(CreatePluginSortingData("1.esp")); - graph.AddVertex(CreatePluginSortingData("2.esp")); - - const auto v1 = graph.GetVertexByName("1.esp").value(); - const auto v2 = graph.GetVertexByName("2.esp").value(); + const auto v1 = graph.AddVertex(CreatePluginSortingData("1.esp")); + const auto v2 = graph.AddVertex(CreatePluginSortingData("2.esp")); graph.AddOverlapEdges(); @@ -269,11 +254,8 @@ TEST_F( PluginGraph graph; - graph.AddVertex(CreatePluginSortingData("1.esp")); - graph.AddVertex(CreatePluginSortingData("2.esp")); - - const auto v1 = graph.GetVertexByName("1.esp").value(); - const auto v2 = graph.GetVertexByName("2.esp").value(); + const auto v1 = graph.AddVertex(CreatePluginSortingData("1.esp")); + const auto v2 = graph.AddVertex(CreatePluginSortingData("2.esp")); graph.AddOverlapEdges(); @@ -293,11 +275,8 @@ TEST_F( PluginGraph graph; - graph.AddVertex(CreatePluginSortingData("1.esp")); - graph.AddVertex(CreatePluginSortingData("2.esp")); - - const auto v1 = graph.GetVertexByName("1.esp").value(); - const auto v2 = graph.GetVertexByName("2.esp").value(); + const auto v1 = graph.AddVertex(CreatePluginSortingData("1.esp")); + const auto v2 = graph.AddVertex(CreatePluginSortingData("2.esp")); graph.AddOverlapEdges(); @@ -318,11 +297,8 @@ TEST_F( PluginGraph graph; - graph.AddVertex(CreatePluginSortingData("1.esp")); - graph.AddVertex(CreatePluginSortingData("2.esp")); - - const auto v1 = graph.GetVertexByName("1.esp").value(); - const auto v2 = graph.GetVertexByName("2.esp").value(); + const auto v1 = graph.AddVertex(CreatePluginSortingData("1.esp")); + const auto v2 = graph.AddVertex(CreatePluginSortingData("2.esp")); graph.AddOverlapEdges(); @@ -344,11 +320,8 @@ TEST_F( PluginGraph graph; - graph.AddVertex(CreatePluginSortingData("1.esp")); - graph.AddVertex(CreatePluginSortingData("2.esp")); - - const auto v1 = graph.GetVertexByName("1.esp").value(); - const auto v2 = graph.GetVertexByName("2.esp").value(); + const auto v1 = graph.AddVertex(CreatePluginSortingData("1.esp")); + const auto v2 = graph.AddVertex(CreatePluginSortingData("2.esp")); graph.AddOverlapEdges(); @@ -370,11 +343,8 @@ TEST_F(PluginGraphTest, PluginGraph graph; - graph.AddVertex(CreatePluginSortingData("1.esp")); - graph.AddVertex(CreatePluginSortingData("2.esp")); - - const auto v1 = graph.GetVertexByName("1.esp").value(); - const auto v2 = graph.GetVertexByName("2.esp").value(); + const auto v1 = graph.AddVertex(CreatePluginSortingData("1.esp")); + const auto v2 = graph.AddVertex(CreatePluginSortingData("2.esp")); graph.AddOverlapEdges();