From 422bd726a4ee5bf97130e04b81307288a21b3476 Mon Sep 17 00:00:00 2001
From: Jan Travnicek <Jan.Travnicek@fit.cvut.cz>
Date: Sun, 20 Nov 2016 22:14:25 +0100
Subject: [PATCH] template RegExpEmpty algorithm

---
 .../src/regexp/properties/RegExpEmpty.cpp     |  87 ----------
 alib2algo/src/regexp/properties/RegExpEmpty.h | 152 +++++++++++++++---
 2 files changed, 134 insertions(+), 105 deletions(-)

diff --git a/alib2algo/src/regexp/properties/RegExpEmpty.cpp b/alib2algo/src/regexp/properties/RegExpEmpty.cpp
index c15d9bf123..f1a432c477 100644
--- a/alib2algo/src/regexp/properties/RegExpEmpty.cpp
+++ b/alib2algo/src/regexp/properties/RegExpEmpty.cpp
@@ -17,96 +17,9 @@ bool RegExpEmpty::languageIsEmpty(const regexp::RegExp& regexp) {
 	return dispatch(regexp.getData());
 }
 
-bool RegExpEmpty::languageIsEmpty(const regexp::FormalRegExpElement < alphabet::Symbol > & regexp) {
-	return regexp.accept < bool, RegExpEmpty::Formal > ( );
-}
-
-bool RegExpEmpty::languageIsEmpty(const regexp::FormalRegExpStructure < alphabet::Symbol > & regexp) {
-	return languageIsEmpty(regexp.getStructure());
-}
-
-bool RegExpEmpty::languageIsEmpty(const regexp::FormalRegExp < > & regexp) {
-	return languageIsEmpty(regexp.getRegExp());
-}
-
 auto RegExpEmptyFormalRegExp = RegExpEmpty::RegistratorWrapper<bool, regexp::FormalRegExp < > >( RegExpEmpty::languageIsEmpty);
-
-bool RegExpEmpty::languageIsEmpty(const regexp::UnboundedRegExpElement < alphabet::Symbol > & regexp) {
-	return regexp.accept < bool, RegExpEmpty::Unbounded > ( );
-}
-
-bool RegExpEmpty::languageIsEmpty(const regexp::UnboundedRegExpStructure < alphabet::Symbol > & regexp) {
-	return languageIsEmpty(regexp.getStructure());
-}
-
-bool RegExpEmpty::languageIsEmpty(const regexp::UnboundedRegExp < > & regexp) {
-	return languageIsEmpty(regexp.getRegExp());
-}
-
 auto RegExpEmptyUnboundedRegExp = RegExpEmpty::RegistratorWrapper<bool, regexp::UnboundedRegExp < > >( RegExpEmpty::languageIsEmpty);
 
-// ----------------------------------------------------------------------------
-
-bool RegExpEmpty::Unbounded::visit(const regexp::UnboundedRegExpAlternation < alphabet::Symbol > & alternation) {
-	for(const auto& element : alternation.getElements()) {
-		if(! element->accept < bool, RegExpEmpty::Unbounded > ( ) ) {
-			return false;
-		}
-	}
-	return true;
-}
-
-bool RegExpEmpty::Unbounded::visit(const regexp::UnboundedRegExpConcatenation < alphabet::Symbol > & concatenation) {
-	for(const auto& element : concatenation.getElements()) {
-		if( element->accept < bool, RegExpEmpty::Unbounded > ( ) ) {
-			return true;
-		}
-	}
-	return false;
-}
-
-bool RegExpEmpty::Unbounded::visit(const regexp::UnboundedRegExpIteration < alphabet::Symbol > &) {
-	return false;
-}
-
-bool RegExpEmpty::Unbounded::visit(const regexp::UnboundedRegExpSymbol < alphabet::Symbol > &) {
-	return false;
-}
-
-bool RegExpEmpty::Unbounded::visit(const regexp::UnboundedRegExpEmpty < alphabet::Symbol > &) {
-	return true;
-}
-
-bool RegExpEmpty::Unbounded::visit(const regexp::UnboundedRegExpEpsilon < alphabet::Symbol > &) {
-	return false;
-}
-
-// ----------------------------------------------------------------------------
-
-bool RegExpEmpty::Formal::visit(const regexp::FormalRegExpAlternation < alphabet::Symbol > & alternation) {
-	return alternation.getLeftElement().accept < bool, RegExpEmpty::Formal > ( ) && alternation.getRightElement().accept < bool, RegExpEmpty::Formal > ( );
-}
-
-bool RegExpEmpty::Formal::visit(const regexp::FormalRegExpConcatenation < alphabet::Symbol > & concatenation) {
-	return concatenation.getLeftElement().accept < bool, RegExpEmpty::Formal > ( ) || concatenation.getRightElement().accept < bool, RegExpEmpty::Formal > ( );
-}
-
-bool RegExpEmpty::Formal::visit(const regexp::FormalRegExpIteration < alphabet::Symbol > &) {
-	return false;
-}
-
-bool RegExpEmpty::Formal::visit(const regexp::FormalRegExpSymbol < alphabet::Symbol > &) {
-	return false;
-}
-
-bool RegExpEmpty::Formal::visit(const regexp::FormalRegExpEmpty < alphabet::Symbol > &) {
-	return true;
-}
-
-bool RegExpEmpty::Formal::visit(const regexp::FormalRegExpEpsilon < alphabet::Symbol > &) {
-	return false;
-}
-
 } /* namespace properties */
 
 } /* namespace regexp */
