diff --git a/alib2common/src/registration/AlgoRegistration.hpp b/alib2common/src/registration/AlgoRegistration.hpp index 87054f6771b61e1197cc682f577f76d71d09d941..23a49272886641d65c93053e46fc7796400350fb 100644 --- a/alib2common/src/registration/AlgoRegistration.hpp +++ b/alib2common/src/registration/AlgoRegistration.hpp @@ -17,22 +17,31 @@ public: } }; +class AlgoRegister { +protected: + template < size_t ParameterTypesNumber, class ... ParamNames, typename std::enable_if < sizeof ... ( ParamNames ) <= ParameterTypesNumber >::type * = nullptr > + static std::array < std::string, ParameterTypesNumber > generateNames ( ParamNames ... paramNames ) { + std::array < std::string, ParameterTypesNumber > parameterNames = { { paramNames ... } }; + for ( unsigned i = sizeof ... ( ParamNames ); i < ParameterTypesNumber; ++i ) + parameterNames [ i ] = "arg" + ext::to_string ( i ); + + return parameterNames; + } +}; + template < class Algorithm, class ReturnType, class ... ParameterTypes > -class AbstractRegister { +class AbstractRegister : public AlgoRegister { public: - template < class ... ParamNames, typename std::enable_if < sizeof ... ( ParamNames ) <= sizeof ... ( ParameterTypes ) >::type * = nullptr > + template < class ... ParamNames > AbstractRegister ( ReturnType ( * callback ) ( ParameterTypes ... ), abstraction::AlgorithmCategories::AlgorithmCategory category, ParamNames ... paramNames ) { registration::NormalizationRegister < ReturnType > ( ); - std::array < std::string, sizeof ... ( ParameterTypes ) > parameterNames = { { paramNames ... } }; - for ( unsigned i = sizeof ... ( ParamNames ); i < sizeof ... ( ParameterTypes ); ++i ) { - parameterNames [ i ] = "arg" + ext::to_string ( i ); - } + std::array < std::string, sizeof ... ( ParameterTypes ) > parameterNames = generateNames < sizeof ... ( ParameterTypes ) > ( paramNames ... ); abstraction::AlgorithmRegistry::registerAlgorithm < Algorithm, ReturnType, ParameterTypes ... > ( callback, category, std::move ( parameterNames ) ); } - template < class ... ParamNames, typename std::enable_if < sizeof ... ( ParamNames ) <= sizeof ... ( ParameterTypes ) >::type * = nullptr > + template < class ... ParamNames > AbstractRegister ( ReturnType ( * callback ) ( ParameterTypes ... ) ) : AbstractRegister ( callback, abstraction::AlgorithmCategories::AlgorithmCategory::DEFAULT ) { } };