From 6a4b3f18305468191f31984d6a4e15030f2f0974 Mon Sep 17 00:00:00 2001 From: Jan Travnicek <Jan.Travnicek@fit.cvut.cz> Date: Mon, 9 Oct 2017 22:10:03 +0200 Subject: [PATCH] simpler param names handling in algo registration --- .../src/registration/AlgoRegistration.hpp | 23 +++++++++++++------ 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/alib2common/src/registration/AlgoRegistration.hpp b/alib2common/src/registration/AlgoRegistration.hpp index 87054f6771..23a4927288 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 ) { } }; -- GitLab