Commit 942a2001 authored by Floris Berendsen's avatar Floris Berendsen
Browse files

WIP: end of the day

parent 38fd0b1b
...@@ -53,6 +53,8 @@ public: ...@@ -53,6 +53,8 @@ public:
typedef std::map< ParameterKeyType, ParameterValueType > CriteriaType; typedef std::map< ParameterKeyType, ParameterValueType > CriteriaType;
typedef std::pair< ParameterKeyType, ParameterValueType > CriterionType; typedef std::pair< ParameterKeyType, ParameterValueType > CriterionType;
typedef std::map< std::string, std::string > InterfaceCriteriaType;
enum interfaceStatus { success, noaccepter, noprovider }; enum interfaceStatus { success, noaccepter, noprovider };
virtual interfaceStatus AcceptConnectionFrom( const char *, ComponentBase * ) = 0; virtual interfaceStatus AcceptConnectionFrom( const char *, ComponentBase * ) = 0;
...@@ -73,6 +75,11 @@ protected: ...@@ -73,6 +75,11 @@ protected:
virtual bool HasProvidingInterface( const char * ) = 0; virtual bool HasProvidingInterface( const char * ) = 0;
//experimental:
virtual unsigned int CountAcceptingInterfaces(const InterfaceCriteriaType) = 0;
virtual unsigned int CountProvidingInterfaces(const InterfaceCriteriaType) = 0;
ComponentBase() {} ComponentBase() {}
virtual ~ComponentBase() {} virtual ~ComponentBase() {}
}; };
......
...@@ -93,6 +93,20 @@ protected: ...@@ -93,6 +93,20 @@ protected:
//{ //{
//}; //};
// helper class for SuperElastixComponent::CountAcceptingInterfaces and SuperElastixComponent::CountProvidingInterfaces to loop over a set of interfaces
template <typename ... RestInterfaces>
struct CountInterfaces
{
static unsigned int Count(const ComponentBase::InterfaceCriteriaType) { return 0 };
};
template < typename FirstInterface, typename ... RestInterfaces>
struct CountInterfaces< FirstInterface, RestInterfaces ... >
{
static unsigned int Count(const ComponentBase::InterfaceCriteriaType);
};
template< typename AcceptingInterfaces, typename ProvidingInterfaces > template< typename AcceptingInterfaces, typename ProvidingInterfaces >
class SuperElastixComponent : public AcceptingInterfaces, public ProvidingInterfaces, public ComponentBase class SuperElastixComponent : public AcceptingInterfaces, public ProvidingInterfaces, public ComponentBase
{ {
...@@ -107,6 +121,11 @@ protected: ...@@ -107,6 +121,11 @@ protected:
virtual bool HasAcceptingInterface( const char * ); virtual bool HasAcceptingInterface( const char * );
virtual bool HasProvidingInterface( const char * ); virtual bool HasProvidingInterface( const char * );
//experimental
virtual unsigned int CountAcceptingInterfaces(const ComponentBase::InterfaceCriteriaType);
virtual unsigned int CountProvidingInterfaces(const ComponentBase::InterfaceCriteriaType);
}; };
} // end namespace selx } // end namespace selx
......
...@@ -72,6 +72,23 @@ SuperElastixComponent< AcceptingInterfaces, ProvidingInterfaces >::HasProvidingI ...@@ -72,6 +72,23 @@ SuperElastixComponent< AcceptingInterfaces, ProvidingInterfaces >::HasProvidingI
return ProvidingInterfaces::HasInterface( interfacename ); return ProvidingInterfaces::HasInterface( interfacename );
} }
template< typename AcceptingInterfaces, typename ProvidingInterfaces >
unsigned int
SuperElastixComponent< AcceptingInterfaces, ProvidingInterfaces >::CountAcceptingInterfaces(const ComponentBase::InterfaceCriteriaType interfaceCriteria)
{
//return AcceptingInterfaces::HasInterface(interfacename);
return CountInterfaces< AcceptingInterfaces >::Count(interfaceCriteria);
}
template< typename AcceptingInterfaces, typename ProvidingInterfaces >
unsigned int
SuperElastixComponent< AcceptingInterfaces, ProvidingInterfaces >::CountProvidingInterfaces(const ComponentBase::InterfaceCriteriaType interfaceCriteria)
{
//return ProvidingInterfaces::HasInterface(interfacename);
return CountInterfaces< ProvidingInterfaces>::Count(interfaceCriteria);
}
////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////
template< typename FirstInterface, typename ... RestInterfaces > template< typename FirstInterface, typename ... RestInterfaces >
...@@ -118,7 +135,9 @@ bool ...@@ -118,7 +135,9 @@ bool
Accepting< FirstInterface, RestInterfaces ... >::HasInterface( const char * interfacename ) Accepting< FirstInterface, RestInterfaces ... >::HasInterface( const char * interfacename )
{ {
//TODO: check on interface template arguments as well //TODO: check on interface template arguments as well
if( InterfaceName< InterfaceAcceptor< FirstInterface >>::Get() == std::string( interfacename ) ) auto interfaceProperies = Properties< FirstInterface >::Get();
if (interfaceProperies["Name"] == std::string(interfacename))
{ {
return true; return true;
} }
...@@ -131,12 +150,34 @@ bool ...@@ -131,12 +150,34 @@ bool
Providing< FirstInterface, RestInterfaces ... >::HasInterface( const char * interfacename ) Providing< FirstInterface, RestInterfaces ... >::HasInterface( const char * interfacename )
{ {
//TODO: check on interface template arguments as well //TODO: check on interface template arguments as well
if( InterfaceName< FirstInterface >::Get() == std::string( interfacename ) ) auto interfaceProperies = Properties< FirstInterface >::Get();
if (interfaceProperies["Name"] == std::string(interfacename))
{ {
return true; return true;
} }
return Providing< RestInterfaces ... >::HasInterface( interfacename ); return Providing< RestInterfaces ... >::HasInterface( interfacename );
} }
template <typename FirstInterface, typename ... RestInterfaces>
unsigned int CountInterfaces<FirstInterface, RestInterfaces ...>::Count(const ComponentBase::InterfaceCriteriaType interfaceCriteria)
{
auto interfaceProperies = Properties< FirstInterface >::Get();
for (const auto keyAndValue : interfaceCriteria)
{
auto && key = keyAndValue.first;
auto && value = keyAndValue.second;
if (interfaceProperies.count(key) != 1 || interfaceProperies[key].compare(value)!=0 )
{
// as soon as any of the criteria fails we break the loop and test the RestInterfaces
return CountInterfaces< RestInterfaces ... >::Count(interfaceCriteria);
}
}
// if all criteria are met for this Interface we add 1 to the count and continue with the RestInterfaces
return 1 + CountInterfaces< RestInterfaces ... >::Count(interfaceCriteria);
};
} // end namespace selx } // end namespace selx
#endif // #define selxSuperElastixComponent_hxx #endif // #define selxSuperElastixComponent_hxx
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