diff --git a/alib2algo/src/regexp/convert/ToAutomatonThompson.h b/alib2algo/src/regexp/convert/ToAutomatonThompson.h index a610b84fd75892baf885ec13be9b9a66d60b60d3..931a81734a9ae4d942194b481d52a200e95e7d01 100644 --- a/alib2algo/src/regexp/convert/ToAutomatonThompson.h +++ b/alib2algo/src/regexp/convert/ToAutomatonThompson.h @@ -27,7 +27,7 @@ namespace convert { * http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.21.7450&rep=rep1&type=ps * Melichar 2.112 */ -class ToAutomatonThompson : public std::SingleDispatch<automaton::EpsilonNFA, regexp::RegExpBase>, regexp::FormalRegExpElement::const_visitor_type, regexp::UnboundedRegExpElement::const_visitor_type { +class ToAutomatonThompson : public std::SingleDispatch<automaton::EpsilonNFA, regexp::RegExpBase>, regexp::FormalRegExpElementVisitor, regexp::UnboundedRegExpElementVisitor { public: ToAutomatonThompson() {} diff --git a/alib2algo/src/regexp/properties/RegExpEmpty.h b/alib2algo/src/regexp/properties/RegExpEmpty.h index 8e3591e2642177df85230455cd34aa6666af62df..8406ca5e9121e444024fa2c257a2ea22bd144b08 100644 --- a/alib2algo/src/regexp/properties/RegExpEmpty.h +++ b/alib2algo/src/regexp/properties/RegExpEmpty.h @@ -22,7 +22,7 @@ namespace properties { * Determines whether regular expression is empty (regexp == \0) * */ -class RegExpEmpty : public std::SingleDispatch<bool, regexp::RegExpBase>, regexp::FormalRegExpElement::const_visitor_type, regexp::UnboundedRegExpElement::const_visitor_type { +class RegExpEmpty : public std::SingleDispatch<bool, regexp::RegExpBase>, regexp::FormalRegExpElementVisitor, regexp::UnboundedRegExpElementVisitor { public: RegExpEmpty() {} diff --git a/alib2algo/src/regexp/properties/RegExpEpsilon.h b/alib2algo/src/regexp/properties/RegExpEpsilon.h index 37f13196936f809cfc6b1bb2e606b2402ca6f51c..7fbcd6f0c458736674224a5dc5de1849f816ec5c 100644 --- a/alib2algo/src/regexp/properties/RegExpEpsilon.h +++ b/alib2algo/src/regexp/properties/RegExpEpsilon.h @@ -22,7 +22,7 @@ namespace properties { * Checks, whether regexp (or its subtree) describes epsilon (empty string). * */ -class RegExpEpsilon : public std::SingleDispatch<bool, regexp::RegExpBase>, regexp::FormalRegExpElement::const_visitor_type, regexp::UnboundedRegExpElement::const_visitor_type { +class RegExpEpsilon : public std::SingleDispatch<bool, regexp::RegExpBase>, regexp::FormalRegExpElementVisitor, regexp::UnboundedRegExpElementVisitor { public: RegExpEpsilon() {} diff --git a/alib2algo/src/regexp/transform/RegExpDerivation.h b/alib2algo/src/regexp/transform/RegExpDerivation.h index 169a9cb81988d04db7852ed31b0a2f45a5dd4a4e..9cf1fc7f1400855bebdf4fce10da03eb3f0a9894 100644 --- a/alib2algo/src/regexp/transform/RegExpDerivation.h +++ b/alib2algo/src/regexp/transform/RegExpDerivation.h @@ -25,7 +25,7 @@ namespace regexp { * - Melichar, definition 2.91 in chapter 2.4.3 * - Brzozowski, J. A. - Derivatives of regular expressions (1964) */ -class RegExpDerivation : public std::SingleDispatchLastStaticParam<regexp::RegExp, regexp::RegExpBase, const string::LinearString&>, regexp::FormalRegExpElement::const_visitor_type, regexp::UnboundedRegExpElement::const_visitor_type { +class RegExpDerivation : public std::SingleDispatchLastStaticParam<regexp::RegExp, regexp::RegExpBase, const string::LinearString&>, regexp::FormalRegExpElementVisitor, regexp::UnboundedRegExpElementVisitor { public: RegExpDerivation() {} diff --git a/alib2algo/src/regexp/transform/RegExpIntegral.h b/alib2algo/src/regexp/transform/RegExpIntegral.h index 84fd1d72ec93517d99704b0921d73a49b580dae5..122bec3c48e460d4b0edc207422c3888b5b754c5 100644 --- a/alib2algo/src/regexp/transform/RegExpIntegral.h +++ b/alib2algo/src/regexp/transform/RegExpIntegral.h @@ -23,7 +23,7 @@ namespace regexp * Calculates integral of regular expression * Source: Melichar definition 2.93 in chapter 2.4.4 */ -class RegExpIntegral : public std::SingleDispatchLastStaticParam<regexp::RegExp, regexp::RegExpBase, const string::LinearString&>, regexp::FormalRegExpElement::const_visitor_type, regexp::UnboundedRegExpElement::const_visitor_type +class RegExpIntegral : public std::SingleDispatchLastStaticParam<regexp::RegExp, regexp::RegExpBase, const string::LinearString&>, regexp::FormalRegExpElementVisitor, regexp::UnboundedRegExpElementVisitor { public: RegExpIntegral() {} diff --git a/alib2common/src/core/visitor.hpp b/alib2common/src/core/visitor.hpp deleted file mode 100644 index 78351976df0aa104c5ebf6ad91b915a87922d21a..0000000000000000000000000000000000000000 --- a/alib2common/src/core/visitor.hpp +++ /dev/null @@ -1,298 +0,0 @@ -/* - * Visitor.h - * - * Created on: Apr 05, 2014 - * Author: Andrew Durward - * Modified: Jan Travnicek - */ - -#ifndef VISITOR_H_ -#define VISITOR_H_ - -#include <stdexcept> -#include <typeindex> -#include <iostream> - -namespace std { - - // Visitor template declaration -template < typename ... Types > -class visitor; - - // specialization for single type -template < typename T > -class visitor < T > { -public: - virtual void Visit ( void *, T & ) const = 0; -}; - - // specialization for multiple types -template < typename T, typename ... Types > -class visitor < T, Types ... > : public visitor < Types ... > { -public: - // promote the function(s) from the base class - using visitor < Types ... >::Visit; - - virtual void Visit ( void *, T & ) const = 0; -}; - - // Visitor template declaration -template < typename ... Types > -class const_visitor; - - // specialization for single type -template < typename T > -class const_visitor < T > { -public: - virtual void Visit ( void *, const T & ) const = 0; -}; - - // specialization for multiple types -template < typename T, typename ... Types > -class const_visitor < T, Types ... > : public const_visitor < Types ... > { -public: - // promote the function(s) from the base class - using const_visitor < Types ... >::Visit; - - virtual void Visit ( void *, const T & ) const = 0; -}; - -template < typename ... Types > -struct const_promoting_helper; - -template < typename Tested, typename ... Other > -struct const_promoting_helper < Tested, Other ... > { - - // variant 1 is swaping first and second argument because it came swaped - template < class Desired, class Base, class TargetVisitor, typename std::enable_if < std::is_constructible < Desired, Tested >::value >::type * = nullptr > - inline static bool tryPromote1 ( void * userData, const Desired & first, const Base & second, const TargetVisitor & visitor ) { - if ( std::type_index ( typeid ( Tested ) ) == std::type_index ( typeid ( second ) ) ) { - visitor.Visit ( userData, Desired ( static_cast < const Tested & > ( second ) ), first ); - return true; - } else { - return const_promoting_helper < Other ... >::tryPromote1 ( userData, first, second, visitor ); - } - } - - template < class Desired, class Base, class TargetVisitor, typename std::enable_if < !std::is_constructible < Desired, Tested >::value >::type * = nullptr > - inline static bool tryPromote1 ( void * userData, const Desired & first, const Base & second, const TargetVisitor & visitor ) { - return const_promoting_helper < Other ... >::tryPromote1 ( userData, first, second, visitor ); - } - - // variant 2 is not swaping first and second argument because it did not came swaped - template < class Desired, class Base, class TargetVisitor, typename std::enable_if < std::is_constructible < Desired, Tested >::value >::type * = nullptr > - inline static bool tryPromote2 ( void * userData, const Desired & first, const Base & second, const TargetVisitor & visitor ) { - if ( std::type_index ( typeid ( Tested ) ) == std::type_index ( typeid ( second ) ) ) { - visitor.Visit ( userData, first, Desired ( static_cast < const Tested & > ( second ) ) ); - return true; - } else { - return const_promoting_helper < Other ... >::tryPromote2 ( userData, first, second, visitor ); - } - } - - template < class Desired, class Base, class TargetVisitor, typename std::enable_if < !std::is_constructible < Desired, Tested >::value >::type * = nullptr > - inline static bool tryPromote2 ( void * userData, const Desired & first, const Base & second, const TargetVisitor & visitor ) { - return const_promoting_helper < Other ... >::tryPromote2 ( userData, first, second, visitor ); - } - -}; - -template < > -struct const_promoting_helper < > { - - template < class Desired, class Base, class TargetVisitor > - inline static bool tryPromote1 ( void *, const Desired &, const Base &, const TargetVisitor & ) { return false; } - - template < class Desired, class Base, class TargetVisitor > - inline static bool tryPromote2 ( void *, const Desired &, const Base &, const TargetVisitor & ) { return false; } -}; - -class const_promoting_visitor_base { }; - - // Visitor template declaration -template < typename ... Types > -class const_promoting_visitor; - - // specialization for single type -template < typename T > -class const_promoting_visitor < T > : public const_promoting_visitor_base { -public: - virtual void Visit ( void *, const T &, const T & ) const = 0; - - // variant 1 is swaping first and second argument because it came swaped - template < typename R, typename promoting_helper_type > - bool Visit1 ( void * userData, const T & first, const R & second ) const { - if ( std::type_index ( typeid ( T ) ) == std::type_index ( typeid ( second ) ) ) { - this->Visit ( userData, static_cast < const T & > ( second ), first ); - return true; - } else { - return promoting_helper_type::tryPromote1 ( userData, first, second, * this ); - } - } - - // variant 2 is not swaping first and second argument because it did not came swaped - template < typename R, typename promoting_helper_type > - bool Visit2 ( void * userData, const T & first, const R & second ) const { - if ( std::type_index ( typeid ( T ) ) == std::type_index ( typeid ( second ) ) ) { - this->Visit ( userData, first, static_cast < const T & > ( second ) ); - return true; - } else { - return promoting_helper_type::tryPromote2 ( userData, first, second, * this ); - } - } - -}; - - // specialization for multiple types -template < typename T, typename ... Types > -class const_promoting_visitor < T, Types ... > : public const_promoting_visitor < Types ... > { -public: - // promote the function(s) from the base class - using const_promoting_visitor < Types ... >::Visit; - using const_promoting_visitor < Types ... >::Visit1; - using const_promoting_visitor < Types ... >::Visit2; - - virtual void Visit ( void *, const T &, const T & ) const = 0; - - // variant 1 is swaping first and second argument because it came swaped - template < typename R, typename promoting_helper_type > - bool Visit1 ( void * userData, const T & first, const R & second ) const { - if ( std::type_index ( typeid ( T ) ) == std::type_index ( typeid ( second ) ) ) { - this->Visit ( userData, static_cast < const T & > ( second ), first ); - return true; - } else { - return promoting_helper_type::tryPromote1 ( userData, first, second, * this ); - } - } - - // variant 2 is not swaping first and second argument because it did not came swaped - template < typename R, typename promoting_helper_type > - bool Visit2 ( void * userData, const T & first, const R & second ) const { - if ( std::type_index ( typeid ( T ) ) == std::type_index ( typeid ( second ) ) ) { - this->Visit ( userData, first, static_cast < const T & > ( second ) ); - return true; - } else { - return promoting_helper_type::tryPromote2 ( userData, first, second, * this ); - } - } - -}; - -class const_same_visitor_base { }; - - // Visitor template declaration -template < typename ... Types > -class const_same_visitor; - - // specialization for single type -template < typename T > -class const_same_visitor < T > : public const_same_visitor_base { -public: - virtual void Visit ( void *, const T &, const T & ) const = 0; - - template < typename R > - void Visit1 ( void * userData, const T & first, const R & second ) const { - if ( std::type_index ( typeid ( T ) ) == std::type_index ( typeid ( second ) ) ) - this->Visit ( userData, first, dynamic_cast < const T & > ( second ) ); // tady ten dynamic cast muze byt i static cast ale to by to muselo na g++ 5.2 fungovat - else - throw std::logic_error ( "Same visitor: Visited types are different." ); - } - -}; - - // specialization for multiple types -template < typename T, typename ... Types > -class const_same_visitor < T, Types ... > : public const_same_visitor < Types ... > { -public: - // promote the function(s) from the base class - using const_same_visitor < Types ... >::Visit; - using const_same_visitor < Types ... >::Visit1; - - virtual void Visit ( void *, const T &, const T & ) const = 0; - - template < typename R > - void Visit1 ( void * userData, const T & first, const R & second ) const { - if ( std::type_index ( typeid ( T ) ) == std::type_index ( typeid ( second ) ) ) - this->Visit ( userData, first, dynamic_cast < const T & > ( second ) ); // tady ten dynamic cast muze byt i static cast ale to by to muselo na g++ 5.2 fungovat - else - throw std::logic_error ( "Same visitor: Visited types are different." ); - } - -}; - -template < typename T, typename ... Types > -class acceptor_base { -public: - typedef visitor < Types ... > visitor_type; - - typedef const_visitor < Types ... > const_visitor_type; - - typedef const_promoting_visitor < Types ... > const_promoting_visitor_type; - typedef const_promoting_helper < Types ... > const_promoting_helper_type; - - typedef const_same_visitor < Types ... > const_same_visitor_type; - - typedef T base_type; - - virtual void Accept ( void * userData, const visitor < Types ... > & visitor ) = 0; - - virtual void Accept ( void * userData, const const_visitor < Types ... > & visitor ) const = 0; - - virtual bool Accept ( void * userData, const T & other, const const_promoting_visitor < Types ... > & visitor, bool swap ) const = 0; - - virtual void Accept ( void * userData, const T & other, const const_same_visitor < Types ... > & visitor ) const = 0; -}; - -template < typename Derived, typename AcceptorBase, typename Base > -class acceptor : public Base { -public: - using Base::Accept; - - virtual void Accept ( void * userData, const typename AcceptorBase::visitor_type & visitor ) { - visitor.Visit ( userData, static_cast < Derived & > ( * this ) ); - } - - virtual void Accept ( void * userData, const typename AcceptorBase::const_visitor_type & visitor ) const { - visitor.Visit ( userData, static_cast < const Derived & > ( * this ) ); - } - - virtual bool Accept ( void * userData, const typename AcceptorBase::base_type & other, const typename AcceptorBase::const_promoting_visitor_type & visitor, bool swap ) const { - if ( swap ) - // variant 1 is swaping first and second argument because it came swaped - return visitor.template Visit1 < typename AcceptorBase::base_type, typename AcceptorBase::const_promoting_helper_type > ( userData, static_cast < const Derived & > ( * this ), other ); - else - // variant 2 is not swaping first and second argument because it did not came swaped - return visitor.template Visit2 < typename AcceptorBase::base_type, typename AcceptorBase::const_promoting_helper_type > ( userData, static_cast < const Derived & > ( * this ), other ); - } - - virtual void Accept ( void * userData, const typename AcceptorBase::base_type & other, const typename AcceptorBase::const_same_visitor_type & visitor ) const { - visitor.template Visit1 < typename AcceptorBase::base_type > ( userData, static_cast < const Derived & > ( * this ), other ); - } - -}; - -template < class T, class R, typename std::enable_if < std::is_base_of < const_same_visitor_base, R >::value >::type * = nullptr > -void Accept ( void * userData, const T & first, const T & second, const R & visitor ) { - first.Accept ( userData, second, visitor ); -} - -template < class T, class R, typename std::enable_if < std::is_base_of < const_promoting_visitor_base, R >::value >::type * = nullptr > -void Accept ( void * userData, const T & first, const T & second, const R & visitor ) { - bool res; - - // variant 2 is swaping first and second argument because it come swaped - res = first.Accept ( userData, second, visitor, false ); - - if ( res ) return; - - // variant 1 is not swaping first and second argument because it did not come swaped - res = second.Accept ( userData, first, visitor, true ); - - if ( res ) return; - - throw std::logic_error ( "Promoting visitor: Can't promote one parameter to type of the other." ); -} - -} /* namespace std */ - -#endif /* VISITOR_H_ */ diff --git a/alib2common/test-src/core/VisitorTest.cpp b/alib2common/test-src/core/VisitorTest.cpp deleted file mode 100644 index dcc79c01724f5f4e1928b3ea80fe9c126812e035..0000000000000000000000000000000000000000 --- a/alib2common/test-src/core/VisitorTest.cpp +++ /dev/null @@ -1,264 +0,0 @@ -#include "VisitorTest.h" -#include "core/visitor.hpp" -#include "base/CommonBase.hpp" -#include <set> -#include <string> - -CPPUNIT_TEST_SUITE_NAMED_REGISTRATION ( VisitorTest, "std" ); -CPPUNIT_TEST_SUITE_REGISTRATION ( VisitorTest ); - -void VisitorTest::setUp ( ) { -} - -void VisitorTest::tearDown ( ) { -} - -namespace visitor { - -class Tmp1; -class Tmp2; -class Tmp3; - -class TmpBase; - -typedef std::acceptor_base < TmpBase, Tmp1, Tmp2, Tmp3 > VisitableTmpBase; - -class TmpBase : public alib::CommonBase < TmpBase >, public VisitableTmpBase { -}; - -class Tmp1 : public std::acceptor < Tmp1, VisitableTmpBase, TmpBase > { - int data; - -public: - Tmp1 ( int data ) : data ( data ) { - } - - 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->data - other.data; - } - - virtual void operator >>( std::ostream & os ) const { - os << "Tmp1(" << data << ")"; - } - - virtual operator std::string ( ) const { - return "Tmp1(" + std::to_string ( data ) + ")"; - } - - int getData ( ) const { - return data; - } - -}; - -class Tmp2 : public std::acceptor < Tmp2, VisitableTmpBase, TmpBase > { - double data; - -public: - Tmp2 ( double data ) : data ( data ) { - } - - Tmp2 ( const Tmp1 & other ) : data ( other.getData ( ) ) { - } - - 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->data - other.data; - } - - virtual void operator >>( std::ostream & os ) const { - os << "Tmp2(" << data << ")"; - } - - virtual operator std::string ( ) const { - return "Tmp2(" + std::to_string ( data ) + ")"; - } - - double getData ( ) const { - return data; - } - -}; - -class Tmp3 : public std::acceptor < Tmp3, VisitableTmpBase, TmpBase > { - std::string data; - -public: - Tmp3 ( const std::string & data ) : data ( data ) { - } - - Tmp3 ( const Tmp1 & other ) : data ( std::to_string ( other.getData ( ) ) ) { - } - - Tmp3 ( const Tmp2 & other ) : data ( std::to_string ( other.getData ( ) ) ) { - } - - 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->data.compare ( other.data ); - } - - virtual void operator >>( std::ostream & os ) const { - os << "Tmp3(" << data << ")"; - } - - virtual operator std::string ( ) const { - return "Tmp3(" + data + ")"; - } - - const std::string & getData ( ) const { - return data; - } - -}; - -class TmpVisitor : public VisitableTmpBase::const_visitor_type { - void Visit ( void * userData, const Tmp1 & first ) const { - int & data = * ( ( int * ) userData ); - - data = 1; - std::cout << first << std::endl; - } - - void Visit ( void * userData, const Tmp2 & first ) const { - int & data = * ( ( int * ) userData ); - - data = 2; - std::cout << first << std::endl; - } - - void Visit ( void * userData, const Tmp3 & first ) const { - int & data = * ( ( int * ) userData ); - - data = 3; - std::cout << first << std::endl; - } - -}; - -class TmpSameVisitor : public VisitableTmpBase::const_same_visitor_type { - void Visit ( void * userData, const Tmp1 & first, const Tmp1 & second ) const { - int & data = * ( ( int * ) userData ); - - data = 1; - std::cout << first << " " << second << std::endl; - } - - void Visit ( void * userData, const Tmp2 & first, const Tmp2 & second ) const { - int & data = * ( ( int * ) userData ); - - data = 2; - std::cout << first << " " << second << std::endl; - } - - void Visit ( void * userData, const Tmp3 & first, const Tmp3 & second ) const { - int & data = * ( ( int * ) userData ); - - data = 3; - std::cout << first << " " << second << std::endl; - } - -}; - -class TmpPromotingVisitor : public VisitableTmpBase::const_promoting_visitor_type { - void Visit ( void * userData, const Tmp1 & first, const Tmp1 & second ) const { - std::string & data = * ( ( std::string * ) userData ); - - data = std::to_string ( first.getData ( ) ) + " " + std::to_string ( second.getData ( ) ); - std::cout << first << " " << second << std::endl; - } - - void Visit ( void * userData, const Tmp2 & first, const Tmp2 & second ) const { - std::string & data = * ( ( std::string * ) userData ); - - data = std::to_string ( first.getData ( ) ) + " " + std::to_string ( second.getData ( ) ); - std::cout << first << " " << second << std::endl; - } - - void Visit ( void * userData, const Tmp3 & first, const Tmp3 & second ) const { - std::string & data = * ( ( std::string * ) userData ); - - data = first.getData ( ) + " " + second.getData ( ); - std::cout << first << " " << second << std::endl; - } - -}; - -} /* namespace visitor */ - -void VisitorTest::testVisitor ( ) { - visitor::TmpVisitor visitor; - - visitor::Tmp1 tmp1 ( 2 ); - - int a = 0; - - tmp1.Accept ( ( void * ) & a, visitor ); - - CPPUNIT_ASSERT ( a == 1 ); -} - -void VisitorTest::testSameVisitor ( ) { - visitor::TmpSameVisitor visitor; - - visitor::Tmp2 tmpA ( 2 ); - visitor::Tmp2 tmpB ( 3 ); - - int a = 0; - - Accept ( ( void * ) & a, ( visitor::TmpBase & ) tmpA, ( visitor::TmpBase & ) tmpB, visitor ); - - CPPUNIT_ASSERT ( a == 2 ); -} - -void VisitorTest::testPromoteVisitor ( ) { - visitor::TmpPromotingVisitor visitor; - - visitor::Tmp1 tmp1 ( 1 ); - visitor::Tmp3 tmp3 ( "3" ); - - std::string a = ""; - - Accept ( ( void * ) & a, ( visitor::TmpBase & ) tmp1, ( visitor::TmpBase & ) tmp3, visitor ); - - CPPUNIT_ASSERT ( a == "1 3" ); - - std::string b = ""; - Accept ( ( void * ) & b, ( visitor::TmpBase & ) tmp3, ( visitor::TmpBase & ) tmp1, visitor ); - - CPPUNIT_ASSERT ( b == "3 1" ); -} diff --git a/alib2common/test-src/core/VisitorTest.h b/alib2common/test-src/core/VisitorTest.h deleted file mode 100644 index 3991d37c8056735d2a542cb90213e61382d97e10..0000000000000000000000000000000000000000 --- a/alib2common/test-src/core/VisitorTest.h +++ /dev/null @@ -1,23 +0,0 @@ -#ifndef VISITOR_TEST_H_ -#define VISITOR_TEST_H_ - -#include <cppunit/extensions/HelperMacros.h> - -class VisitorTest : public CppUnit::TestFixture -{ - CPPUNIT_TEST_SUITE( VisitorTest ); - CPPUNIT_TEST( testPromoteVisitor ); - CPPUNIT_TEST( testSameVisitor ); - CPPUNIT_TEST( testVisitor ); - CPPUNIT_TEST_SUITE_END(); - -public: - void setUp(); - void tearDown(); - - void testPromoteVisitor(); - void testSameVisitor(); - void testVisitor(); -}; - -#endif // VISITOR_TEST_H_ diff --git a/alib2data/src/regexp/common/RegExpToXMLComposer.h b/alib2data/src/regexp/common/RegExpToXMLComposer.h index 82fbb1e72edf2f35619e07bc3e9794756b5f8128..f1dc2f030ebd852ecaef98d5630819acdf7c113b 100644 --- a/alib2data/src/regexp/common/RegExpToXMLComposer.h +++ b/alib2data/src/regexp/common/RegExpToXMLComposer.h @@ -19,7 +19,7 @@ namespace regexp { /** * This class contains methods to print XML representation of regular expression to the output stream. */ -class RegExpToXMLComposer : public UnboundedRegExpElement::const_visitor_type, public FormalRegExpElement::const_visitor_type { +class RegExpToXMLComposer : public UnboundedRegExpElementVisitor, public FormalRegExpElementVisitor { public: RegExpToXMLComposer() {} diff --git a/alib2data/src/regexp/formal/FormalRegExpAlternation.h b/alib2data/src/regexp/formal/FormalRegExpAlternation.h index 924c22adbfd3aab56304e3d32d7441529eee1610..98dd7d3e8b929988718725fdc8326d037ba0ef4d 100644 --- a/alib2data/src/regexp/formal/FormalRegExpAlternation.h +++ b/alib2data/src/regexp/formal/FormalRegExpAlternation.h @@ -23,7 +23,7 @@ class RegExpOptimize; * Represents alternation operator in the regular expression. Contains list of FormalRegExpElement * as operands of the operator. */ -class FormalRegExpAlternation : public std::acceptor < FormalRegExpAlternation, FormalRegExpElement, FormalRegExpElement > { +class FormalRegExpAlternation : public FormalRegExpElement { protected: /** * @copydoc FormalRegExpElement::clone() const @@ -49,6 +49,10 @@ protected: virtual void computeMinimalAlphabet ( std::set < alphabet::Symbol > & alphabet ) const; public: + void Accept ( void * userData, const FormalRegExpElementVisitor & visitor ) const { + visitor.Visit ( userData, * this ); + } + explicit FormalRegExpAlternation ( FormalRegExpElement && left, FormalRegExpElement && right ); explicit FormalRegExpAlternation ( const FormalRegExpElement & left, const FormalRegExpElement & right ); diff --git a/alib2data/src/regexp/formal/FormalRegExpConcatenation.h b/alib2data/src/regexp/formal/FormalRegExpConcatenation.h index 67aed5a92452efe6bf69a58e3c94fccdb01a490c..7987a22d21cb0d6d3b55e9b7e4f2c1cc71f8635c 100644 --- a/alib2data/src/regexp/formal/FormalRegExpConcatenation.h +++ b/alib2data/src/regexp/formal/FormalRegExpConcatenation.h @@ -24,7 +24,7 @@ class RegExpOptimize; * Represents concatenation operator in the regular expression. Contains list of FormalRegExpElement * as operands of the operator. */ -class FormalRegExpConcatenation : public std::acceptor < FormalRegExpConcatenation, FormalRegExpElement, FormalRegExpElement > { +class FormalRegExpConcatenation : public FormalRegExpElement { protected: /** * @copydoc FormalRegExpElement::clone() const @@ -50,6 +50,10 @@ protected: virtual void computeMinimalAlphabet ( std::set < alphabet::Symbol > & alphabet ) const; public: + void Accept ( void * userData, const FormalRegExpElementVisitor & visitor ) const { + visitor.Visit ( userData, * this ); + } + explicit FormalRegExpConcatenation ( FormalRegExpElement && left, FormalRegExpElement && right ); explicit FormalRegExpConcatenation ( const FormalRegExpElement & left, const FormalRegExpElement & right ); diff --git a/alib2data/src/regexp/formal/FormalRegExpElement.h b/alib2data/src/regexp/formal/FormalRegExpElement.h index 5a5f116dca499a19ba112a6fa5a94474bfbd6128..ab661f3ade4c51f2cc81746b37396968cc311911 100644 --- a/alib2data/src/regexp/formal/FormalRegExpElement.h +++ b/alib2data/src/regexp/formal/FormalRegExpElement.h @@ -9,7 +9,6 @@ #define FORMAL_REG_EXP_ELEMENT_H_ #include <XmlApi.hpp> -#include <core/visitor.hpp> #include "../../alphabet/Symbol.h" #include "../common/RegExpAlphabet.h" #include <set> @@ -28,12 +27,20 @@ class FormalRegExpEpsilon; class UnboundedRegExpElement; class FormalRegExpElement; +class FormalRegExpElementVisitor { +public: + virtual void Visit ( void *, const FormalRegExpAlternation & ) const = 0; + virtual void Visit ( void *, const FormalRegExpConcatenation & ) const = 0; + virtual void Visit ( void *, const FormalRegExpIteration & ) const = 0; + virtual void Visit ( void *, const FormalRegExpSymbol & ) const = 0; + virtual void Visit ( void *, const FormalRegExpEmpty & ) const = 0; + virtual void Visit ( void *, const FormalRegExpEpsilon & ) const = 0; +}; + /** * Abstract class representing element in the regular expression. Can be operator or symbol. */ -typedef std::acceptor_base < FormalRegExpElement, FormalRegExpAlternation, FormalRegExpConcatenation, FormalRegExpIteration, FormalRegExpSymbol, FormalRegExpEmpty, FormalRegExpEpsilon > VisitableFormalRegExpElement; - -class FormalRegExpElement : public alib::CommonBase < FormalRegExpElement >, public VisitableFormalRegExpElement { +class FormalRegExpElement : public alib::CommonBase < FormalRegExpElement > { protected: /* * Parent regexp contanining this instance of RegExpElement @@ -64,6 +71,8 @@ protected: virtual void computeMinimalAlphabet ( std::set < alphabet::Symbol > & alphabet ) const = 0; public: + virtual void Accept ( void * userData, const FormalRegExpElementVisitor & visitor ) const = 0; + explicit FormalRegExpElement ( ); /** diff --git a/alib2data/src/regexp/formal/FormalRegExpEmpty.h b/alib2data/src/regexp/formal/FormalRegExpEmpty.h index da9f25692cb56e5499651ff28b348ddebb722fba..fc5ac43f1c795dbdfdaab457edfd137292767d24 100644 --- a/alib2data/src/regexp/formal/FormalRegExpEmpty.h +++ b/alib2data/src/regexp/formal/FormalRegExpEmpty.h @@ -16,7 +16,7 @@ namespace regexp { /** * Represents empty regular expression in the regular expression. */ -class FormalRegExpEmpty : public std::acceptor < FormalRegExpEmpty, FormalRegExpElement, FormalRegExpElement > { +class FormalRegExpEmpty : public FormalRegExpElement { protected: /** * @copydoc FormalRegExpElement::clone() const @@ -39,6 +39,10 @@ protected: virtual void computeMinimalAlphabet ( std::set < alphabet::Symbol > & alphabet ) const; public: + void Accept ( void * userData, const FormalRegExpElementVisitor & visitor ) const { + visitor.Visit ( userData, * this ); + } + explicit FormalRegExpEmpty ( ); FormalRegExpEmpty ( const FormalRegExpEmpty & other ); FormalRegExpEmpty ( FormalRegExpEmpty && other ) noexcept; diff --git a/alib2data/src/regexp/formal/FormalRegExpEpsilon.h b/alib2data/src/regexp/formal/FormalRegExpEpsilon.h index 7376efee5ec650b42598042002ff31f70d3efff4..d291dc09e4a285bb22f5c32625a0efde58c41469 100644 --- a/alib2data/src/regexp/formal/FormalRegExpEpsilon.h +++ b/alib2data/src/regexp/formal/FormalRegExpEpsilon.h @@ -16,7 +16,7 @@ namespace regexp { /** * Represents epsilon in the regular expression. */ -class FormalRegExpEpsilon : public std::acceptor < FormalRegExpEpsilon, FormalRegExpElement, FormalRegExpElement > { +class FormalRegExpEpsilon : public FormalRegExpElement { protected: /** * @copydoc FormalRegExpElement::clone() const @@ -39,6 +39,10 @@ protected: virtual void computeMinimalAlphabet ( std::set < alphabet::Symbol > & alphabet ) const; public: + void Accept ( void * userData, const FormalRegExpElementVisitor & visitor ) const { + visitor.Visit ( userData, * this ); + } + explicit FormalRegExpEpsilon ( ); FormalRegExpEpsilon ( const FormalRegExpEpsilon & other ); FormalRegExpEpsilon ( FormalRegExpEpsilon && other ) noexcept; diff --git a/alib2data/src/regexp/formal/FormalRegExpIteration.h b/alib2data/src/regexp/formal/FormalRegExpIteration.h index 825ebd29fe34a88b275d279531536510a5e63fc1..003e48d412136bef4c93115f2b5238bc5b945027 100644 --- a/alib2data/src/regexp/formal/FormalRegExpIteration.h +++ b/alib2data/src/regexp/formal/FormalRegExpIteration.h @@ -23,7 +23,7 @@ class RegExpOptimize; * Represents iteration operator in the regular expression. Contains one FormalRegExpElement * as operand. */ -class FormalRegExpIteration : public std::acceptor < FormalRegExpIteration, FormalRegExpElement, FormalRegExpElement > { +class FormalRegExpIteration : public FormalRegExpElement { protected: FormalRegExpElement * element; @@ -48,6 +48,10 @@ protected: virtual void computeMinimalAlphabet ( std::set < alphabet::Symbol > & alphabet ) const; public: + void Accept ( void * userData, const FormalRegExpElementVisitor & visitor ) const { + visitor.Visit ( userData, * this ); + } + explicit FormalRegExpIteration ( FormalRegExpElement && ); explicit FormalRegExpIteration ( const FormalRegExpElement & ); diff --git a/alib2data/src/regexp/formal/FormalRegExpSymbol.h b/alib2data/src/regexp/formal/FormalRegExpSymbol.h index ca76c10661ce94e16a5e6431669fb9d65f8da102..d384284c02b7d880888de61f6dd2c64911a1e062 100644 --- a/alib2data/src/regexp/formal/FormalRegExpSymbol.h +++ b/alib2data/src/regexp/formal/FormalRegExpSymbol.h @@ -17,7 +17,7 @@ namespace regexp { /** * Represents symbol in the regular expression. Contains name of the symbol. */ -class FormalRegExpSymbol : public std::acceptor < FormalRegExpSymbol, FormalRegExpElement, FormalRegExpElement > { +class FormalRegExpSymbol : public FormalRegExpElement { protected: alphabet::Symbol symbol; @@ -42,6 +42,10 @@ protected: virtual void computeMinimalAlphabet ( std::set < alphabet::Symbol > & alphabet ) const; public: + void Accept ( void * userData, const FormalRegExpElementVisitor & visitor ) const { + visitor.Visit ( userData, * this ); + } + explicit FormalRegExpSymbol ( int number ); explicit FormalRegExpSymbol ( char character ); explicit FormalRegExpSymbol ( const std::string & label ); diff --git a/alib2data/src/regexp/unbounded/UnboundedRegExpAlternation.h b/alib2data/src/regexp/unbounded/UnboundedRegExpAlternation.h index 4bddc57fb8f747529ca76cdcee1c22c2d0a7151d..841658f866259fb686f6406f1fb4e1be82a1a7a7 100644 --- a/alib2data/src/regexp/unbounded/UnboundedRegExpAlternation.h +++ b/alib2data/src/regexp/unbounded/UnboundedRegExpAlternation.h @@ -23,7 +23,7 @@ class RegExpOptimize; * Represents alternation operator in the regular expression. Contains list of UnboundedRegExpElement * as operands of the operator. */ -class UnboundedRegExpAlternation : public std::acceptor < UnboundedRegExpAlternation, UnboundedRegExpElement, UnboundedRegExpElement > { +class UnboundedRegExpAlternation : public UnboundedRegExpElement { protected: /** * @copydoc UnboundedRegExpElement::cloneAsFormal() const @@ -48,6 +48,10 @@ protected: virtual void computeMinimalAlphabet ( std::set < alphabet::Symbol > & alphabet ) const; public: + void Accept ( void * userData, const UnboundedRegExpElementVisitor & visitor ) const { + visitor.Visit ( userData, * this ); + } + explicit UnboundedRegExpAlternation ( ); UnboundedRegExpAlternation ( const UnboundedRegExpAlternation & other ); diff --git a/alib2data/src/regexp/unbounded/UnboundedRegExpConcatenation.h b/alib2data/src/regexp/unbounded/UnboundedRegExpConcatenation.h index d70e0124803a0fb73db1eb2876b6bcbcf245bb03..2e6db918e30836487d48e5e4acd5b1c7d07f5512 100644 --- a/alib2data/src/regexp/unbounded/UnboundedRegExpConcatenation.h +++ b/alib2data/src/regexp/unbounded/UnboundedRegExpConcatenation.h @@ -23,7 +23,7 @@ class RegExpOptimize; * Represents concatenation operator in the regular expression. Contains list of UnboundedRegExpElement * as operands of the operator. */ -class UnboundedRegExpConcatenation : public std::acceptor < UnboundedRegExpConcatenation, UnboundedRegExpElement, UnboundedRegExpElement > { +class UnboundedRegExpConcatenation : public UnboundedRegExpElement { protected: /** * @copydoc UnboundedRegExpElement::cloneAsFormal() const @@ -48,6 +48,10 @@ protected: virtual void computeMinimalAlphabet ( std::set < alphabet::Symbol > & alphabet ) const; public: + void Accept ( void * userData, const UnboundedRegExpElementVisitor & visitor ) const { + visitor.Visit ( userData, * this ); + } + explicit UnboundedRegExpConcatenation ( ); UnboundedRegExpConcatenation ( const UnboundedRegExpConcatenation & other ); diff --git a/alib2data/src/regexp/unbounded/UnboundedRegExpElement.h b/alib2data/src/regexp/unbounded/UnboundedRegExpElement.h index 6e0e1ce597afb914d12c821b37ff09de12cc680f..fc3e032f72c858c1dce4627e44f3a3c9ae9799ae 100644 --- a/alib2data/src/regexp/unbounded/UnboundedRegExpElement.h +++ b/alib2data/src/regexp/unbounded/UnboundedRegExpElement.h @@ -9,7 +9,6 @@ #define UNBOUNDED_REG_EXP_ELEMENT_H_ #include <XmlApi.hpp> -#include <core/visitor.hpp> #include "../../alphabet/Symbol.h" #include "../common/RegExpAlphabet.h" #include <set> @@ -28,12 +27,20 @@ class UnboundedRegExpEpsilon; class FormalRegExpElement; class UnboundedRegExpElement; +class UnboundedRegExpElementVisitor { +public: + virtual void Visit ( void *, const UnboundedRegExpAlternation & ) const = 0; + virtual void Visit ( void *, const UnboundedRegExpConcatenation & ) const = 0; + virtual void Visit ( void *, const UnboundedRegExpIteration & ) const = 0; + virtual void Visit ( void *, const UnboundedRegExpSymbol & ) const = 0; + virtual void Visit ( void *, const UnboundedRegExpEmpty & ) const = 0; + virtual void Visit ( void *, const UnboundedRegExpEpsilon & ) const = 0; +}; + /** * Abstract class representing element in the regular expression. Can be operator or symbol. */ -typedef std::acceptor_base < UnboundedRegExpElement, UnboundedRegExpAlternation, UnboundedRegExpConcatenation, UnboundedRegExpIteration, UnboundedRegExpSymbol, UnboundedRegExpEmpty, UnboundedRegExpEpsilon > VisitableUnboundedRegExpElement; - -class UnboundedRegExpElement : public alib::CommonBase < UnboundedRegExpElement >, public VisitableUnboundedRegExpElement { +class UnboundedRegExpElement : public alib::CommonBase < UnboundedRegExpElement > { protected: /** * Parent regexp contanining this instance of RegExpElement @@ -64,6 +71,8 @@ protected: virtual void computeMinimalAlphabet ( std::set < alphabet::Symbol > & alphabet ) const = 0; public: + virtual void Accept ( void * userData, const UnboundedRegExpElementVisitor & visitor ) const = 0; + explicit UnboundedRegExpElement ( ); /** diff --git a/alib2data/src/regexp/unbounded/UnboundedRegExpEmpty.h b/alib2data/src/regexp/unbounded/UnboundedRegExpEmpty.h index 383ec060497c85b1148c57fc72b40ccd133891f6..14151e858a0b9ab8d74534097b122fcfc7456657 100644 --- a/alib2data/src/regexp/unbounded/UnboundedRegExpEmpty.h +++ b/alib2data/src/regexp/unbounded/UnboundedRegExpEmpty.h @@ -15,7 +15,7 @@ namespace regexp { /** * Represents empty regular expression in the regular expression. */ -class UnboundedRegExpEmpty : public std::acceptor < UnboundedRegExpEmpty, UnboundedRegExpElement, UnboundedRegExpElement > { +class UnboundedRegExpEmpty : public UnboundedRegExpElement { protected: /** * @copydoc UnboundedRegExpElement::cloneAsFormal() const @@ -38,6 +38,10 @@ protected: virtual void computeMinimalAlphabet ( std::set < alphabet::Symbol > & alphabet ) const; public: + void Accept ( void * userData, const UnboundedRegExpElementVisitor & visitor ) const { + visitor.Visit ( userData, * this ); + } + explicit UnboundedRegExpEmpty ( ); UnboundedRegExpEmpty ( const UnboundedRegExpEmpty & other ); UnboundedRegExpEmpty ( UnboundedRegExpEmpty && other ) noexcept; diff --git a/alib2data/src/regexp/unbounded/UnboundedRegExpEpsilon.h b/alib2data/src/regexp/unbounded/UnboundedRegExpEpsilon.h index d510508c92768c3b0887e05838090f1214e3f0de..4f38a7f0599a1eeb6d4f47fd6959d4e27a79093c 100644 --- a/alib2data/src/regexp/unbounded/UnboundedRegExpEpsilon.h +++ b/alib2data/src/regexp/unbounded/UnboundedRegExpEpsilon.h @@ -15,7 +15,7 @@ namespace regexp { /** * Represents epsilon in the regular expression. */ -class UnboundedRegExpEpsilon : public std::acceptor < UnboundedRegExpEpsilon, UnboundedRegExpElement, UnboundedRegExpElement > { +class UnboundedRegExpEpsilon : public UnboundedRegExpElement { protected: /** * @copydoc UnboundedRegExpElement::cloneAsFormal() const @@ -38,6 +38,10 @@ protected: virtual void computeMinimalAlphabet ( std::set < alphabet::Symbol > & alphabet ) const; public: + void Accept ( void * userData, const UnboundedRegExpElementVisitor & visitor ) const { + visitor.Visit ( userData, * this ); + } + explicit UnboundedRegExpEpsilon ( ); UnboundedRegExpEpsilon ( const UnboundedRegExpEpsilon & other ); UnboundedRegExpEpsilon ( UnboundedRegExpEpsilon && other ) noexcept; diff --git a/alib2data/src/regexp/unbounded/UnboundedRegExpIteration.h b/alib2data/src/regexp/unbounded/UnboundedRegExpIteration.h index 797182fabba8773d6832648bff9946ecf943fe39..605f9871276f3267cf86d9b19453a83824df8950 100644 --- a/alib2data/src/regexp/unbounded/UnboundedRegExpIteration.h +++ b/alib2data/src/regexp/unbounded/UnboundedRegExpIteration.h @@ -23,7 +23,7 @@ class RegExpOptimize; * Represents iteration operator in the regular expression. Contains one UnboundedRegExpElement * as operand. */ -class UnboundedRegExpIteration : public std::acceptor < UnboundedRegExpIteration, UnboundedRegExpElement, UnboundedRegExpElement > { +class UnboundedRegExpIteration : public UnboundedRegExpElement { protected: UnboundedRegExpElement * element; @@ -48,6 +48,10 @@ protected: virtual void computeMinimalAlphabet ( std::set < alphabet::Symbol > & alphabet ) const; public: + void Accept ( void * userData, const UnboundedRegExpElementVisitor & visitor ) const { + visitor.Visit ( userData, * this ); + } + explicit UnboundedRegExpIteration ( UnboundedRegExpElement && ); explicit UnboundedRegExpIteration ( const UnboundedRegExpElement & ); diff --git a/alib2data/src/regexp/unbounded/UnboundedRegExpSymbol.h b/alib2data/src/regexp/unbounded/UnboundedRegExpSymbol.h index d673e669b011215f0197d4367c3de22d880db57f..7526910f9e657e49eefde659b1a4aa765e038389 100644 --- a/alib2data/src/regexp/unbounded/UnboundedRegExpSymbol.h +++ b/alib2data/src/regexp/unbounded/UnboundedRegExpSymbol.h @@ -17,7 +17,7 @@ namespace regexp { /** * Represents symbol in the regular expression. Contains name of the symbol. */ -class UnboundedRegExpSymbol : public std::acceptor < UnboundedRegExpSymbol, UnboundedRegExpElement, UnboundedRegExpElement > { +class UnboundedRegExpSymbol : public UnboundedRegExpElement { protected: alphabet::Symbol symbol; @@ -42,6 +42,10 @@ protected: virtual void computeMinimalAlphabet ( std::set < alphabet::Symbol > & alphabet ) const; public: + void Accept ( void * userData, const UnboundedRegExpElementVisitor & visitor ) const { + visitor.Visit ( userData, * this ); + } + explicit UnboundedRegExpSymbol ( int number ); explicit UnboundedRegExpSymbol ( char character ); explicit UnboundedRegExpSymbol ( const std::string & label ); diff --git a/alib2str/src/regexp/RegExpToStringComposer.h b/alib2str/src/regexp/RegExpToStringComposer.h index a2f176a70cea3b5f98bd85eca97be16b9f696394..2fa525e37c17e1bd71045366aec7441e06806d22 100644 --- a/alib2str/src/regexp/RegExpToStringComposer.h +++ b/alib2str/src/regexp/RegExpToStringComposer.h @@ -16,7 +16,7 @@ namespace regexp { -class RegExpToStringComposer : public std::SingleDispatchFirstStaticParam<void, std::ostream&, RegExpBase>, UnboundedRegExpElement::const_visitor_type, FormalRegExpElement::const_visitor_type { +class RegExpToStringComposer : public std::SingleDispatchFirstStaticParam<void, std::ostream&, RegExpBase>, UnboundedRegExpElementVisitor, FormalRegExpElementVisitor { private: void Visit(void*, const UnboundedRegExpAlternation& alternation) const; void Visit(void*, const UnboundedRegExpConcatenation& concatenation) const;