From c054165639c52049447b6e3f31c892d0ee972bb1 Mon Sep 17 00:00:00 2001
From: Jan Travnicek <Jan.Travnicek@fit.cvut.cz>
Date: Tue, 25 Feb 2014 18:53:04 +0100
Subject: [PATCH] simplification of operators of regexps

---
 alib/src/regexp/Alternation.cpp   | 31 ---------------------------
 alib/src/regexp/Alternation.h     |  5 -----
 alib/src/regexp/Concatenation.cpp | 35 -------------------------------
 alib/src/regexp/Concatenation.h   |  6 ------
 alib/src/regexp/Iteration.cpp     | 16 --------------
 alib/src/regexp/Iteration.h       |  4 ----
 alib/src/regexp/RegExp.cpp        |  8 +++++++
 alib/src/regexp/RegExp.h          |  2 ++
 alib/src/regexp/RegExpElement.cpp | 34 +++++++-----------------------
 alib/src/regexp/RegExpElement.h   |  9 ++------
 alib/src/regexp/RegExpEpsilon.cpp |  4 ----
 alib/src/regexp/RegExpEpsilon.h   |  1 -
 alib/src/regexp/RegExpSymbol.cpp  | 12 -----------
 alib/src/regexp/RegExpSymbol.h    |  3 ---
 14 files changed, 20 insertions(+), 150 deletions(-)

diff --git a/alib/src/regexp/Alternation.cpp b/alib/src/regexp/Alternation.cpp
index 0a02374c60..1c557224ef 100644
--- a/alib/src/regexp/Alternation.cpp
+++ b/alib/src/regexp/Alternation.cpp
@@ -98,37 +98,6 @@ bool Alternation::operator==(const Alternation& other) const {
 	return true;
 }
 
