From 795b5c68499819eace5bbdb7f630ab3f2e7fa368 Mon Sep 17 00:00:00 2001
From: Jan Travnicek <Jan.Travnicek@fit.cvut.cz>
Date: Sun, 4 May 2014 20:09:20 +0200
Subject: [PATCH] operator of assignment

---
 alib2/src/regexp/Alternation.cpp   | 25 +++++++++++++------------
 alib2/src/regexp/Alternation.h     |  2 +-
 alib2/src/regexp/Concatenation.cpp |  6 +++++-
 alib2/src/regexp/Concatenation.h   |  2 +-
 alib2/src/regexp/Iteration.cpp     |  7 +++++--
 alib2/src/regexp/Iteration.h       |  2 +-
 alib2/src/regexp/RegExpEmpty.cpp   | 18 ++++++++++++++++--
 alib2/src/regexp/RegExpEmpty.h     |  5 ++++-
 alib2/src/regexp/RegExpEpsilon.cpp | 18 ++++++++++++++++--
 alib2/src/regexp/RegExpEpsilon.h   |  5 ++++-
 alib2/src/regexp/RegExpSymbol.cpp  | 21 ++++++++++++++++++++-
 alib2/src/regexp/RegExpSymbol.h    |  4 +++-
 12 files changed, 89 insertions(+), 26 deletions(-)

