diff --git a/alib2common/test-src/core/ComponentsTest.cpp b/alib2common/test-src/core/ComponentsTest.cpp index 71f367a1d9d2b6dc40e6b3c1e8fcd7cf4efa6a10..2715cfc7e2ce353c6e9fe477cbbf458e5872277d 100644 --- a/alib2common/test-src/core/ComponentsTest.cpp +++ b/alib2common/test-src/core/ComponentsTest.cpp @@ -1,5 +1,5 @@ #include "ComponentsTest.h" -#include <core/components.hpp> +#include <core/components2.hpp> CPPUNIT_TEST_SUITE_NAMED_REGISTRATION ( ComponentsTest, "alphabet" ); CPPUNIT_TEST_SUITE_REGISTRATION ( ComponentsTest ); @@ -13,91 +13,97 @@ struct NonlinearAlphabet { struct SubtreeWildcard { }; -class A : public std::Components < A, std::string, std::tuple < GeneralAlphabet, NonlinearAlphabet >, std::tuple < SubtreeWildcard > > { +class A : public std::Components2 < A, std::string, std::tuple < GeneralAlphabet, NonlinearAlphabet >, std::tuple < SubtreeWildcard > > { public: - A ( std::string string ) : std::Components < A, std::string, std::tuple < GeneralAlphabet, NonlinearAlphabet >, std::tuple < SubtreeWildcard > > ( std::make_tuple ( std::set < std::string > { string, "aaa" }, std::set < std::string > { "aaa" } ), std::make_tuple ( string ) ) { + A ( std::string string ) : std::Components2 < A, std::string, std::tuple < GeneralAlphabet, NonlinearAlphabet >, std::tuple < SubtreeWildcard > > ( std::make_tuple ( std::set < std::string > { string, "aaa" }, std::set < std::string > { "aaa" } ), std::make_tuple ( string ) ) { } }; namespace std { template < > -bool A::Component < A, std::string, GeneralAlphabet >::used ( const std::string & string ) const { - return static_cast < const A * > ( this )->accessComponent < NonlinearAlphabet > ( ).get ( ).count ( string ) || static_cast < const A * > ( this )->accessElement < SubtreeWildcard > ( ).get ( ) == string; -} +class ComponentConstraint2< A, std::string, GeneralAlphabet > { +public: + static bool used ( const A & a, const std::string & string ) { + return a.accessComponent < NonlinearAlphabet > ( ).get ( ).count ( string ) || a.accessElement < SubtreeWildcard > ( ).get ( ) == string; + } -template < > -bool A::Component < A, std::string, NonlinearAlphabet >::used ( const std::string & ) const { - return false; -} + static bool available ( const A &, const std::string & ) { + return true; + } -template < > -bool A::Component < A, std::string, GeneralAlphabet >::available ( const std::string & ) const { - return true; -} + static void valid ( const A &, const std::string & ) { + } +}; template < > -bool A::Component < A, std::string, NonlinearAlphabet >::available ( const std::string & string ) const { - return static_cast < const A * > ( this )->accessComponent < GeneralAlphabet > ( ).get ( ).count ( string ); -} +class ComponentConstraint2< A, std::string, NonlinearAlphabet > { +public: + static bool used ( const A &, const std::string & ) { + return false; + } -template < > -bool A::Element < A, std::string, SubtreeWildcard >::available ( const std::string & string ) const { - return static_cast < const A * > ( this )->accessComponent < GeneralAlphabet > ( ).get ( ).count ( string ); -} + static bool available ( const A & a, const std::string & string ) { + return a.accessComponent < GeneralAlphabet > ( ).get ( ).count ( string ); + } -template < > -void A::Component < A, std::string, GeneralAlphabet >::valid ( const std::string & ) const { -} + static void valid ( const A & a, const std::string & string ) { + if ( a.accessElement < SubtreeWildcard > ( ).get ( ) == string ) + throw::exception::CommonException ( "Symbol " + ( std::string ) string + "cannot be set as nonlinear variable since it is already a subtree wildcard" ); + } +}; template < > -void A::Component < A, std::string, NonlinearAlphabet >::valid ( const std::string & string ) const { - if ( static_cast < const A * > ( this )->accessElement < SubtreeWildcard > ( ).get ( ) == string ) - throw::exception::CommonException ( "Symbol " + ( std::string ) string + "cannot be set as nonlinear variable since it is already a subtree wildcard" ); -} +class ElementConstraint2< A, std::string, SubtreeWildcard > { +public: + static bool available ( const A & a, const std::string & string ) { + return a.accessComponent < GeneralAlphabet > ( ).get ( ).count ( string ); + } -template < > -void A::Element < A, std::string, SubtreeWildcard >::valid ( const std::string & string ) const { - if ( static_cast < const A * > ( this )->accessComponent < NonlinearAlphabet > ( ).get ( ).count ( string ) ) - throw::exception::CommonException ( "Symbol " + ( std::string ) string + "cannot be set as subtree wildcard since it is already a nonlinear variable" ); -} + static void valid ( const A & a, const std::string & string) { + if ( a.accessComponent < NonlinearAlphabet > ( ).get ( ).count ( string ) ) + throw::exception::CommonException ( "Symbol " + ( std::string ) string + "cannot be set as subtree wildcard since it is already a nonlinear variable" ); + } +}; -} +} /* namespace std */ -class B : public std::Components < A, std::string, std::tuple < GeneralAlphabet, NonlinearAlphabet >, std::tuple < > > { +class B : public std::Components2 < B, std::string, std::tuple < GeneralAlphabet, NonlinearAlphabet >, std::tuple < > > { }; namespace std { template < > -bool B::Component < B, std::string, GeneralAlphabet >::used ( const std::string & ) const { - return false; -} +class ComponentConstraint2< B, std::string, GeneralAlphabet > { +public: + static bool used ( const B &, const std::string & ) { + return false; + } -template < > -bool B::Component < B, std::string, NonlinearAlphabet >::used ( const std::string & ) const { - return false; -} + static bool available ( const B &, const std::string & ) { + return true; + } -template < > -bool B::Component < B, std::string, GeneralAlphabet >::available ( const std::string & ) const { - return true; -} + static void valid ( const B &, const std::string & ) { + } +}; template < > -bool B::Component < B, std::string, NonlinearAlphabet >::available ( const std::string & ) const { - return true; -} +class ComponentConstraint2< B, std::string, NonlinearAlphabet > { +public: + static bool used ( const B &, const std::string & ) { + return false; + } -template < > -void B::Component < B, std::string, GeneralAlphabet >::valid ( const std::string & ) const { -} + static bool available ( const B &, const std::string & ) { + return true; + } -template < > -void B::Component < B, std::string, NonlinearAlphabet >::valid ( const std::string & ) const { -} + static void valid ( const B &, const std::string & ) { + } +}; -} +} /* namespace std */ void ComponentsTest::setUp ( ) { }