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

STYLE: uncrustify

parent e4089f81
...@@ -27,11 +27,10 @@ ...@@ -27,11 +27,10 @@
namespace selx namespace selx
{ {
class Blueprint class Blueprint
{ {
public: public:
typedef std::string ParameterKeyType; typedef std::string ParameterKeyType;
typedef std::vector< std::string > ParameterValueType; typedef std::vector< std::string > ParameterValueType;
typedef std::map< ParameterKeyType, ParameterValueType > ParameterMapType; typedef std::map< ParameterKeyType, ParameterValueType > ParameterMapType;
...@@ -39,18 +38,18 @@ public: ...@@ -39,18 +38,18 @@ public:
typedef std::vector< ComponentNameType > ComponentNamesType; typedef std::vector< ComponentNameType > ComponentNamesType;
Blueprint( void ); Blueprint( void );
Blueprint(const Blueprint& other); // copyable Blueprint( const Blueprint & other ); // copyable
Blueprint& operator=(const Blueprint& other); // Blueprint & operator=( const Blueprint & other ); //
//Blueprint(Blueprint&&); //Blueprint(Blueprint&&);
~Blueprint( void ); ~Blueprint( void );
bool SetComponent( ComponentNameType, ParameterMapType parameterMap ); bool SetComponent( ComponentNameType, ParameterMapType parameterMap );
ParameterMapType GetComponent( ComponentNameType componentName ) const; ParameterMapType GetComponent( ComponentNameType componentName ) const;
bool DeleteComponent( ComponentNameType componentName ); bool DeleteComponent( ComponentNameType componentName );
bool ComponentExists( ComponentNameType componentName ) const; bool ComponentExists( ComponentNameType componentName ) const;
// Returns a vector of the all Component names in the graph. // Returns a vector of the all Component names in the graph.
...@@ -67,21 +66,20 @@ public: ...@@ -67,21 +66,20 @@ public:
//std::unique_ptr<Blueprint> Clone(Blueprint const &other ); //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. // "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); bool ComposeWith( std::unique_ptr< Blueprint > const & other );
// Returns a vector of the Component names at the incoming direction // Returns a vector of the Component names at the incoming direction
ComponentNamesType GetInputNames( const ComponentNameType name ) const; ComponentNamesType GetInputNames( const ComponentNameType name ) const;
// Returns a vector of the Component names at the outgoing direction // Returns a vector of the Component names at the outgoing direction
ComponentNamesType GetOutputNames( const ComponentNameType name ) const; ComponentNamesType GetOutputNames( const ComponentNameType name ) const;
void Write( const std::string filename ); void Write( const std::string filename );
private: private:
struct BlueprintImpl; struct BlueprintImpl;
std::unique_ptr< BlueprintImpl > m_Pimple; std::unique_ptr< BlueprintImpl > m_Pimple;
}; };
} }
......
...@@ -20,30 +20,32 @@ ...@@ -20,30 +20,32 @@
#include "selxBlueprint.h" #include "selxBlueprint.h"
#include "selxBlueprintImpl.h" #include "selxBlueprintImpl.h"
namespace selx { namespace selx
{
Blueprint Blueprint
::Blueprint( void ) : m_Pimple( new Blueprint::BlueprintImpl ) {}; ::Blueprint( void ) : m_Pimple( new Blueprint::BlueprintImpl ) {}
Blueprint::Blueprint(const Blueprint& other) Blueprint::Blueprint( const Blueprint & other )
: m_Pimple(new BlueprintImpl(*other.m_Pimple)) : m_Pimple( new BlueprintImpl( *other.m_Pimple ) )
{} {}
Blueprint& Blueprint::operator=(const Blueprint& other) { Blueprint &
if (this != &other) { Blueprint::operator=( const Blueprint & other )
m_Pimple.reset(new BlueprintImpl(*other.m_Pimple)); {
if( this != &other )
{
m_Pimple.reset( new BlueprintImpl( *other.m_Pimple ) );
} }
return *this; return *this;
} }
//Blueprint //Blueprint
//::Blueprint(Blueprint&&) = default; //::Blueprint(Blueprint&&) = default;
Blueprint Blueprint
::~Blueprint( void ) = default; ::~Blueprint( void ) = default;
bool bool
Blueprint Blueprint
::SetComponent( ComponentNameType name, ParameterMapType parameterMap ) ::SetComponent( ComponentNameType name, ParameterMapType parameterMap )
...@@ -114,18 +116,19 @@ Blueprint ...@@ -114,18 +116,19 @@ Blueprint
return this->m_Pimple->ConnectionExists( upstream, downstream ); return this->m_Pimple->ConnectionExists( upstream, downstream );
} }
//std::unique_ptr<Blueprint> //std::unique_ptr<Blueprint>
//Blueprint //Blueprint
//::Clone(Blueprint const &other) //::Clone(Blueprint const &other)
//{ //{
// return std::make_unique<Blueprint>(other); // return std::make_unique<Blueprint>(other);
//} //}
bool bool
Blueprint Blueprint
::ComposeWith(std::unique_ptr<Blueprint> const &other ) ::ComposeWith( std::unique_ptr< Blueprint > const & other )
{ {
return this->m_Pimple->ComposeWith(other); return this->m_Pimple->ComposeWith( other );
} }
...@@ -151,5 +154,4 @@ Blueprint ...@@ -151,5 +154,4 @@ Blueprint
{ {
this->m_Pimple->Write( filename ); this->m_Pimple->Write( filename );
} }
} // namespace selx
} // namespace selx
\ No newline at end of file
...@@ -23,15 +23,14 @@ ...@@ -23,15 +23,14 @@
namespace selx namespace selx
{ {
// Declared outside of the class body, so it is a free function // Declared outside of the class body, so it is a free function
std::ostream & std::ostream &
operator<<(std::ostream & out, const Blueprint::ParameterMapType & val) operator<<( std::ostream & out, const Blueprint::ParameterMapType & val )
{ {
for (auto const & mapPair : val) for( auto const & mapPair : val )
{ {
out << mapPair.first << " : [ "; out << mapPair.first << " : [ ";
for (auto const & value : mapPair.second) for( auto const & value : mapPair.second )
{ {
out << value << " "; out << value << " ";
} }
...@@ -46,11 +45,11 @@ class vertex_label_writer ...@@ -46,11 +45,11 @@ class vertex_label_writer
{ {
public: public:
vertex_label_writer(NameType _name, ParameterMapType _parameterMap) : name(_name), parameterMap(_parameterMap) {} vertex_label_writer( NameType _name, ParameterMapType _parameterMap ) : name( _name ), parameterMap( _parameterMap ) {}
template< class VertexOrEdge > template< class VertexOrEdge >
void operator()(std::ostream & out, const VertexOrEdge & v) const void operator()( std::ostream & out, const VertexOrEdge & v ) const
{ {
out << "[label=\"" << name[v] << "\n" << parameterMap[v] << "\"]"; out << "[label=\"" << name[ v ] << "\n" << parameterMap[ v ] << "\"]";
} }
...@@ -62,9 +61,9 @@ private: ...@@ -62,9 +61,9 @@ private:
template< class NameType, class ParameterMapType > template< class NameType, class ParameterMapType >
inline vertex_label_writer< NameType, ParameterMapType > inline vertex_label_writer< NameType, ParameterMapType >
make_vertex_label_writer(NameType n, ParameterMapType p) make_vertex_label_writer( NameType n, ParameterMapType p )
{ {
return vertex_label_writer< NameType, ParameterMapType >(n, p); return vertex_label_writer< NameType, ParameterMapType >( n, p );
} }
...@@ -73,11 +72,11 @@ class edge_label_writer ...@@ -73,11 +72,11 @@ class edge_label_writer
{ {
public: public:
edge_label_writer(ParameterMapType _parameterMap) : parameterMap(_parameterMap) {} edge_label_writer( ParameterMapType _parameterMap ) : parameterMap( _parameterMap ) {}
template< class VertexOrEdge > template< class VertexOrEdge >
void operator()(std::ostream & out, const VertexOrEdge & v) const void operator()( std::ostream & out, const VertexOrEdge & v ) const
{ {
out << "[label=\"" << parameterMap[v] << "\"]"; out << "[label=\"" << parameterMap[ v ] << "\"]";
} }
...@@ -88,9 +87,9 @@ private: ...@@ -88,9 +87,9 @@ private:
template< class ParameterMapType > template< class ParameterMapType >
inline edge_label_writer< ParameterMapType > inline edge_label_writer< ParameterMapType >
make_edge_label_writer(ParameterMapType p) make_edge_label_writer( ParameterMapType p )
{ {
return edge_label_writer< ParameterMapType >(p); return edge_label_writer< ParameterMapType >( p );
} }
...@@ -109,7 +108,7 @@ Blueprint::BlueprintImpl ...@@ -109,7 +108,7 @@ Blueprint::BlueprintImpl
} }
} }
Blueprint::ParameterMapType Blueprint::ParameterMapType
Blueprint::BlueprintImpl Blueprint::BlueprintImpl
::GetComponent( ComponentNameType name ) const ::GetComponent( ComponentNameType name ) const
...@@ -134,10 +133,11 @@ Blueprint::BlueprintImpl ...@@ -134,10 +133,11 @@ Blueprint::BlueprintImpl
this->m_Graph.remove_vertex( name ); this->m_Graph.remove_vertex( name );
return true; return true;
} }
return false; return false;
} }
Blueprint::ComponentNamesType Blueprint::ComponentNamesType
Blueprint::BlueprintImpl Blueprint::BlueprintImpl
::GetComponentNames( void ) const ::GetComponentNames( void ) const
...@@ -159,7 +159,7 @@ Blueprint::BlueprintImpl ...@@ -159,7 +159,7 @@ Blueprint::BlueprintImpl
{ {
return false; return false;
} }
if( !this->ConnectionExists( upstream, downstream ) ) if( !this->ConnectionExists( upstream, downstream ) )
{ {
boost::add_edge_by_label( upstream, downstream, { parameterMap }, this->m_Graph ); boost::add_edge_by_label( upstream, downstream, { parameterMap }, this->m_Graph );
...@@ -168,7 +168,7 @@ Blueprint::BlueprintImpl ...@@ -168,7 +168,7 @@ Blueprint::BlueprintImpl
{ {
this->m_Graph[ this->GetConnectionIndex( upstream, downstream ) ].parameterMap = parameterMap; this->m_Graph[ this->GetConnectionIndex( upstream, downstream ) ].parameterMap = parameterMap;
} }
return true; return true;
} }
...@@ -219,44 +219,45 @@ Blueprint::BlueprintImpl ...@@ -219,44 +219,45 @@ Blueprint::BlueprintImpl
return boost::edge_by_label( upstream, downstream, this->m_Graph ).second; return boost::edge_by_label( upstream, downstream, this->m_Graph ).second;
} }
bool
bool
Blueprint::BlueprintImpl Blueprint::BlueprintImpl
::ComposeWith(std::unique_ptr<Blueprint> const &other) ::ComposeWith( std::unique_ptr< Blueprint > const & other )
{ {
// Make a backup of the current blueprint status in case composition fails // Make a backup of the current blueprint status in case composition fails
GraphType graph_backup = GraphType(this->m_Graph); GraphType graph_backup = GraphType( this->m_Graph );
// Copy-in all components (Nodes) // Copy-in all components (Nodes)
for (auto const & componentName : other->GetComponentNames()) for( auto const & componentName : other->GetComponentNames() )
{ {
// Does other blueprint use component with a name that already exists? // Does other blueprint use component with a name that already exists?
if (this->ComponentExists(componentName)) if( this->ComponentExists( componentName ) )
{ {
// Component exists, check if properties can be merged // Component exists, check if properties can be merged
auto ownProperties = this->GetComponent(componentName); auto ownProperties = this->GetComponent( componentName );
auto othersProperties = other->GetComponent(componentName); auto othersProperties = other->GetComponent( componentName );
for (auto const & othersEntry : othersProperties) for( auto const & othersEntry : othersProperties )
{ {
// Does other use a property key that already exists in this component? // Does other use a property key that already exists in this component?
if (ownProperties.count(othersEntry.first)) if( ownProperties.count( othersEntry.first ) )
{ {
auto && ownValues = ownProperties[othersEntry.first]; auto && ownValues = ownProperties[ othersEntry.first ];
auto && otherValues = othersEntry.second; auto && otherValues = othersEntry.second;
// Are the property values equal? // Are the property values equal?
if (ownValues.size() != otherValues.size()) if( ownValues.size() != otherValues.size() )
{ {
// No, based on the number of values we see that it is different. Blueprints cannot be Composed // No, based on the number of values we see that it is different. Blueprints cannot be Composed
this->m_Graph = graph_backup; this->m_Graph = graph_backup;
return false; return false;
} }
else else
{ {
ParameterValueType::const_iterator ownValue; ParameterValueType::const_iterator ownValue;
ParameterValueType::const_iterator otherValue; ParameterValueType::const_iterator otherValue;
for (ownValue = ownValues.begin(), otherValue = otherValues.begin(); ownValue != ownValues.end(); ++ownValue, ++otherValue) for( ownValue = ownValues.begin(), otherValue = otherValues.begin(); ownValue != ownValues.end(); ++ownValue, ++otherValue )
{ {
if (*otherValue != *ownValue) if( *otherValue != *ownValue )
{ {
// No, at least one value is different. Blueprints cannot be Composed // No, at least one value is different. Blueprints cannot be Composed
this->m_Graph = graph_backup; this->m_Graph = graph_backup;
...@@ -268,41 +269,39 @@ Blueprint::BlueprintImpl ...@@ -268,41 +269,39 @@ Blueprint::BlueprintImpl
else else
{ {
// Property key doesn't exist yet, add entry to this component // Property key doesn't exist yet, add entry to this component
auto ownProperties = this->GetComponent(componentName); auto ownProperties = this->GetComponent( componentName );
ownProperties[othersEntry.first] = othersEntry.second; ownProperties[ othersEntry.first ] = othersEntry.second;
this->SetComponent(componentName, ownProperties); this->SetComponent( componentName, ownProperties );
} }
} }
} }
else else
{ {
// Create Component copying properties of other // Create Component copying properties of other
this->SetComponent(componentName, other->GetComponent(componentName)); this->SetComponent( componentName, other->GetComponent( componentName ) );
} }
} }
// Copy-in all connections (Edges) // Copy-in all connections (Edges)
for (auto const & componentName : other->GetComponentNames()) for( auto const & componentName : other->GetComponentNames() )
{ {
for( auto incomingName : other->GetInputNames(componentName)) for( auto incomingName : other->GetInputNames( componentName ) )
{ {
// Does other blueprint have a connection that already exists? // Does other blueprint have a connection that already exists?
if (this->ConnectionExists(incomingName, componentName)) if( this->ConnectionExists( incomingName, componentName ) )
{ {
// Connection exists, check if properties can be merged // Connection exists, check if properties can be merged
auto ownProperties = this->GetConnection(incomingName, componentName); auto ownProperties = this->GetConnection( incomingName, componentName );
auto othersProperties = other->GetConnection(incomingName, componentName); auto othersProperties = other->GetConnection( incomingName, componentName );
for (auto const & othersEntry : othersProperties) for( auto const & othersEntry : othersProperties )
{ {
// Does other use a property key that already exists in this component? // Does other use a property key that already exists in this component?
if (ownProperties.count(othersEntry.first)) if( ownProperties.count( othersEntry.first ) )
{ {
auto && ownValues = ownProperties[othersEntry.first]; auto && ownValues = ownProperties[ othersEntry.first ];
auto && otherValues = othersEntry.second; auto && otherValues = othersEntry.second;
// Are the property values equal? // Are the property values equal?
if (ownValues.size() != otherValues.size()) if( ownValues.size() != otherValues.size() )
{ {
// No, based on the number of values we see that it is different. Blueprints cannot be Composed // No, based on the number of values we see that it is different. Blueprints cannot be Composed
this->m_Graph = graph_backup; this->m_Graph = graph_backup;
...@@ -312,9 +311,9 @@ Blueprint::BlueprintImpl ...@@ -312,9 +311,9 @@ Blueprint::BlueprintImpl
{ {
ParameterValueType::const_iterator ownValue; ParameterValueType::const_iterator ownValue;
ParameterValueType::const_iterator otherValue; ParameterValueType::const_iterator otherValue;
for (ownValue = ownValues.begin(), otherValue = otherValues.begin(); ownValue != ownValues.end(); ++ownValue, ++otherValue) for( ownValue = ownValues.begin(), otherValue = otherValues.begin(); ownValue != ownValues.end(); ++ownValue, ++otherValue )
{ {
if (*otherValue != *ownValue) if( *otherValue != *ownValue )
{ {
// No, at least one value is different. Blueprints cannot be Composed // No, at least one value is different. Blueprints cannot be Composed
this->m_Graph = graph_backup; this->m_Graph = graph_backup;
...@@ -326,19 +325,18 @@ Blueprint::BlueprintImpl ...@@ -326,19 +325,18 @@ Blueprint::BlueprintImpl
else else
{ {
// Property key doesn't exist yet, add entry to this component // Property key doesn't exist yet, add entry to this component
auto ownProperties = this->GetConnection(incomingName, componentName); auto ownProperties = this->GetConnection( incomingName, componentName );
ownProperties[othersEntry.first] = othersEntry.second; ownProperties[ othersEntry.first ] = othersEntry.second;
this->SetConnection(incomingName, componentName, ownProperties); this->SetConnection( incomingName, componentName, ownProperties );
} }
} }
} }
else else
{ {
// Create Component copying properties of other // Create Component copying properties of other
this->SetConnection(incomingName, componentName, other->GetConnection(incomingName, componentName)); this->SetConnection( incomingName, componentName, other->GetConnection( incomingName, componentName ) );
} }
} }
} }
return true; return true;
...@@ -397,9 +395,8 @@ Blueprint::BlueprintImpl ...@@ -397,9 +395,8 @@ Blueprint::BlueprintImpl
{ {
std::ofstream dotfile( filename.c_str() ); std::ofstream dotfile( filename.c_str() );
boost::write_graphviz( dotfile, this->m_Graph, boost::write_graphviz( dotfile, this->m_Graph,
make_vertex_label_writer( boost::get( &ComponentPropertyType::name, this->m_Graph ), make_vertex_label_writer( boost::get( &ComponentPropertyType::name, this->m_Graph ),
boost::get( &ComponentPropertyType::parameterMap, this->m_Graph ) ), boost::get( &ComponentPropertyType::parameterMap, this->m_Graph ) ),
make_edge_label_writer( boost::get( &ConnectionPropertyType::parameterMap, this->m_Graph ) ) ); make_edge_label_writer( boost::get( &ConnectionPropertyType::parameterMap, this->m_Graph ) ) );
} }
} // namespace selx } // namespace selx
...@@ -29,15 +29,15 @@ ...@@ -29,15 +29,15 @@
#include "selxBlueprint.h" #include "selxBlueprint.h"
namespace selx { namespace selx
{
struct Blueprint::BlueprintImpl { struct Blueprint::BlueprintImpl
{
// Component parameter map that sits on a node in the graph // Component parameter map that sits on a node in the graph
// and holds component configuration settings // and holds component configuration settings
struct ComponentPropertyType struct ComponentPropertyType
{ {
ComponentPropertyType(ComponentNameType name = "", ParameterMapType parameterMap = {}) : name(name), parameterMap(parameterMap) {} ComponentPropertyType( ComponentNameType name = "", ParameterMapType parameterMap = {} ) : name( name ), parameterMap( parameterMap ) {}
ComponentNameType name; ComponentNameType name;
ParameterMapType parameterMap; ParameterMapType parameterMap;