Commit fb838449 authored by Floris Berendsen's avatar Floris Berendsen
Browse files

ENH: added Blueprint Copy constructor, finished ComposeWith and extended

BlueprintTest
parent 0e23bb37
......@@ -39,6 +39,10 @@ public:
typedef std::vector< ComponentNameType > ComponentNamesType;
Blueprint( void );
Blueprint(const Blueprint& other); // copyable
Blueprint& operator=(const Blueprint& other); //
//Blueprint(Blueprint&&);
~Blueprint( void );
bool SetComponent( ComponentNameType, ParameterMapType parameterMap );
......@@ -60,6 +64,8 @@ public:
bool ConnectionExists( ComponentNameType upstream, ComponentNameType downstream ) const;
//std::unique_ptr<Blueprint> Clone(Blueprint const &other );
// "functional" composition of blueprints is done by adding settings of other to this blueprint. Redefining/overwriting properties is not allowed and returns false.
bool ComposeWith(std::unique_ptr<Blueprint> const &other);
......
......@@ -26,6 +26,19 @@ namespace selx {
Blueprint
::Blueprint( void ) : m_Pimple( new Blueprint::BlueprintImpl ) {};
Blueprint::Blueprint(const Blueprint& other)
: m_Pimple(new BlueprintImpl(*other.m_Pimple))
{}
Blueprint& Blueprint::operator=(const Blueprint& other) {
if (this != &other) {
m_Pimple.reset(new BlueprintImpl(*other.m_Pimple));
}
return *this;
}
//Blueprint
//::Blueprint(Blueprint&&) = default;
Blueprint
::~Blueprint( void ) = default;
......@@ -101,6 +114,12 @@ Blueprint
return this->m_Pimple->ConnectionExists( upstream, downstream );
}
//std::unique_ptr<Blueprint>
//Blueprint
//::Clone(Blueprint const &other)
//{
// return std::make_unique<Blueprint>(other);
//}
bool
Blueprint
......
......@@ -93,13 +93,25 @@ inline edge_label_writer< ParameterMapType >
return edge_label_writer< ParameterMapType >(p);
}
struct Blueprint::BlueprintImpl::do_nothing
{
template <typename VertexOrEdge1, typename VertexOrEdge2>
void operator()(const VertexOrEdge1&, VertexOrEdge2&) const
{
}
};
//Used in CloneGraph
struct Blueprint::BlueprintImpl::vertex_copier {
struct Blueprint::BlueprintImpl::vertex_copier
{
ComponentPropertyType& from;
ComponentPropertyType& to;
void operator()(Blueprint::BlueprintImpl::GraphType::vertex_descriptor input, Blueprint::BlueprintImpl::GraphType::vertex_descriptor output) const {
void operator()(GraphType::vertex_descriptor input, GraphType::vertex_descriptor output) const {
//TODO !
//to[output] = { from[input]};
//to.name = from.name ;
//to.name = from.name;
}
};
......@@ -232,9 +244,12 @@ Blueprint::BlueprintImpl::GraphType
Blueprint::BlueprintImpl
::CloneGraph(void) const
{
GraphType clone;
GraphType clone = GraphType(this->m_Graph);
// TODO!
// boost::copy_graph(this->m_Graph, clone, boost::vertex_copy(vertex_copier()));
//boost::copy_graph(this->m_Graph, clone, boost::vertex_copy(do_nothing()).edge_copy(do_nothing()));
//boost::copy_graph(this->m_Graph, clone, boost::vertex_copy(vertex_copier( this->m_Graph, clone )));
//boost::copy_graph(this->m_Graph, clone);
return clone;
}
......
......@@ -37,6 +37,7 @@ struct Blueprint::BlueprintImpl {
// and holds component configuration settings
struct ComponentPropertyType
{
ComponentPropertyType(ComponentNameType name = "", ParameterMapType parameterMap = {}) : name(name), parameterMap(parameterMap) {}
ComponentNameType name;
ParameterMapType parameterMap;
};
......@@ -45,10 +46,12 @@ struct Blueprint::BlueprintImpl {
// and holds component connection configuration settings
struct ConnectionPropertyType
{
ConnectionPropertyType(ParameterMapType parameterMap = {}) : parameterMap(parameterMap) {}
ParameterMapType parameterMap;
};
struct vertex_copier;
struct do_nothing;
typedef boost::labeled_graph<
boost::adjacency_list<
......
......@@ -105,6 +105,24 @@ TEST_F( BlueprintTest, SetGetDeleteConnection )
}
TEST_F(BlueprintTest, CopyConstuctor)
{
std::unique_ptr< Blueprint > baseBlueprint;
EXPECT_NO_THROW(baseBlueprint = std::unique_ptr< Blueprint >(new Blueprint()));
baseBlueprint->SetComponent("Component0", { { "OperationType", { "Transform" } } });
std::unique_ptr< Blueprint > clonedBaseBlueprint;
EXPECT_NO_THROW(clonedBaseBlueprint = std::make_unique<Blueprint>(*baseBlueprint.get()));
EXPECT_NO_THROW(clonedBaseBlueprint->SetComponent("Component1", { { "OperationType", { "Source" } }, { "Dimensionality", { "3" } } }));
Blueprint::ParameterMapType clonedComponent0;
EXPECT_NO_THROW(clonedComponent0 = clonedBaseBlueprint->GetComponent("Component0"));
Blueprint::ParameterMapType component1;
EXPECT_THROW(component1 = baseBlueprint->GetComponent("Component1"), std::runtime_error);
}
TEST_F(BlueprintTest, Compose)
{
std::unique_ptr< Blueprint > baseBlueprint;
......@@ -121,7 +139,7 @@ TEST_F(BlueprintTest, Compose)
nonConflictingBlueprint0->SetComponent("Component2", { { "OperationType", { "Sink" } } });
EXPECT_TRUE(baseBlueprint->ComposeWith(nonConflictingBlueprint0));
EXPECT_STREQ("Sink", baseBlueprint->GetComponent("Component2")["OperationType"][0].c_str());
// compose-in additional properties of Component0 and Component1
std::unique_ptr< Blueprint > nonConflictingBlueprint1;
......@@ -131,7 +149,9 @@ TEST_F(BlueprintTest, Compose)
nonConflictingBlueprint1->SetComponent("Component1", { { "NameOfClass", { "ImageSourceClass" } } });
EXPECT_TRUE( baseBlueprint->ComposeWith(nonConflictingBlueprint1) );
EXPECT_STREQ("Transform", baseBlueprint->GetComponent("Component0")["OperationType"][0].c_str());
EXPECT_STREQ("Diffeomorphic", baseBlueprint->GetComponent("Component0")["TranformationGroup"][0].c_str());
EXPECT_STREQ("ImageSourceClass", baseBlueprint->GetComponent("Component1")["NameOfClass"][0].c_str());
// compose-in existing component with existing property key, but equal property value(s). Nothing happens actually (i.e. idempotency)
std::unique_ptr< Blueprint > nonConflictingBlueprint2;
......@@ -145,10 +165,15 @@ TEST_F(BlueprintTest, Compose)
// trying to overwrite properties fails
std::unique_ptr< Blueprint > conflictingBlueprint0;
EXPECT_NO_THROW(conflictingBlueprint0 = std::unique_ptr< Blueprint >(new Blueprint()));
conflictingBlueprint0->SetComponent("Component1", { { "Dimensionality", { "2" } }, { "PixelType", { "float" } } });
conflictingBlueprint0->SetComponent("Component1", { { "Dimensionality", { "2" } }, { "InternalComputationValueType", { "float" } } });
// Compose fails and returns false
EXPECT_FALSE(baseBlueprint->ComposeWith(conflictingBlueprint0));
//baseBlueprint should not have been altered by a failing compose operation
EXPECT_STREQ("3", baseBlueprint->GetComponent("Component1")["Dimensionality"][0].c_str());
EXPECT_EQ(0,baseBlueprint->GetComponent("Component1").count("InternalComputationValueType"));
}
//TEST_F( BlueprintTest, WriteBlueprint )
//{
......
Supports Markdown
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