Commit 33870b69 authored by Floris Berendsen's avatar Floris Berendsen
Browse files

ENH: WIP: added methods and helper Classes to CountInterfaces

parent 942a2001
...@@ -76,9 +76,9 @@ protected: ...@@ -76,9 +76,9 @@ protected:
virtual bool HasProvidingInterface( const char * ) = 0; virtual bool HasProvidingInterface( const char * ) = 0;
//experimental: //experimental:
virtual unsigned int CountAcceptingInterfaces(const InterfaceCriteriaType) = 0; //virtual unsigned int CountAcceptingInterfaces(const InterfaceCriteriaType) = 0;
virtual unsigned int CountProvidingInterfaces(const InterfaceCriteriaType) = 0; //virtual unsigned int CountProvidingInterfaces(const InterfaceCriteriaType) = 0;
ComponentBase() {} ComponentBase() {}
virtual ~ComponentBase() {} virtual ~ComponentBase() {}
......
...@@ -49,7 +49,7 @@ template< typename ... RestInterfaces > ...@@ -49,7 +49,7 @@ template< typename ... RestInterfaces >
class Accepting class Accepting
{ {
public: public:
static unsigned int CountMeetsCriteria(const ComponentBase::InterfaceCriteriaType) { return 0; }
ComponentBase::interfaceStatus ConnectFromImpl( const char *, ComponentBase * ) { return ComponentBase::interfaceStatus::noaccepter; } //no interface called interfacename ; ComponentBase::interfaceStatus ConnectFromImpl( const char *, ComponentBase * ) { return ComponentBase::interfaceStatus::noaccepter; } //no interface called interfacename ;
int ConnectFromImpl( ComponentBase * ) { return 0; } //Empty RestInterfaces does 0 successful connects ; int ConnectFromImpl( ComponentBase * ) { return 0; } //Empty RestInterfaces does 0 successful connects ;
...@@ -62,7 +62,7 @@ template< typename FirstInterface, typename ... RestInterfaces > ...@@ -62,7 +62,7 @@ template< typename FirstInterface, typename ... RestInterfaces >
class Accepting< FirstInterface, RestInterfaces ... > : public InterfaceAcceptor< FirstInterface >, public Accepting< RestInterfaces ... > class Accepting< FirstInterface, RestInterfaces ... > : public InterfaceAcceptor< FirstInterface >, public Accepting< RestInterfaces ... >
{ {
public: public:
static unsigned int CountMeetsCriteria(const ComponentBase::InterfaceCriteriaType);
ComponentBase::interfaceStatus ConnectFromImpl( const char *, ComponentBase * ); ComponentBase::interfaceStatus ConnectFromImpl( const char *, ComponentBase * );
int ConnectFromImpl( ComponentBase * ); int ConnectFromImpl( ComponentBase * );
...@@ -75,6 +75,8 @@ protected: ...@@ -75,6 +75,8 @@ protected:
template< typename ... RestInterfaces > template< typename ... RestInterfaces >
class Providing class Providing
{ {
public:
static unsigned int CountMeetsCriteria(const ComponentBase::InterfaceCriteriaType) { return 0; }
protected: protected:
bool HasInterface( const char * ) { return false; } bool HasInterface( const char * ) { return false; }
...@@ -83,6 +85,8 @@ protected: ...@@ -83,6 +85,8 @@ protected:
template< typename FirstInterface, typename ... RestInterfaces > template< typename FirstInterface, typename ... RestInterfaces >
class Providing< FirstInterface, RestInterfaces ... > : public FirstInterface, public Providing< RestInterfaces ... > class Providing< FirstInterface, RestInterfaces ... > : public FirstInterface, public Providing< RestInterfaces ... >
{ {
public:
static unsigned int CountMeetsCriteria(const ComponentBase::InterfaceCriteriaType);
protected: protected:
bool HasInterface( const char * ); bool HasInterface( const char * );
...@@ -95,23 +99,29 @@ protected: ...@@ -95,23 +99,29 @@ protected:
// helper class for SuperElastixComponent::CountAcceptingInterfaces and SuperElastixComponent::CountProvidingInterfaces to loop over a set of interfaces // helper class for SuperElastixComponent::CountAcceptingInterfaces and SuperElastixComponent::CountProvidingInterfaces to loop over a set of interfaces
template <typename ... RestInterfaces> template <typename ... Interfaces>
struct CountInterfaces struct Count;
template <>
struct Count<>
{ {
static unsigned int Count(const ComponentBase::InterfaceCriteriaType) { return 0 }; static unsigned int MeetsCriteria(const ComponentBase::InterfaceCriteriaType) { return 0; };
}; };
template < typename FirstInterface, typename ... RestInterfaces> template < typename FirstInterface, typename ... RestInterfaces>
struct CountInterfaces< FirstInterface, RestInterfaces ... > struct Count< FirstInterface, RestInterfaces ... >
{ {
static unsigned int Count(const ComponentBase::InterfaceCriteriaType); static unsigned int MeetsCriteria(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
{ {
public: public:
using AcceptingInterfacesTypeList = AcceptingInterfaces;
using ProvidingInterfacesTypeList = ProvidingInterfaces;
virtual interfaceStatus AcceptConnectionFrom( const char *, ComponentBase * ); virtual interfaceStatus AcceptConnectionFrom( const char *, ComponentBase * );
virtual int AcceptConnectionFrom( ComponentBase * ); virtual int AcceptConnectionFrom( ComponentBase * );
...@@ -123,8 +133,9 @@ protected: ...@@ -123,8 +133,9 @@ protected:
virtual bool HasProvidingInterface( const char * ); virtual bool HasProvidingInterface( const char * );
//experimental //experimental
virtual unsigned int CountAcceptingInterfaces(const ComponentBase::InterfaceCriteriaType); //SuperElastixComponentType::AcceptingInterfacesTypeList::CountMeetsCriteria(InterfaceCriteriaType);
virtual unsigned int CountProvidingInterfaces(const ComponentBase::InterfaceCriteriaType); //virtual unsigned int CountAcceptingInterfaces(const ComponentBase::InterfaceCriteriaType);
//virtual unsigned int CountProvidingInterfaces(const ComponentBase::InterfaceCriteriaType);
}; };
} // end namespace selx } // end namespace selx
......
...@@ -72,23 +72,6 @@ SuperElastixComponent< AcceptingInterfaces, ProvidingInterfaces >::HasProvidingI ...@@ -72,23 +72,6 @@ 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 >
...@@ -159,8 +142,25 @@ Providing< FirstInterface, RestInterfaces ... >::HasInterface( const char * inte ...@@ -159,8 +142,25 @@ Providing< FirstInterface, RestInterfaces ... >::HasInterface( const char * inte
return Providing< RestInterfaces ... >::HasInterface( interfacename ); return Providing< RestInterfaces ... >::HasInterface( interfacename );
} }
template< typename FirstInterface, typename ... RestInterfaces >
unsigned int
Accepting< FirstInterface, RestInterfaces ... >::CountMeetsCriteria(const ComponentBase::InterfaceCriteriaType interfaceCriteria)
{
return Count<FirstInterface, RestInterfaces ... >::MeetsCriteria(interfaceCriteria);
}
template< typename FirstInterface, typename ... RestInterfaces >
unsigned int
Providing< FirstInterface, RestInterfaces ... >::CountMeetsCriteria(const ComponentBase::InterfaceCriteriaType interfaceCriteria)
{
return Count<FirstInterface, RestInterfaces ... >::MeetsCriteria(interfaceCriteria);
}
template <typename FirstInterface, typename ... RestInterfaces> template <typename FirstInterface, typename ... RestInterfaces>
unsigned int CountInterfaces<FirstInterface, RestInterfaces ...>::Count(const ComponentBase::InterfaceCriteriaType interfaceCriteria) unsigned int Count<FirstInterface, RestInterfaces ...>::MeetsCriteria(const ComponentBase::InterfaceCriteriaType interfaceCriteria)
{ {
auto interfaceProperies = Properties< FirstInterface >::Get(); auto interfaceProperies = Properties< FirstInterface >::Get();
for (const auto keyAndValue : interfaceCriteria) for (const auto keyAndValue : interfaceCriteria)
...@@ -170,11 +170,11 @@ unsigned int CountInterfaces<FirstInterface, RestInterfaces ...>::Count(const Co ...@@ -170,11 +170,11 @@ unsigned int CountInterfaces<FirstInterface, RestInterfaces ...>::Count(const Co
if (interfaceProperies.count(key) != 1 || interfaceProperies[key].compare(value)!=0 ) 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 // as soon as any of the criteria fails we break the loop and test the RestInterfaces
return CountInterfaces< RestInterfaces ... >::Count(interfaceCriteria); return Count< RestInterfaces ... >::MeetsCriteria(interfaceCriteria);
} }
} }
// if all criteria are met for this Interface we add 1 to the count and continue with the RestInterfaces // 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); return 1 + Count< RestInterfaces ... >::MeetsCriteria(interfaceCriteria);
}; };
......
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