diff --git a/alib2common/src/core/multipleDispatch.hpp b/alib2common/src/core/multipleDispatch.hpp deleted file mode 100644 index c518d10926538d3cf325a3f282b263f77c0eccae..0000000000000000000000000000000000000000 --- a/alib2common/src/core/multipleDispatch.hpp +++ /dev/null @@ -1,225 +0,0 @@ -/* - * multipleDispatch.hpp - * - * Created on: Apr 05, 2014 - * Author: Jan Travnicek - */ - -#ifndef MULTIPLE_DISPATCH_H_ -#define MULTIPLE_DISPATCH_H_ - -#include <stdexcept> -#include <functional> -#include <map> -#include <iostream> -#include <type_traits> -#include <sstream> -#include <tuple> -#include <memory> - -#include <core/castApi.hpp> -#include <exception/CommonException.h> - -namespace alib { - -template < class Algorithm, class ReturnType, class ... Params > -class MultipleDispatch; - -template < class Algorithm, class ReturnType, class ... FrontStaticParamTypes, class ... DispatchedParameterTypes, class ... BackStaticParamTypes > -class MultipleDispatch < Algorithm, ReturnType, ext::tuple < FrontStaticParamTypes ... >, ext::tuple < DispatchedParameterTypes ... >, ext::tuple < BackStaticParamTypes ... > > { -public: - template < class RealReturnType, class ... RealParameterTypeBases > - using overload = std::function < RealReturnType ( FrontStaticParamTypes ..., typename ext::match_cv_ref < DispatchedParameterTypes, RealParameterTypeBases >::type && ..., BackStaticParamTypes ... ) >; - - template < class RealReturnType, class ... RealParameterTypeBases > - using rawOverload = RealReturnType ( * ) ( FrontStaticParamTypes ..., typename ext::match_cv_ref < DispatchedParameterTypes, RealParameterTypeBases >::type && ..., BackStaticParamTypes ... ); - - typedef ext::tuple < FrontStaticParamTypes ... > frontParams; - typedef ext::tuple < DispatchedParameterTypes ... > dispatchedParams; - typedef ext::tuple < BackStaticParamTypes ... > backParams; - typedef ReturnType returnType; - -private: - class RegistratorWrapperBase { - public: - virtual ReturnType eval ( FrontStaticParamTypes ..., DispatchedParameterTypes && ..., BackStaticParamTypes ... ) = 0; - }; - - template < class RealReturnType, class ... RealParameterTypeBases > - class RegistratorWrapper : public RegistratorWrapperBase { - overload < RealReturnType, RealParameterTypeBases ... > m_callback; - - public: - ReturnType eval ( FrontStaticParamTypes ... front, DispatchedParameterTypes && ... dispatched, BackStaticParamTypes ... back ) { - return ReturnType ( m_callback ( front ..., std::forward < typename ext::match_cv_ref < DispatchedParameterTypes, RealParameterTypeBases >::type > ( static_cast < typename ext::match_cv_ref < DispatchedParameterTypes, RealParameterTypeBases >::type && > ( dispatched ) ) ..., back ... ) ); - } - - RegistratorWrapper ( overload < RealReturnType, RealParameterTypeBases ... > callback ) : m_callback ( callback ) { - } - - }; - - ext::map < typename ext::TupleBuilder < ext::type_index, sizeof ... ( DispatchedParameterTypes ) >::type, std::unique_ptr < RegistratorWrapperBase > > registeredFunctions; - - static MultipleDispatch < Algorithm, ReturnType, ext::tuple < FrontStaticParamTypes ... >, ext::tuple < DispatchedParameterTypes ... >, ext::tuple < BackStaticParamTypes ... > > & getInstance ( ) { - static MultipleDispatch < Algorithm, ReturnType, ext::tuple < FrontStaticParamTypes ... >, ext::tuple < DispatchedParameterTypes ... >, ext::tuple < BackStaticParamTypes ... > > res; - - return res; - } - -public: - template < class RealReturnType, class ... RealParameterTypeBases > -// static void registerOverload ( overload < RealReturnType, RealParameterTypeBases ... > callback ) { causes clang 4.0.0 to crash... -// static void registerOverload ( rawOverload < RealReturnType, RealParameterTypeBases ... > callback ) { causes clang 4.0.0 to crash... - static void registerOverload ( RealReturnType ( * callback ) ( FrontStaticParamTypes ..., typename ext::match_cv_ref < DispatchedParameterTypes, RealParameterTypeBases >::type && ..., BackStaticParamTypes ... ) ) { - auto key = ext::make_tuple ( ext::type_index ( typeid ( typename ext::match_cv_ref < DispatchedParameterTypes, RealParameterTypeBases >::type ) ) ... ); - std::unique_ptr < RegistratorWrapperBase > value ( new RegistratorWrapper < RealReturnType, RealParameterTypeBases ... > ( callback ) ); - - bool res = getInstance ( ).registeredFunctions.insert ( std::make_pair ( std::move ( key ), std::move ( value ) ) ).second; - - if ( ! res ) { - std::stringstream ss; - ( void ) std::initializer_list < int > { ( ss << ext::to_string < typename ext::match_cv_ref < DispatchedParameterTypes, RealParameterTypeBases >::type > ( ), 0 ) ... }; - - std::string classType = ext::to_string < Algorithm > ( ); - - throw::exception::CommonException ( "Callback for " + ss.str ( ) + " already registered on " + classType + "." ); - } - } - - static ReturnType dispatch ( FrontStaticParamTypes ... front, DispatchedParameterTypes && ... dispatched, BackStaticParamTypes ... back ) { - auto callback = getInstance ( ).registeredFunctions.find ( ext::make_tuple ( ext::type_index ( typeid ( dispatched ) ) ... ) ); - - if ( callback == getInstance ( ).registeredFunctions.end ( ) ) { - std::stringstream ss; - ( void ) std::initializer_list < int > { ( ss << ext::to_string ( typeid ( dispatched ) ), 0 ) ... }; - - std::string classType = ext::to_string < Algorithm > ( ); - - throw::exception::CommonException ( "Callback for " + ss.str ( ) + " not registered on " + classType + "." ); - } - - return callback->second->eval ( front ..., std::forward < DispatchedParameterTypes > ( dispatched ) ..., back ... ); - } - -}; - -// -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- - -template < class Algorithm, class ReturnType, class FirstParameterType, class ... StaticParamTypes > -using SingleDispatch = MultipleDispatch < Algorithm, ReturnType, ext::tuple < >, ext::tuple < FirstParameterType >, ext::tuple < StaticParamTypes ... > >; - -template < class Algorithm, class ReturnType, class StaticParamType, class FirstParameterType > -using SingleDispatchFirstStaticParam = MultipleDispatch < Algorithm, ReturnType, ext::tuple < StaticParamType >, ext::tuple < FirstParameterType >, ext::tuple < > >; - -template < class Algorithm, class ReturnType, class FirstParameterType, class SecondParameterType, class ... StaticParamTypes > -using DoubleDispatch = MultipleDispatch < Algorithm, ReturnType, ext::tuple < >, ext::tuple < FirstParameterType, SecondParameterType >, ext::tuple < StaticParamTypes ... > >; - -template < class Algorithm, class ReturnType, class StaticParamType, class FirstParameterType, class SecondParameterType > -using DoubleDispatchFirstStaticParam = MultipleDispatch < Algorithm, ReturnType, ext::tuple < StaticParamType >, ext::tuple < FirstParameterType, SecondParameterType >, ext::tuple < > >; - -// -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- - -template < class Algorithm, class ReturnType, class ParametersType > -class PromotingDoubleDispatch { -public: - template < class RealReturnType, class RealParametersTypeBase > - using overload = std::function < RealReturnType ( typename ext::match_cv_ref < ParametersType, RealParametersTypeBase >::type &&, typename ext::match_cv_ref < ParametersType, RealParametersTypeBase >::type && ) >; - - template < class RealReturnType, class RealParametersTypeBase > - using rawOverload = RealReturnType ( * ) ( typename ext::match_cv_ref < ParametersType, RealParametersTypeBase >::type &&, typename ext::match_cv_ref < ParametersType, RealParametersTypeBase >::type && ); - - typedef ext::tuple < > frontParams; - typedef ext::tuple < ParametersType, ParametersType > dispatchedParams; - typedef ext::tuple < > backParams; - typedef ReturnType returnType; - -private: - class RegistratorWrapperBase { - public: - virtual ReturnType eval ( bool firstAttempt, ParametersType &&, ParametersType && ) = 0; - virtual bool available ( bool firstAttempt, ext::type_index first, ext::type_index second ) = 0; - }; - - template < class RealReturnType, class RealParametersTypeBase > - class RegistratorWrapper : public RegistratorWrapperBase { - typedef typename ext::match_cv_ref < ParametersType, RealParametersTypeBase >::type RealParametersType; - - std::function < RealReturnType ( RealParametersType &&, RealParametersType && ) > m_callback; - - public: - ReturnType eval ( bool firstAttempt, ParametersType && first, ParametersType && second ) { - if ( ext::type_index ( typeid ( first ) ) == ext::type_index ( typeid ( second ) ) ) - return ReturnType ( m_callback ( std::forward < RealParametersType > ( static_cast < RealParametersType && > ( first ) ), std::forward < RealParametersType > ( static_cast < RealParametersType && > ( second ) ) ) ); - - if ( firstAttempt ) { - alib::Object casted = alib::castApi::getCastPool ( ext::type_index ( typeid ( first ) ) ).cast ( std::forward < ParametersType > ( second ) ); - return ReturnType ( m_callback ( std::forward < RealParametersType > ( static_cast < RealParametersType && > ( first ) ), std::forward < RealParametersType > ( static_cast < RealParametersType && > ( casted.getData ( ) ) ) ) ); - } else { - alib::Object casted = alib::castApi::getCastPool ( ext::type_index ( typeid ( second ) ) ).cast ( std::forward < ParametersType > ( first ) ); - return ReturnType ( m_callback ( std::forward < RealParametersType > ( static_cast < RealParametersType && > ( casted.getData ( ) ) ), std::forward < RealParametersType > ( static_cast < RealParametersType && > ( second ) ) ) ); - } - } - - bool available ( bool firstAttempt, ext::type_index first, ext::type_index second ) { - if ( first == second ) return true; - - if ( firstAttempt ) - return alib::castApi::castAvailable ( first, second ); - else - return alib::castApi::castAvailable ( second, first ); - } - - RegistratorWrapper ( RealReturnType ( * callback ) ( RealParametersType &&, RealParametersType && ) ) : m_callback ( callback ) { - } - - }; - - ext::map < ext::type_index, std::unique_ptr < RegistratorWrapperBase > > registeredFunctions; - - static PromotingDoubleDispatch < Algorithm, ReturnType, ParametersType > & getInstance ( ) { - static PromotingDoubleDispatch < Algorithm, ReturnType, ParametersType > res; - - return res; - } - -public: - template < class RealReturnType, class RealParametersTypeBase > - static void registerOverload ( RealReturnType ( * callback ) ( typename ext::match_cv_ref < ParametersType, RealParametersTypeBase >::type &&, typename ext::match_cv_ref < ParametersType, RealParametersTypeBase >::type && ) ) { - std::unique_ptr < RegistratorWrapperBase > value ( new RegistratorWrapper < RealReturnType, RealParametersTypeBase > ( callback ) ); - - bool res = getInstance ( ).registeredFunctions.insert ( std::make_pair ( ext::type_index ( typeid ( typename ext::match_cv_ref < ParametersType, RealParametersTypeBase >::type ) ), std::move ( value ) ) ).second; - if ( ! res ) { - std::string paramsType = ext::to_string < typename ext::match_cv_ref < ParametersType, RealParametersTypeBase >::type > ( ); - - std::string classType = ext::to_string < Algorithm > ( ); - - throw::exception::CommonException ( "Callback for " + paramsType + " already registered on " + classType + "." ); - } - } - - static ReturnType dispatch ( ParametersType && first, ParametersType && second ) { - typename ext::map < ext::type_index, std::unique_ptr < RegistratorWrapperBase > >::iterator callback = getInstance ( ).registeredFunctions.find ( ext::type_index ( typeid ( first ) ) ); - - if ( ( callback != getInstance ( ).registeredFunctions.end ( ) ) && callback->second->available ( true, ext::type_index ( typeid ( first ) ), ext::type_index ( typeid ( second ) ) ) ) - return callback->second->eval ( true, std::forward < ParametersType > ( first ), std::forward < ParametersType > ( second ) ); - - callback = getInstance ( ).registeredFunctions.find ( ext::type_index ( typeid ( second ) ) ); - - if ( ( callback != getInstance ( ).registeredFunctions.end ( ) ) && callback->second->available ( false, ext::type_index ( typeid ( first ) ), ext::type_index ( typeid ( second ) ) ) ) - return callback->second->eval ( false, std::forward < ParametersType > ( first ), std::forward < ParametersType > ( second ) ); - - std::string firstType = ext::to_string ( typeid ( first ) ); - - std::string secondType = ext::to_string ( typeid ( second ) ); - - std::string classType = ext::to_string < Algorithm > ( ); - - throw::exception::CommonException ( "Callback for (" + firstType + ", " + secondType + ") (promoting) not registered on " + classType + "." ); - } - -}; - -} /* namespace alib */ - -#endif /* MULTIPLE_DISPATCH_H_ */ diff --git a/alib2common/src/registration/AlgoRegistration.hpp b/alib2common/src/registration/AlgoRegistration.hpp index 8751a68be527bf86083d20a3ae68b8094b0b0e15..713b46640ba8f97a6bf0e7216e3d9717d5ded8b0 100644 --- a/alib2common/src/registration/AlgoRegistration.hpp +++ b/alib2common/src/registration/AlgoRegistration.hpp @@ -1,22 +1,12 @@ #ifndef _ALGO_REGISTRATION_HPP_ #define _ALGO_REGISTRATION_HPP_ -#include <core/multipleDispatch.hpp> - #include <abstraction/AlgorithmRegistry.hpp> #include <registration/NormalizationRegistration.hpp> namespace registration { -template < class Algorithm, class RealReturnType, class ... RealParameterTypeBases > -class OverloadRegister { -public: - OverloadRegister ( typename Algorithm::template rawOverload < RealReturnType, RealParameterTypeBases ... > callback ) { - Algorithm::template registerOverload < RealReturnType, RealParameterTypeBases ... > ( callback ); - } -}; - class AlgoRegister { protected: template < size_t ParameterTypesNumber, class ... ParamNames, typename std::enable_if < sizeof ... ( ParamNames ) <= ParameterTypesNumber >::type * = nullptr > diff --git a/alib2common/test-src/core/DispatchTest.cpp b/alib2common/test-src/core/DispatchTest.cpp deleted file mode 100644 index da5501d353487a20ecd55d78929b4f533b159f73..0000000000000000000000000000000000000000 --- a/alib2common/test-src/core/DispatchTest.cpp +++ /dev/null @@ -1,377 +0,0 @@ -#include "DispatchTest.h" -#include <registration/AlgoRegistration.hpp> -#include "base/CommonBase.hpp" -#include <set> -#include <string> - -CPPUNIT_TEST_SUITE_NAMED_REGISTRATION ( DispatchTest, "std" ); -CPPUNIT_TEST_SUITE_REGISTRATION ( DispatchTest ); - -void DispatchTest::setUp ( ) { -} - -void DispatchTest::tearDown ( ) { -} - -namespace dispatch { - - - -class TmpBase : public alib::CommonBase < TmpBase > { -}; - -class Tmp1 : public TmpBase { - int m_data; - -public: - int m_moves; - int m_copies; - - Tmp1 ( int data ) : m_data ( data ), m_moves ( 0 ), m_copies ( 0 ) { - } - - Tmp1 ( const Tmp1 & other ) : m_data ( other.m_data ), m_moves ( other.m_moves ), m_copies ( other.m_copies + 1 ) { - } - - Tmp1 ( Tmp1 && other ) noexcept : m_data ( other.m_data ), m_moves ( other.m_moves + 1 ), m_copies ( other.m_copies ) { - } - - ~Tmp1 ( ) noexcept { - } - - TmpBase * clone ( ) const { - return new Tmp1 ( * this ); - } - - TmpBase * plunder ( ) && { - return new Tmp1 ( * this ); - } - - virtual int compare ( const TmpBase & other ) const { - return -other.compare ( * this ); - } - - virtual int compare ( const Tmp1 & other ) const { - return this->m_data - other.m_data; - } - - virtual void operator >>( std::ostream & os ) const { - os << "Tmp1(" << m_data << ")"; - } - - virtual operator std::string ( ) const { - return "Tmp1(" + ext::to_string ( m_data ) + ")"; - } - - int getData ( ) const { - return m_data; - } - - virtual TmpBase * normalize ( ) && { - return this; - } - -}; - -class Tmp2 : public TmpBase { - double m_data; - -public: - int m_moves; - int m_copies; - - Tmp2 ( double data ) : m_data ( data ), m_moves ( 0 ), m_copies ( 0 ) { - } - - Tmp2 ( const Tmp1 & other ) : m_data ( other.getData ( ) ) { - } - - Tmp2 ( const Tmp2 & other ) : m_data ( other.m_data ), m_moves ( other.m_moves ), m_copies ( other.m_copies + 1 ) { - } - - Tmp2 ( Tmp2 && other ) noexcept : m_data ( other.m_data ), m_moves ( other.m_moves + 1 ), m_copies ( other.m_copies ) { - } - - ~Tmp2 ( ) noexcept { - } - - TmpBase * clone ( ) const { - return new Tmp2 ( * this ); - } - - TmpBase * plunder ( ) && { - return new Tmp2 ( * this ); - } - - virtual int compare ( const TmpBase & other ) const { - return -other.compare ( * this ); - } - - virtual int compare ( const Tmp2 & other ) const { - return this->m_data - other.m_data; - } - - virtual void operator >>( std::ostream & os ) const { - os << "Tmp2(" << m_data << ")"; - } - - virtual operator std::string ( ) const { - return "Tmp2(" + ext::to_string ( m_data ) + ")"; - } - - double getData ( ) const { - return m_data; - } - - virtual TmpBase * normalize ( ) && { - return this; - } - -}; - -class Tmp3 : public TmpBase { - std::string m_data; - -public: - int m_moves; - int m_copies; - - Tmp3 ( const std::string & data ) : m_data ( data ), m_moves ( 0 ), m_copies ( 0 ) { - } - - Tmp3 ( const Tmp1 & other ) : m_data ( ext::to_string ( other.getData ( ) ) ), m_moves ( 0 ), m_copies ( 0 ) { - } - - Tmp3 ( const Tmp2 & other ) : m_data ( ext::to_string ( other.getData ( ) ) ), m_moves ( 0 ), m_copies ( 0 ) { - } - - Tmp3 ( const Tmp3 & other ) : m_data ( other.m_data ), m_moves ( other.m_moves ), m_copies ( other.m_copies + 1 ) { - } - - Tmp3 ( Tmp3 && other ) noexcept : m_data ( other.m_data ), m_moves ( other.m_moves + 1 ), m_copies ( other.m_copies ) { - } - - ~Tmp3 ( ) noexcept { - } - - TmpBase * clone ( ) const { - return new Tmp3 ( * this ); - } - - TmpBase * plunder ( ) && { - return new Tmp3 ( * this ); - } - - virtual int compare ( const TmpBase & other ) const { - return -other.compare ( * this ); - } - - virtual int compare ( const Tmp3 & other ) const { - return this->m_data.compare ( other.m_data ); - } - - virtual void operator >>( std::ostream & os ) const { - os << "Tmp3(" << m_data << ")"; - } - - virtual operator std::string ( ) const { - return "Tmp3(" + m_data + ")"; - } - - const std::string & getData ( ) const { - return m_data; - } - - virtual TmpBase * normalize ( ) && { - return this; - } - -}; - -// ------------------------------------------------------------------------------------------------------------------------------------------------------- - -class TmpVisitor : public alib::MultipleDispatch < TmpVisitor, int, ext::tuple < >, ext::tuple < const TmpBase & >, ext::tuple < > > { -public: - static int eval ( const Tmp2 & first ) { - std::cout << first << std::endl; - - CPPUNIT_ASSERT ( first.m_moves == 0); - CPPUNIT_ASSERT ( first.m_copies == 0); - - return 2; - } - - static int eval ( const Tmp3 & first ) { - std::cout << first << std::endl; - - CPPUNIT_ASSERT ( first.m_moves == 0); - CPPUNIT_ASSERT ( first.m_copies == 0); - - return 3; - } - - static int eval ( const TmpBase & first ) { - return dispatch ( first ); - } - -}; - -int TmpVisitorExtensionTmp1 ( const Tmp1 & first ) { - std::cout << first << std::endl; - - return 1; -} - -auto TmpVisitorTmp1 = registration::OverloadRegister < TmpVisitor, int, Tmp1 > ( TmpVisitorExtensionTmp1 ); -auto TmpVisitorTmp2 = registration::OverloadRegister < TmpVisitor, int, Tmp2 > ( TmpVisitor::eval ); -auto TmpVisitorTmp3 = registration::OverloadRegister < TmpVisitor, int, Tmp3 > ( TmpVisitor::eval ); - -} /* namespace dispatch */ - -void DispatchTest::testDispatch ( ) { - dispatch::Tmp1 tmp1 ( 2 ); - - int a = dispatch::TmpVisitor::eval ( tmp1 ); - - CPPUNIT_ASSERT ( a == 1 ); - - a = dispatch::TmpVisitor::eval ( ( dispatch::TmpBase & ) tmp1 ); - CPPUNIT_ASSERT ( a == 1 ); - - dispatch::Tmp2 tmp2 ( 3.3 ); - - a = dispatch::TmpVisitor::eval ( tmp2 ); - CPPUNIT_ASSERT ( a == 2 ); - - a = dispatch::TmpVisitor::eval ( ( dispatch::TmpBase & ) tmp2 ); - CPPUNIT_ASSERT ( a == 2 ); -} - -// ------------------------------------------------------------------------------------------------------------------------------------------------------- - -namespace dispatch { - -class TmpVisitor2 : public alib::SingleDispatchFirstStaticParam < TmpVisitor2, void, int &, const TmpBase & > { -public: - static void eval ( int & res, const Tmp2 & first ) { - std::cout << first << std::endl; - - CPPUNIT_ASSERT ( first.m_moves == 0); - CPPUNIT_ASSERT ( first.m_copies == 0); - - res = 2; - } - - static void eval ( int & res, const Tmp3 & first ) { - std::cout << first << std::endl; - - CPPUNIT_ASSERT ( first.m_moves == 0); - CPPUNIT_ASSERT ( first.m_copies == 0); - - res = 3; - } - - static void eval ( int & res, const TmpBase & first ) { - dispatch ( res, first ); - } - -}; - -void TmpVisitor2ExtensionTmp1 ( int & res, const Tmp1 & first ) { - std::cout << first << std::endl; - - CPPUNIT_ASSERT ( first.m_moves == 0); - CPPUNIT_ASSERT ( first.m_copies == 0); - - res = 1; -} - -auto TmpVisitor2Tmp1 = registration::OverloadRegister < TmpVisitor2, void, Tmp1 > ( TmpVisitor2ExtensionTmp1 ); -auto TmpVisitor2Tmp2 = registration::OverloadRegister < TmpVisitor2, void, Tmp2 > ( TmpVisitor2::eval ); -auto TmpVisitor2Tmp3 = registration::OverloadRegister < TmpVisitor2, void, Tmp3 > ( TmpVisitor2::eval ); - -} /* namespace dispatch */ - -void DispatchTest::testDispatch2 ( ) { - dispatch::Tmp1 tmp1 ( 2 ); - - int a; - dispatch::TmpVisitor2::eval ( a, tmp1 ); - - CPPUNIT_ASSERT ( a == 1 ); - - dispatch::TmpVisitor2::eval ( a, ( dispatch::TmpBase & ) tmp1 ); - CPPUNIT_ASSERT ( a == 1 ); - - dispatch::Tmp2 tmp2 ( 3.3 ); - - dispatch::TmpVisitor2::eval ( a, tmp2 ); - CPPUNIT_ASSERT ( a == 2 ); - - dispatch::TmpVisitor2::eval ( a, ( dispatch::TmpBase & ) tmp2 ); - CPPUNIT_ASSERT ( a == 2 ); -} - -// ------------------------------------------------------------------------------------------------------------------------------------------------------- - -namespace dispatch { - -class TmpVisitor3 : public alib::SingleDispatch < TmpVisitor3, int, TmpBase && > { -public: - static int eval ( Tmp2 && first ) { - std::cout << first << std::endl; - - CPPUNIT_ASSERT ( first.m_moves == 0); - CPPUNIT_ASSERT ( first.m_copies == 0); - - return 2; - } - - static int eval ( Tmp3 && first ) { - std::cout << first << std::endl; - - CPPUNIT_ASSERT ( first.m_moves == 0); - CPPUNIT_ASSERT ( first.m_copies == 0); - - return 3; - } - - static int eval ( TmpBase && first ) { - return dispatch ( std::move ( first ) ); - } - -}; - -int TmpVisitor3ExtensionTmp1 ( Tmp1 && first ) { - std::cout << first << std::endl; - - CPPUNIT_ASSERT ( first.m_moves == 0); - CPPUNIT_ASSERT ( first.m_copies == 0); - - return 1; -} - -auto TmpVisitor3Tmp1 = registration::OverloadRegister < TmpVisitor3, int, Tmp1 > ( TmpVisitor3ExtensionTmp1 ); -auto TmpVisitor3Tmp2 = registration::OverloadRegister < TmpVisitor3, int, Tmp2 > ( TmpVisitor3::eval ); -auto TmpVisitor3Tmp3 = registration::OverloadRegister < TmpVisitor3, int, Tmp3 > ( TmpVisitor3::eval ); - -} /* namespace dispatch */ - -void DispatchTest::testDispatch3 ( ) { - dispatch::Tmp1 tmp1 ( 2 ); - - int a = dispatch::TmpVisitor3::eval ( std::move ( tmp1 ) ); - - CPPUNIT_ASSERT ( a == 1 ); - - a = dispatch::TmpVisitor3::eval ( std::move ( ( dispatch::TmpBase & ) tmp1 ) ); - CPPUNIT_ASSERT ( a == 1 ); - - dispatch::Tmp2 tmp2 ( 3.3 ); - - a = dispatch::TmpVisitor3::eval ( std::move ( tmp2 ) ); - CPPUNIT_ASSERT ( a == 2 ); - - a = dispatch::TmpVisitor3::eval ( std::move ( ( dispatch::TmpBase & ) tmp2 ) ); - CPPUNIT_ASSERT ( a == 2 ); -} diff --git a/alib2common/test-src/core/DispatchTest.h b/alib2common/test-src/core/DispatchTest.h deleted file mode 100644 index ffc3b3d4c9ccebfe6f3f4285abb0ae3f78cbd7e5..0000000000000000000000000000000000000000 --- a/alib2common/test-src/core/DispatchTest.h +++ /dev/null @@ -1,23 +0,0 @@ -#ifndef DISPATCH_TEST_H_ -#define DISPATCH_TEST_H_ - -#include <cppunit/extensions/HelperMacros.h> - -class DispatchTest : public CppUnit::TestFixture -{ - CPPUNIT_TEST_SUITE( DispatchTest ); - CPPUNIT_TEST( testDispatch ); - CPPUNIT_TEST( testDispatch2 ); - CPPUNIT_TEST( testDispatch3 ); - CPPUNIT_TEST_SUITE_END(); - -public: - void setUp(); - void tearDown(); - - void testDispatch(); - void testDispatch2(); - void testDispatch3(); -}; - -#endif // DISPATCH_TEST_H_