diff --git a/alib2algo/src/regexp/properties/RegExpEmpty.h b/alib2algo/src/regexp/properties/RegExpEmpty.h
index 30871d0b9f..3c6853e54c 100644
--- a/alib2algo/src/regexp/properties/RegExpEmpty.h
+++ b/alib2algo/src/regexp/properties/RegExpEmpty.h
@@ -28,36 +28,152 @@ class RegExpEmpty : public std::SingleDispatch<RegExpEmpty, bool, const regexp::
 public:
 	static bool languageIsEmpty(const regexp::RegExp& regexp);
 
-	static bool languageIsEmpty(const regexp::FormalRegExpElement < alphabet::Symbol > & regexp);
-	static bool languageIsEmpty(const regexp::FormalRegExpStructure < alphabet::Symbol > & regexp);
-	static bool languageIsEmpty(const regexp::FormalRegExp < > & regexp);
+	template < class SymbolType >
+	static bool languageIsEmpty(const regexp::FormalRegExpElement < SymbolType > & regexp);
+	template < class SymbolType >
+	static bool languageIsEmpty(const regexp::FormalRegExpStructure < SymbolType > & regexp);
+	template < class SymbolType >
+	static bool languageIsEmpty(const regexp::FormalRegExp < SymbolType > & regexp);
 
-	static bool languageIsEmpty(const regexp::UnboundedRegExpElement < alphabet::Symbol > & regexp);
-	static bool languageIsEmpty(const regexp::UnboundedRegExpStructure < alphabet::Symbol > & regexp);
-	static bool languageIsEmpty(const regexp::UnboundedRegExp < > & regexp);
+	template < class SymbolType >
+	static bool languageIsEmpty(const regexp::UnboundedRegExpElement < SymbolType > & regexp);
+	template < class SymbolType >
+	static bool languageIsEmpty(const regexp::UnboundedRegExpStructure < SymbolType > & regexp);
+	template < class SymbolType >
+	static bool languageIsEmpty(const regexp::UnboundedRegExp < SymbolType > & regexp);
 
+	template < class SymbolType >
 	class Unbounded {
 	public:
-		static bool visit(const regexp::UnboundedRegExpAlternation < alphabet::Symbol > & alternation);
-		static bool visit(const regexp::UnboundedRegExpConcatenation < alphabet::Symbol > & concatenation);
-		static bool visit(const regexp::UnboundedRegExpIteration < alphabet::Symbol > & iteration);
-		static bool visit(const regexp::UnboundedRegExpSymbol < alphabet::Symbol > & symbol);
-		static bool visit(const regexp::UnboundedRegExpEmpty < alphabet::Symbol > & empty);
-		static bool visit(const regexp::UnboundedRegExpEpsilon < alphabet::Symbol > & epsilon);
+		static bool visit(const regexp::UnboundedRegExpAlternation < SymbolType > & alternation);
+		static bool visit(const regexp::UnboundedRegExpConcatenation < SymbolType > & concatenation);
+		static bool visit(const regexp::UnboundedRegExpIteration < SymbolType > & iteration);
+		static bool visit(const regexp::UnboundedRegExpSymbol < SymbolType > & symbol);
+		static bool visit(const regexp::UnboundedRegExpEmpty < SymbolType > & empty);
+		static bool visit(const regexp::UnboundedRegExpEpsilon < SymbolType > & epsilon);
 	};
 
+	template < class SymbolType >
 	class Formal {
 	public:
-		static bool visit(const regexp::FormalRegExpAlternation < alphabet::Symbol > & alternation);
-		static bool visit(const regexp::FormalRegExpConcatenation < alphabet::Symbol > & concatenation);
-		static bool visit(const regexp::FormalRegExpIteration < alphabet::Symbol > & iteration);
-		static bool visit(const regexp::FormalRegExpSymbol < alphabet::Symbol > & symbol);
-		static bool visit(const regexp::FormalRegExpEmpty < alphabet::Symbol > & empty);
-		static bool visit(const regexp::FormalRegExpEpsilon < alphabet::Symbol > & epsilon);
+		static bool visit(const regexp::FormalRegExpAlternation < SymbolType > & alternation);
+		static bool visit(const regexp::FormalRegExpConcatenation < SymbolType > & concatenation);
+		static bool visit(const regexp::FormalRegExpIteration < SymbolType > & iteration);
+		static bool visit(const regexp::FormalRegExpSymbol < SymbolType > & symbol);
+		static bool visit(const regexp::FormalRegExpEmpty < SymbolType > & empty);
+		static bool visit(const regexp::FormalRegExpEpsilon < SymbolType > & epsilon);
 	};
 
 };
 
