diff --git a/alib2cli/test-src/cli/CliTest.cpp b/alib2cli/test-src/cli/CliTest.cpp index c848b39da577aad2df88523597502d1eb97efaec..e236bb2e058926026a0d0ba2ac6eb70eb5075253 100644 --- a/alib2cli/test-src/cli/CliTest.cpp +++ b/alib2cli/test-src/cli/CliTest.cpp @@ -9,6 +9,7 @@ #include <sys/stat.h> #include <abstraction/AlgorithmRegistry.hpp> +#include <registration/AlgoRegistration.hpp> CPPUNIT_TEST_SUITE_NAMED_REGISTRATION ( CliTest, "common" ); CPPUNIT_TEST_SUITE_REGISTRATION ( CliTest ); @@ -278,16 +279,28 @@ public: return m_base + value; } + int base ( ) { + return m_base; + } + static Foo make_foo ( int base ) { return Foo ( base ); } }; +namespace { + +auto fooBar = registration::MethodRegister < int, Foo, int > ( & Foo::bar, "bar" ); + +} /* namespace */ + void CliTest::testMember ( ) { abstraction::AlgorithmRegistry::registerAlgorithm < Foo > ( Foo::make_foo, abstraction::AlgorithmCategories::AlgorithmCategory::DEFAULT, std::array < std::string, 1 > ( ) ); - abstraction::AlgorithmRegistry::registerMethod < Foo > ( & Foo::bar, "bar", std::array < std::string, 1 > ( ) ); + abstraction::AlgorithmRegistry::registerMethod < Foo > ( & Foo::base, "base", std::array < std::string, 0 > ( ) ); cli::Environment environment; - cli::Parser parser ( cli::Lexer ( "execute Foo 3 | Foo::bar - 2" ) ); + cli::Parser parser ( cli::Lexer ( "execute Foo 3 | Foo::base -" ) ); + parser.parse ( )->run ( environment ); + parser = cli::Parser ( cli::Lexer ( "execute Foo 3 | Foo::bar - 2" ) ); parser.parse ( )->run ( environment ); } diff --git a/alib2common/src/registration/AlgoRegistration.hpp b/alib2common/src/registration/AlgoRegistration.hpp index 24a0946041fa2ca2cf7f5e499d8d01514deb5278..5d210c27df1936b5e080bc76ce4cafbb007033a0 100644 --- a/alib2common/src/registration/AlgoRegistration.hpp +++ b/alib2common/src/registration/AlgoRegistration.hpp @@ -58,6 +58,18 @@ public: }; +template < class ReturnType, class ObjectType, class ... ParameterTypes > +class MethodRegister : public AlgoRegister { +public: + template < class ... ParamNames > + MethodRegister ( ReturnType ( ObjectType::* callback ) ( ParameterTypes ... ), std::string methodName, ParamNames ... paramNames ) { + std::array < std::string, sizeof ... ( ParameterTypes ) > parameterNames = generateNames < sizeof ... ( ParameterTypes ) > ( paramNames ... ); + + abstraction::AlgorithmRegistry::registerMethod < ObjectType > ( callback, methodName, std::move ( parameterNames ) ); + } + +}; + } /* namespace registration */ #endif // _ALGO_REGISTRATION_HPP_