-bool Alternation::operator>(const Alternation& other) const {
-	int thisSize = this->elements.size();
-	int otherSize = other.elements.size();
-	if(thisSize < otherSize) return false;
-	if(thisSize > otherSize) return true;
-
-	auto thisIter = this->elements.begin();
-	auto otherIter = other.elements.begin();
-	for(; thisIter != this->elements.end(); thisIter++, otherIter++) {
-	  if(**thisIter > **otherIter) return true;
-	}
-
-	return false;
-}
-
-bool Alternation::operator>(const Iteration&) const {
-	return true;
-}
-
-bool Alternation::operator>(const RegExpSymbol&) const {
-	return true;
-}
-
-bool Alternation::operator>(const RegExpEpsilon&) const {
-	return true;
-}
-
-bool Alternation::operator>(const RegExpEmpty&) const {
-	return true;
-}
-
 bool Alternation::containsEmptyString() const {
 	for(const auto& e : getElements())
 		if(e->containsEmptyString())
diff --git a/alib/src/regexp/Alternation.h b/alib/src/regexp/Alternation.h
index cfeb34d639..52b8f8c184 100644
--- a/alib/src/regexp/Alternation.h
+++ b/alib/src/regexp/Alternation.h
@@ -50,11 +50,6 @@ public:
 	virtual bool operator<(const Concatenation&) const;
 	virtual bool operator<(const Alternation&) const;
 	virtual bool operator==(const Alternation&) const;
-	virtual bool operator>(const Alternation&) const;
-	virtual bool operator>(const Iteration&) const;
-	virtual bool operator>(const RegExpSymbol&) const;
-	virtual bool operator>(const RegExpEpsilon&) const;
-	virtual bool operator>(const RegExpEmpty&) const;
 
 	/**
 	 * @copydoc RegExpElement::containsEmptyString() const
diff --git a/alib/src/regexp/Concatenation.cpp b/alib/src/regexp/Concatenation.cpp
index 623d2102f5..c43e767dfd 100644
--- a/alib/src/regexp/Concatenation.cpp
+++ b/alib/src/regexp/Concatenation.cpp
@@ -94,41 +94,6 @@ bool Concatenation::operator==(const Concatenation& other) const {
 	return true;
 }
 
-bool Concatenation::operator>(const Concatenation& other) const {
-	int thisSize = this->elements.size();
-	int otherSize = other.elements.size();
-	if(thisSize < otherSize) return false;
-	if(thisSize > otherSize) return true;
-
-	auto thisIter = this->elements.begin();
-	auto otherIter = other.elements.begin();
-	for(; thisIter != this->elements.end(); thisIter++, otherIter++) {
-	  if(**thisIter > **otherIter) return true;
-	}
-
-	return false;
-}
-
-bool Concatenation::operator>(const Alternation&) const {
-	return true;
-}
-
-bool Concatenation::operator>(const Iteration&) const {
-	return true;
-}
-
-bool Concatenation::operator>(const RegExpSymbol&) const {
-	return true;
-}
-
-bool Concatenation::operator>(const RegExpEpsilon&) const {
-	return true;
-}
-
-bool Concatenation::operator>(const RegExpEmpty&) const {
-	return true;
-}
-
 bool Concatenation::containsEmptyString() const {
 	for( const auto& e : getElements())
 		if( ! e->containsEmptyString())
diff --git a/alib/src/regexp/Concatenation.h b/alib/src/regexp/Concatenation.h
index e35d05eac2..9fead277d3 100644
--- a/alib/src/regexp/Concatenation.h
+++ b/alib/src/regexp/Concatenation.h
@@ -49,12 +49,6 @@ public:
 
 	virtual bool operator<(const Concatenation&) const;
 	virtual bool operator==(const Concatenation&) const;
-	virtual bool operator>(const Concatenation&) const;
-	virtual bool operator>(const Alternation&) const;
-	virtual bool operator>(const Iteration&) const;
-	virtual bool operator>(const RegExpSymbol&) const;
-	virtual bool operator>(const RegExpEpsilon&) const;
-	virtual bool operator>(const RegExpEmpty&) const;
 
 	/**
 	 * @copydoc RegExpElement::containsEmptyString() const
diff --git a/alib/src/regexp/Iteration.cpp b/alib/src/regexp/Iteration.cpp
index 61e38b6f32..85e68a1025 100644
--- a/alib/src/regexp/Iteration.cpp
+++ b/alib/src/regexp/Iteration.cpp
@@ -93,22 +93,6 @@ bool Iteration::operator==(const Iteration& other) const {
 	return *(this->element) == *(other.element);
 }
 
-bool Iteration::operator>(const Iteration& other) const {
-	return *(this->element) > *(other.element);
-}
-
-bool Iteration::operator>(const RegExpSymbol&) const {
-	return true;
-}
-
-bool Iteration::operator>(const RegExpEpsilon&) const {
-	return true;
-}
-
-bool Iteration::operator>(const RegExpEmpty&) const {
-	return true;
-}
-
 bool Iteration::containsEmptyString() const {
 	return true;
 }
diff --git a/alib/src/regexp/Iteration.h b/alib/src/regexp/Iteration.h
index ab34a89deb..7466b2aedc 100644
--- a/alib/src/regexp/Iteration.h
+++ b/alib/src/regexp/Iteration.h
@@ -57,10 +57,6 @@ public:
 	virtual bool operator<(const Alternation&) const;
 	virtual bool operator<(const Iteration&) const;
 	virtual bool operator==(const Iteration&) const;
-	virtual bool operator>(const Iteration&) const;
-	virtual bool operator>(const RegExpSymbol&) const;
-	virtual bool operator>(const RegExpEpsilon&) const;
-	virtual bool operator>(const RegExpEmpty&) const;
 
 	/**
 	 * @copydoc RegExpElement::containsEmptyString() const
diff --git a/alib/src/regexp/RegExp.cpp b/alib/src/regexp/RegExp.cpp
index 3d8f2dbe13..621b004152 100644
--- a/alib/src/regexp/RegExp.cpp
+++ b/alib/src/regexp/RegExp.cpp
@@ -94,6 +94,10 @@ bool RegExp::operator<(const RegExp& other) const {
 	return *(this->regExp) < *(other.regExp);
 }
 
+bool RegExp::operator<=(const RegExp& other) const {
+	return *(this->regExp) <= *(other.regExp);
+}
+
 bool RegExp::operator==(const RegExp& other) const {
 	return *(this->regExp) == *(other.regExp);
 }
@@ -106,4 +110,8 @@ bool RegExp::operator>(const RegExp& other) const {
 	return *(this->regExp) > *(other.regExp);
 }
 
+bool RegExp::operator>=(const RegExp& other) const {
+	return *(this->regExp) >= *(other.regExp);
+}
+
 } /* namespace regexp */
diff --git a/alib/src/regexp/RegExp.h b/alib/src/regexp/RegExp.h
index 36b5de12ad..f16133cc5f 100644
--- a/alib/src/regexp/RegExp.h
+++ b/alib/src/regexp/RegExp.h
@@ -79,9 +79,11 @@ public:
 	friend ostream& operator<<(ostream& out, RegExp& regexp);
 
 	bool operator<(const RegExp&) const;
+	bool operator<=(const RegExp&) const;
 	bool operator==(const RegExp&) const;
 	bool operator!=(const RegExp&) const;
 	bool operator>(const RegExp&) const;
+	bool operator>=(const RegExp&) const;
 };
 
 } /* namespace regexp */
diff --git a/alib/src/regexp/RegExpElement.cpp b/alib/src/regexp/RegExpElement.cpp
index 4b1cfb8834..fc07c4c1f0 100644
--- a/alib/src/regexp/RegExpElement.cpp
+++ b/alib/src/regexp/RegExpElement.cpp
@@ -13,6 +13,14 @@ RegExpElement::~RegExpElement() {
 
 }
 
+bool RegExpElement::operator>=(const RegExpElement& other) const {
+	return !(*this < other);
+}
+
+bool RegExpElement::operator<=(const RegExpElement& other) const {
+	return !(*this > other);
+}
+
 bool RegExpElement::operator!=(const RegExpElement& other) const {
 	return !(*this == other);
 }
@@ -63,34 +71,8 @@ bool RegExpElement::operator==(const RegExpEpsilon& other) const {
 	return false;
 }
 