+// ----------------------------------------------------------------------------
+
+template < class SymbolType >
+bool RegExpEmpty::languageIsEmpty(const regexp::FormalRegExpElement < SymbolType > & regexp) {
+	return regexp.template accept < bool, RegExpEmpty::Formal < SymbolType > > ( );
+}
+
+template < class SymbolType >
+bool RegExpEmpty::languageIsEmpty(const regexp::FormalRegExpStructure < SymbolType > & regexp) {
+	return languageIsEmpty(regexp.getStructure());
+}
+
+template < class SymbolType >
+bool RegExpEmpty::languageIsEmpty(const regexp::FormalRegExp < SymbolType > & regexp) {
+	return languageIsEmpty(regexp.getRegExp());
+}
+
+// ----------------------------------------------------------------------------
+
+template < class SymbolType >
+bool RegExpEmpty::languageIsEmpty(const regexp::UnboundedRegExpElement < SymbolType > & regexp) {
+	return regexp.template accept < bool, RegExpEmpty::Unbounded < SymbolType > > ( );
+}
+
+template < class SymbolType >
+bool RegExpEmpty::languageIsEmpty(const regexp::UnboundedRegExpStructure < SymbolType > & regexp) {
+	return languageIsEmpty(regexp.getStructure());
+}
+
+template < class SymbolType >
+bool RegExpEmpty::languageIsEmpty(const regexp::UnboundedRegExp < SymbolType > & regexp) {
+	return languageIsEmpty(regexp.getRegExp());
+}
+
+// ----------------------------------------------------------------------------
+
+template < class SymbolType >
+bool RegExpEmpty::Unbounded< SymbolType >::visit(const regexp::UnboundedRegExpAlternation < SymbolType > & alternation) {
+	for(const auto& element : alternation.getElements()) {
+		if(! element->template accept < bool, RegExpEmpty::Unbounded < SymbolType > > ( ) ) {
+			return false;
+		}
+	}
+	return true;
+}
+
+template < class SymbolType >
+bool RegExpEmpty::Unbounded< SymbolType >::visit(const regexp::UnboundedRegExpConcatenation < SymbolType > & concatenation) {
+	for(const auto& element : concatenation.getElements()) {
+		if( element->template accept < bool, RegExpEmpty::Unbounded < SymbolType > > ( ) ) {
+			return true;
+		}
+	}
+	return false;
+}
+
+template < class SymbolType >
+bool RegExpEmpty::Unbounded< SymbolType >::visit(const regexp::UnboundedRegExpIteration < SymbolType > &) {
+	return false;
+}
+
+template < class SymbolType >
+bool RegExpEmpty::Unbounded< SymbolType >::visit(const regexp::UnboundedRegExpSymbol < SymbolType > &) {
+	return false;
+}
+
+template < class SymbolType >
+bool RegExpEmpty::Unbounded< SymbolType >::visit(const regexp::UnboundedRegExpEmpty < SymbolType > &) {
+	return true;
+}
+
+template < class SymbolType >
+bool RegExpEmpty::Unbounded< SymbolType >::visit(const regexp::UnboundedRegExpEpsilon < SymbolType > &) {
+	return false;
+}
+
+// ----------------------------------------------------------------------------
+
+template < class SymbolType >
+bool RegExpEmpty::Formal< SymbolType >::visit(const regexp::FormalRegExpAlternation < SymbolType > & alternation) {
+	return alternation.getLeftElement().template accept < bool, RegExpEmpty::Formal < SymbolType > > ( ) && alternation.getRightElement().template accept < bool, RegExpEmpty::Formal < SymbolType > > ( );
+}
+
+template < class SymbolType >
+bool RegExpEmpty::Formal< SymbolType >::visit(const regexp::FormalRegExpConcatenation < SymbolType > & concatenation) {
+	return concatenation.getLeftElement().template accept < bool, RegExpEmpty::Formal < SymbolType > > ( ) || concatenation.getRightElement().template accept < bool, RegExpEmpty::Formal < SymbolType > > ( );
+}
+
+template < class SymbolType >
+bool RegExpEmpty::Formal< SymbolType >::visit(const regexp::FormalRegExpIteration < SymbolType > &) {
+	return false;
+}
+
+template < class SymbolType >
+bool RegExpEmpty::Formal< SymbolType >::visit(const regexp::FormalRegExpSymbol < SymbolType > &) {
+	return false;
+}
+
+template < class SymbolType >
+bool RegExpEmpty::Formal< SymbolType >::visit(const regexp::FormalRegExpEmpty < SymbolType > &) {
+	return true;
+}
+
+template < class SymbolType >
+bool RegExpEmpty::Formal< SymbolType >::visit(const regexp::FormalRegExpEpsilon < SymbolType > &) {
+	return false;
+}
+
 } /* namespace properties */
 
 } /* namespace regexp */
-- 
GitLab