diff --git a/alib2/src/regexp/Alternation.cpp b/alib2/src/regexp/Alternation.cpp
index b7de7ca6d7..1cf04c9af4 100644
--- a/alib2/src/regexp/Alternation.cpp
+++ b/alib2/src/regexp/Alternation.cpp
@@ -10,7 +10,6 @@
 
 namespace regexp {
 
-
 Alternation::Alternation(RegExpElement&& left, RegExpElement&& right) {
 	appendElement(std::move(left));
 	appendElement(std::move(right));
@@ -42,9 +41,12 @@ Alternation& Alternation::operator=(const Alternation& other) {
 	return *this;
 }
 
-Alternation& Alternation::operator=(Alternation&& other) noexcept {
+Alternation& Alternation::operator=(Alternation&& other) {
 	std::swap(this->elements, other.elements);
-	  
+	std::swap(this->parentRegExp, other.parentRegExp);
+	
+	this->attachRegExp(other.parentRegExp);
+	
 	return *this;
 }
 
@@ -126,6 +128,14 @@ bool Alternation::operator==(const Alternation& other) const {
 	return true;
 }
 
+void Alternation::operator>>(std::ostream& out) const {
+	out << "(Alternation";
+	for(const auto& e : elements)
+		out << " " << *e;
+
+	out << ")";
+}
+
 bool Alternation::testSymbol( const alphabet::Symbol & symbol ) const {
 	for(const auto& child : this->elements)
 		if(child->testSymbol(symbol)) return true;
@@ -146,14 +156,6 @@ void Alternation::computeMinimalAlphabet( std::set<alphabet::Symbol>& alphabet )
 		child->computeMinimalAlphabet(alphabet);
 }
 
-void Alternation::operator>>(std::ostream& out) const {
-	out << "(Alternation";
-	for(const auto& e : elements)
-		out << " " << *e;
-
-	out << ")";
-}
-
 bool Alternation::containsEmptyString() const {
 	for(const auto& e : elements)
 		if(e->containsEmptyString())
@@ -171,4 +173,3 @@ bool Alternation::isEmpty() const {
 }
 
 } /* namespace regexp */
-
diff --git a/alib2/src/regexp/Alternation.h b/alib2/src/regexp/Alternation.h
index 75fc1e3c5a..5424fe016e 100644
--- a/alib2/src/regexp/Alternation.h
+++ b/alib2/src/regexp/Alternation.h
@@ -53,7 +53,7 @@ public:
 	Alternation(const Alternation& other);
 	Alternation(Alternation&& other) noexcept;
 	Alternation& operator =(const Alternation& other);
-	Alternation& operator =(Alternation&& other) noexcept;
+	Alternation& operator =(Alternation&& other);
 	virtual ~Alternation() noexcept;
 	
 	/**
diff --git a/alib2/src/regexp/Concatenation.cpp b/alib2/src/regexp/Concatenation.cpp
index 4faa19cd58..8b3aee33c2 100644
--- a/alib2/src/regexp/Concatenation.cpp
+++ b/alib2/src/regexp/Concatenation.cpp
@@ -41,9 +41,12 @@ Concatenation& Concatenation::operator=(const Concatenation& other) {
 	return *this;
 }
 
-Concatenation& Concatenation::operator=(Concatenation&& other) noexcept {
+Concatenation& Concatenation::operator=(Concatenation&& other) {
 	std::swap(this->elements, other.elements);
+	std::swap(this->parentRegExp, other.parentRegExp);
   
+	this->attachRegExp(other.parentRegExp);
+	
 	return *this;
 }
 
@@ -141,6 +144,7 @@ bool Concatenation::testSymbol( const alphabet::Symbol & symbol ) const {
 
 bool Concatenation::attachRegExp(const RegExp * regexp ) {
 	if(this->parentRegExp == regexp) return true;
+	
 	this->parentRegExp = regexp;
 	for(const auto& child : this->elements)
 		if(!child->attachRegExp(regexp)) return false;
diff --git a/alib2/src/regexp/Concatenation.h b/alib2/src/regexp/Concatenation.h
index ade705b85a..f3cb0ad367 100644
--- a/alib2/src/regexp/Concatenation.h
+++ b/alib2/src/regexp/Concatenation.h
@@ -50,7 +50,7 @@ public:
 	Concatenation(const Concatenation& other);
 	Concatenation(Concatenation&& other) noexcept;
 	Concatenation& operator =(const Concatenation& other);
-	Concatenation& operator =(Concatenation&& other) noexcept;
+	Concatenation& operator =(Concatenation&& other);
 	virtual ~Concatenation() noexcept;
 	
 	/**
diff --git a/alib2/src/regexp/Iteration.cpp b/alib2/src/regexp/Iteration.cpp
index 51c364c6e2..27a470014e 100644
--- a/alib2/src/regexp/Iteration.cpp
+++ b/alib2/src/regexp/Iteration.cpp
@@ -24,7 +24,7 @@ Iteration::Iteration(const Iteration& other) : element(other.element->clone()) {
 }
 
 Iteration::Iteration(Iteration&& other) noexcept : element(other.element) {
-	other.element = nullptr;
+	other.element = NULL;
 	this->attachRegExp(NULL);
 }
 
@@ -38,8 +38,11 @@ Iteration& Iteration::operator=(const Iteration& other) {
 	return *this;
 }
 
-Iteration& Iteration::operator=(Iteration&& other) noexcept {
+Iteration& Iteration::operator=(Iteration&& other) {
 	std::swap(this->element, other.element);
+	std::swap(this->parentRegExp, other.parentRegExp);
+	
+	this->attachRegExp(other.parentRegExp);
 
 	return *this;
 }
diff --git a/alib2/src/regexp/Iteration.h b/alib2/src/regexp/Iteration.h
index 6c04a1fa2c..f0eb5139e0 100644
--- a/alib2/src/regexp/Iteration.h
+++ b/alib2/src/regexp/Iteration.h
@@ -50,7 +50,7 @@ public:
 	Iteration(const Iteration& other);
 	Iteration(Iteration&& other) noexcept;
 	Iteration& operator =(const Iteration& other);
-	Iteration& operator =(Iteration&& other) noexcept;
+	Iteration& operator =(Iteration&& other);
 	virtual ~Iteration() noexcept;
 
 	/**
diff --git a/alib2/src/regexp/RegExpEmpty.cpp b/alib2/src/regexp/RegExpEmpty.cpp
index 90fbf970ac..bcc13aaf60 100644
--- a/alib2/src/regexp/RegExpEmpty.cpp
+++ b/alib2/src/regexp/RegExpEmpty.cpp
@@ -9,14 +9,28 @@
 
 namespace regexp {
   
-RegExpEmpty::RegExpEmpty(const RegExpEmpty& other) {
+RegExpEmpty::RegExpEmpty() {
+  // so that default constructor is available
+}
   
+RegExpEmpty::RegExpEmpty(const RegExpEmpty& other) {
+  // so that copy constructor is available
 }
 
-RegExpEmpty::RegExpEmpty(RegExpEmpty&& other) {
+RegExpEmpty::RegExpEmpty(RegExpEmpty&& other) noexcept {
   this->attachRegExp(NULL);
 }
 
+RegExpEmpty& RegExpEmpty::operator =(const RegExpEmpty& other) {
+  //this is actually different than default implementation
+  return *this;
+}
+
+RegExpEmpty& RegExpEmpty::operator =(RegExpEmpty&& other) noexcept {
+  //this is actually different than default implementation
+  return *this;
+}
+
 RegExpElement* RegExpEmpty::clone() const {
 	return new RegExpEmpty(*this);
 }
diff --git a/alib2/src/regexp/RegExpEmpty.h b/alib2/src/regexp/RegExpEmpty.h
index 1293b61c38..64b28a08aa 100644
--- a/alib2/src/regexp/RegExpEmpty.h
+++ b/alib2/src/regexp/RegExpEmpty.h
@@ -40,8 +40,11 @@ protected:
 	virtual void computeMinimalAlphabet( std::set<alphabet::Symbol>& alphabet ) const;
 
 public:
+	RegExpEmpty();
 	RegExpEmpty(const RegExpEmpty& other);
-	RegExpEmpty(RegExpEmpty&& other);
+	RegExpEmpty(RegExpEmpty&& other) noexcept;
+	RegExpEmpty& operator =(const RegExpEmpty& other);
+	RegExpEmpty& operator =(RegExpEmpty&& other) noexcept;
   
 	virtual bool operator<(const RegExpElement&) const;
 	virtual bool operator==(const RegExpElement&) const;
diff --git a/alib2/src/regexp/RegExpEpsilon.cpp b/alib2/src/regexp/RegExpEpsilon.cpp
index 0984e2ec81..f4d004a876 100644
--- a/alib2/src/regexp/RegExpEpsilon.cpp
+++ b/alib2/src/regexp/RegExpEpsilon.cpp
@@ -9,13 +9,27 @@
 
 namespace regexp {
   
-RegExpEpsilon::RegExpEpsilon(const RegExpEpsilon& other) {
+RegExpEpsilon::RegExpEpsilon() {
+  // so that default constructor is available
+}
   
+RegExpEpsilon::RegExpEpsilon(const RegExpEpsilon& other) {
+  // so that copy constructor is available
 }
 
-RegExpEpsilon::RegExpEpsilon(RegExpEpsilon&& other) {
+RegExpEpsilon::RegExpEpsilon(RegExpEpsilon&& other) noexcept {
 	this->attachRegExp(NULL);
 }
+
+RegExpEpsilon& RegExpEpsilon::operator =(const RegExpEpsilon& other) {
+  //this is actually different than default implementation
+  return *this;
+}
+
+RegExpEpsilon& RegExpEpsilon::operator =(RegExpEpsilon&& other) noexcept {
+  //this is actually different than default implementation
+  return *this;
+}
   
 RegExpElement* RegExpEpsilon::clone() const {
 	return new RegExpEpsilon(*this);
diff --git a/alib2/src/regexp/RegExpEpsilon.h b/alib2/src/regexp/RegExpEpsilon.h
index 56c2a76cc0..f36f3f25e4 100644
--- a/alib2/src/regexp/RegExpEpsilon.h
+++ b/alib2/src/regexp/RegExpEpsilon.h
@@ -41,8 +41,11 @@ protected:
 
 public:
   
+	RegExpEpsilon();
 	RegExpEpsilon(const RegExpEpsilon& other);
-	RegExpEpsilon(RegExpEpsilon&& other);
+	RegExpEpsilon(RegExpEpsilon&& other) noexcept;
+	RegExpEpsilon& operator=(const RegExpEpsilon& other);
+	RegExpEpsilon& operator=(RegExpEpsilon&& other) noexcept;
 	
 	virtual bool operator<(const RegExpElement&) const;
 	virtual bool operator==(const RegExpElement&) const;
diff --git a/alib2/src/regexp/RegExpSymbol.cpp b/alib2/src/regexp/RegExpSymbol.cpp
index 118340a101..d2d2ad2930 100644
--- a/alib2/src/regexp/RegExpSymbol.cpp
+++ b/alib2/src/regexp/RegExpSymbol.cpp
@@ -13,10 +13,29 @@ RegExpSymbol::RegExpSymbol(const RegExpSymbol& other) : alphabet::Symbol(other.s
   
 }
 
-RegExpSymbol::RegExpSymbol(RegExpSymbol&& other) : alphabet::Symbol(std::move(other.symbol)) {
+RegExpSymbol::RegExpSymbol(RegExpSymbol&& other) noexcept : alphabet::Symbol(std::move(other.symbol)) {
 	this->attachRegExp(NULL);
 }
 
+RegExpSymbol& RegExpSymbol::operator=(const RegExpSymbol& other) {
+  	if (this == &other) {
+		return *this;
+	}
+
+	*this = RegExpSymbol(other);
+
+	return *this;
+}
+
+RegExpSymbol& RegExpSymbol::operator=(RegExpSymbol&& other) {
+	std::swap(this->symbol, other.symbol);
+	std::swap(this->parentRegExp, other.parentRegExp);
+	
+	this->attachRegExp(other.parentRegExp);
+	
+	return *this;
+}
+
 RegExpSymbol::RegExpSymbol(const std::string& symbol) :
 		alphabet::Symbol(symbol) {
 }
diff --git a/alib2/src/regexp/RegExpSymbol.h b/alib2/src/regexp/RegExpSymbol.h
index 0fa85b0b19..e94d40bc9b 100644
--- a/alib2/src/regexp/RegExpSymbol.h
+++ b/alib2/src/regexp/RegExpSymbol.h
@@ -45,7 +45,9 @@ public:
 	RegExpSymbol(std::string&& symbol);
 	
 	RegExpSymbol(const RegExpSymbol& other);
-	RegExpSymbol(RegExpSymbol&& other);
+	RegExpSymbol(RegExpSymbol&& other) noexcept;
+	RegExpSymbol& operator=(const RegExpSymbol& other);
+	RegExpSymbol& operator=(RegExpSymbol&& other);
 	
 	bool operator==(const alphabet::Symbol&) const;
 	friend bool operator==(const alphabet::Symbol&, const RegExpSymbol&);
-- 
GitLab