-
 bool RegExpElement::operator==(const RegExpEmpty& other) const {
 	return false;
 }
 
-bool RegExpElement::operator>(const Concatenation& other) const {
-	return false;
-}
-
-bool RegExpElement::operator>(const Alternation& other) const {
-	return false;
-}
-
-bool RegExpElement::operator>(const Iteration& other) const {
-	return false;
-}
-
-bool RegExpElement::operator>(const RegExpSymbol& other) const {
-	return false;
-}
-
-bool RegExpElement::operator>(const RegExpEpsilon& other) const {
-	return false;
-}
-
-bool RegExpElement::operator>(const RegExpEmpty& other) const {
-	return false;
-}
-
 } /* namespace regexp */
-
diff --git a/alib/src/regexp/RegExpElement.h b/alib/src/regexp/RegExpElement.h
index 206c80759d..69421fde01 100644
--- a/alib/src/regexp/RegExpElement.h
+++ b/alib/src/regexp/RegExpElement.h
@@ -37,6 +37,8 @@ public:
 	virtual bool operator==(const RegExpElement&) const = 0;
 	virtual bool operator>(const RegExpElement&) const = 0;
 
+	virtual bool operator>=(const RegExpElement&) const;
+	virtual bool operator<=(const RegExpElement&) const;
 	virtual bool operator!=(const RegExpElement&) const;
 
 	virtual bool operator<(const Concatenation&) const;
@@ -53,13 +55,6 @@ public:
 	virtual bool operator==(const RegExpEpsilon&) const;
 	virtual bool operator==(const RegExpEmpty&) const;
 
-	virtual bool operator>(const Concatenation&) const;
-	virtual bool operator>(const Alternation&) const;
-	virtual bool operator>(const Iteration&) const;
-	virtual bool operator>(const RegExpSymbol&) const;
-	virtual bool operator>(const RegExpEpsilon&) const;
-	virtual bool operator>(const RegExpEmpty&) const;
-
 	/**
 	 * @return true if this subtree of regexp matches empty string (epsilon)
 	 */
diff --git a/alib/src/regexp/RegExpEpsilon.cpp b/alib/src/regexp/RegExpEpsilon.cpp
index 8909db8053..ff8fbb4b12 100644
--- a/alib/src/regexp/RegExpEpsilon.cpp
+++ b/alib/src/regexp/RegExpEpsilon.cpp
@@ -49,10 +49,6 @@ bool RegExpEpsilon::operator==(const RegExpEpsilon&) const {
 	  return true;
 }
 
-bool RegExpEpsilon::operator>(const RegExpEmpty&) const {
-	  return true;
-}
-
 bool RegExpEpsilon::containsEmptyString() const {
 	return true;
 }
diff --git a/alib/src/regexp/RegExpEpsilon.h b/alib/src/regexp/RegExpEpsilon.h
index 351df1bde6..a7dced2eaf 100644
--- a/alib/src/regexp/RegExpEpsilon.h
+++ b/alib/src/regexp/RegExpEpsilon.h
@@ -37,7 +37,6 @@ public:
 	virtual bool operator<(const Iteration&) const;
 	virtual bool operator<(const RegExpSymbol&) const;
 	virtual bool operator==(const RegExpEpsilon&) const;
-	virtual bool operator>(const RegExpEmpty&) const;
 
 	/**
 	 * @copydoc RegExpElement::containsEmptyString() const
diff --git a/alib/src/regexp/RegExpSymbol.cpp b/alib/src/regexp/RegExpSymbol.cpp
index 75a109e770..2283563829 100644
--- a/alib/src/regexp/RegExpSymbol.cpp
+++ b/alib/src/regexp/RegExpSymbol.cpp
@@ -54,18 +54,6 @@ bool RegExpSymbol::operator==(const RegExpSymbol& other) const {
 	return this->symbol == other.symbol;
 }
 
-bool RegExpSymbol::operator>(const RegExpSymbol& other) const {
-	return this->symbol > other.symbol;
-}
-
-bool RegExpSymbol::operator>(const RegExpEpsilon&) const {
-	return true;
-}
-
-bool RegExpSymbol::operator>(const RegExpEmpty&) const {
-	return true;
-}
-
 bool RegExpSymbol::containsEmptyString() const {
 	return false;
 }
diff --git a/alib/src/regexp/RegExpSymbol.h b/alib/src/regexp/RegExpSymbol.h
index 6ea3028565..1c337bc115 100644
--- a/alib/src/regexp/RegExpSymbol.h
+++ b/alib/src/regexp/RegExpSymbol.h
@@ -40,9 +40,6 @@ public:
 	virtual bool operator<(const Iteration&) const;
 	virtual bool operator<(const RegExpSymbol&) const;
 	virtual bool operator==(const RegExpSymbol&) const;
-	virtual bool operator>(const RegExpSymbol&) const;
-	virtual bool operator>(const RegExpEpsilon&) const;
-	virtual bool operator>(const RegExpEmpty&) const;
 
 
 	/**
-- 
GitLab