Commit 316bf229 authored by Floris Berendsen's avatar Floris Berendsen
Browse files

ENH: Delete for named connections; and tests

parent 0989fcca
......@@ -82,7 +82,7 @@ public:
ParameterMapType GetConnection( ComponentNameType upstream, ComponentNameType downstream, ConnectionNameType name = "" ) const;
bool DeleteConnection( ComponentNameType upstream, ComponentNameType downstream );
bool DeleteConnection( ComponentNameType upstream, ComponentNameType downstream, ConnectionNameType name = "" );
bool ConnectionExists( ComponentNameType upstream, ComponentNameType downstream, ConnectionNameType name = "" ) const;
......
......@@ -101,10 +101,10 @@ Blueprint
bool
Blueprint
::DeleteConnection( ComponentNameType upstream, ComponentNameType downstream )
::DeleteConnection( ComponentNameType upstream, ComponentNameType downstream, ConnectionNameType name )
{
this->Modified();
return this->m_BlueprintImpl->DeleteConnection( upstream, downstream );
return this->m_BlueprintImpl->DeleteConnection( upstream, downstream, name );
}
......
......@@ -224,12 +224,20 @@ BlueprintImpl
{
if( this->ConnectionExists( upstream, downstream, name ) )
{
// this removes all connections between upstream and downstream
//TODO: remove only connection named "name"
boost::remove_edge_by_label( upstream, downstream, this->m_Graph );
boost::graph_traits<GraphType>::out_edge_iterator ei, ei_end;
// too bad edge_range_by_label doesn't exist
boost::tie(ei, ei_end) = boost::edge_range(this->m_Graph.vertex(upstream), this->m_Graph.vertex(downstream), this->m_Graph.graph());
for (; ei != ei_end; ++ei) {
auto existingName = boost::get(&ConnectionPropertyType::name, this->m_Graph.graph(), *ei);
if (name == existingName)
{
boost::remove_edge(*ei, this->m_Graph.graph());
return true;
}
}
}
return !this->ConnectionExists( upstream, downstream, name );
return false;
}
......
......@@ -209,13 +209,21 @@ TEST_F(BlueprintTest, ParallelConnections) //#150: Let Blueprint handle two conn
auto blueprint = Blueprint::New();
blueprint->SetComponent("ComponentA", { });
blueprint->SetComponent("ComponentB", { });
blueprint->SetConnection("ComponentA", "ComponentB", {{"NameOfInterface", {"FirstInterface"}}},"FirstConnection");
blueprint->SetConnection("ComponentA", "ComponentB", {{"NameOfInterface", {"SecondInterface"}}},"SecondConnection");
ParameterMapType firstConnection = {{"NameOfInterface", {"FirstInterface"}}};
blueprint->SetConnection("ComponentA", "ComponentB", firstConnection, "FirstConnection");
ParameterMapType secondConnection = {{"NameOfInterface", {"SecondInterface"}}};
blueprint->SetConnection("ComponentA", "ComponentB", secondConnection, "SecondConnection");
auto connection1 = blueprint->GetConnection("ComponentA", "ComponentB","FirstConnection");
EXPECT_EQ(firstConnection["NameOfInterface"][0], connection1["NameOfInterface"][0]);
auto connection2 = blueprint->GetConnection("ComponentA", "ComponentB","SecondConnection");
//auto item = connection1[0];
EXPECT_EQ(secondConnection["NameOfInterface"][0], connection2["NameOfInterface"][0]);
blueprint->DeleteConnection("ComponentA", "ComponentB", "FirstConnection");
EXPECT_FALSE(blueprint->ConnectionExists("ComponentA", "ComponentB", "FirstConnection"));
EXPECT_TRUE(blueprint->ConnectionExists("ComponentA", "ComponentB", "SecondConnection"));
blueprint->DeleteConnection("ComponentA", "ComponentB", "SecondConnection");
EXPECT_FALSE(blueprint->ConnectionExists("ComponentA", "ComponentB", "SecondConnection"));
}
TEST_F(BlueprintTest, ReadParallelConnections) //#150: Let Blueprint reader handle two connections between the same components
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment