From 8268ef240f8a0d29156b60602d9598124a5889e9 Mon Sep 17 00:00:00 2001
From: Jan Travnicek <Jan.Travnicek@fit.cvut.cz>
Date: Fri, 13 Apr 2018 17:20:47 +0200
Subject: [PATCH] simplify rte representation

---
 alib2data/src/rte/formal/FormalRTEIteration.h | 17 +++++++++--------
 .../src/rte/formal/FormalRTESubstitution.h    | 19 ++++++++++---------
 alib2data/src/rte/formal/FormalRTESymbol.h    |  2 +-
 .../src/rte/formal/FormalRTESymbolSubst.h     |  4 ----
 4 files changed, 20 insertions(+), 22 deletions(-)

diff --git a/alib2data/src/rte/formal/FormalRTEIteration.h b/alib2data/src/rte/formal/FormalRTEIteration.h
index f8be708776..a5d64aebbb 100644
--- a/alib2data/src/rte/formal/FormalRTEIteration.h
+++ b/alib2data/src/rte/formal/FormalRTEIteration.h
@@ -49,7 +49,7 @@ class FormalRTEIteration : public FormalRTEElement < SymbolType, RankType >, pub
 	/**
 	 * The substitution symbol of the node. The symbol will be substitued in left tree by right
 	 */
-	ext::smart_ptr < FormalRTESymbolSubst < SymbolType, RankType > > m_substitutionSymbol;
+	FormalRTESymbolSubst < SymbolType, RankType > m_substitutionSymbol;
 
 	/**
 	 * @copydoc regexp::FormalRTEElement < SymbolType, RankType >::accept ( ) const
@@ -181,12 +181,13 @@ public:
 	 * @copydoc regexp::FormalRTEElement < SymbolType, RankType >::normalize ( ) &&
 	 */
 	virtual ext::smart_ptr < FormalRTEElement < DefaultSymbolType, DefaultRankType > > normalize ( ) && override {
-		return ext::smart_ptr < FormalRTEElement < DefaultSymbolType, DefaultRankType > > ( new FormalRTEIteration < DefaultSymbolType, DefaultRankType > ( std::move ( * std::move ( getElement ( ) ).normalize ( ) ), std::move ( * m_substitutionSymbol ).normalizeRaw ( ) ) );
+		FormalRTESymbolSubst < DefaultSymbolType, DefaultRankType > subst ( alphabet::SymbolNormalize::normalizeRankedSymbol ( std::move ( m_substitutionSymbol ).getSymbol ( ) ) );
+		return ext::smart_ptr < FormalRTEElement < DefaultSymbolType, DefaultRankType > > ( new FormalRTEIteration < DefaultSymbolType, DefaultRankType > ( std::move ( * std::move ( getElement ( ) ).normalize ( ) ), std::move ( subst ) ) );
 	}
 };
 
 template < class SymbolType, class RankType >
-FormalRTEIteration < SymbolType, RankType >::FormalRTEIteration ( FormalRTEElement < SymbolType, RankType > && element, FormalRTESymbolSubst < SymbolType, RankType > substitutionSymbol ) : ext::UnaryNode < ext::smart_ptr < FormalRTEElement < SymbolType, RankType > >, ext::smart_ptr < const FormalRTEElement < SymbolType, RankType > >, FormalRTEIteration < SymbolType, RankType > > ( ext::smart_ptr < FormalRTEElement < SymbolType, RankType > > ( std::move ( element ).plunder ( ) ) ), m_substitutionSymbol ( ext::smart_ptr < FormalRTESymbolSubst < SymbolType, RankType > > ( std::move ( substitutionSymbol ).plunder ( ) ) ) {
+FormalRTEIteration < SymbolType, RankType >::FormalRTEIteration ( FormalRTEElement < SymbolType, RankType > && element, FormalRTESymbolSubst < SymbolType, RankType > substitutionSymbol ) : ext::UnaryNode < ext::smart_ptr < FormalRTEElement < SymbolType, RankType > >, ext::smart_ptr < const FormalRTEElement < SymbolType, RankType > >, FormalRTEIteration < SymbolType, RankType > > ( ext::smart_ptr < FormalRTEElement < SymbolType, RankType > > ( std::move ( element ).plunder ( ) ) ), m_substitutionSymbol ( std::move ( substitutionSymbol ) ) {
 }
 
 template < class SymbolType, class RankType >
@@ -205,12 +206,12 @@ FormalRTEElement < SymbolType, RankType > & FormalRTEIteration < SymbolType, Ran
 
 template < class SymbolType, class RankType >
 const FormalRTESymbolSubst < SymbolType, RankType > & FormalRTEIteration < SymbolType, RankType >::getSubstitutionSymbol ( ) const {
-	return * m_substitutionSymbol;
+	return m_substitutionSymbol;
 }
 
 template < class SymbolType, class RankType >
 FormalRTESymbolSubst < SymbolType, RankType > & FormalRTEIteration < SymbolType, RankType >::getSubstitutionSymbol ( ) {
-	return * m_substitutionSymbol;
+	return m_substitutionSymbol;
 }
 
 template < class SymbolType, class RankType >
@@ -225,7 +226,7 @@ void FormalRTEIteration < SymbolType, RankType >::setElement ( FormalRTEElement
 
 template < class SymbolType, class RankType >
 void FormalRTEIteration < SymbolType, RankType >::setSubstitutionSymbol ( FormalRTESymbolSubst < SymbolType, RankType > symbol ) {
-	m_substitutionSymbol = ext::smart_ptr < FormalRTESymbolSubst < SymbolType, RankType > > ( std::move ( symbol ).plunder ( ) );
+	m_substitutionSymbol = std::move ( symbol );
 }
 
 template < class SymbolType, class RankType >
@@ -250,7 +251,7 @@ int FormalRTEIteration < SymbolType, RankType >::compare ( const FormalRTEIterat
 
 template < class SymbolType, class RankType >
 void FormalRTEIteration < SymbolType, RankType >::operator >>( std::ostream & out ) const {
-	out << "(RTEFormalRTEIteration " << * m_substitutionSymbol << " " << getElement ( ) << ")";
+	out << "(RTEFormalRTEIteration " << m_substitutionSymbol << " " << getElement ( ) << ")";
 }
 
 template < class SymbolType, class RankType >
@@ -260,7 +261,7 @@ bool FormalRTEIteration < SymbolType, RankType >::testSymbol ( const common::ran
 
 template < class SymbolType, class RankType >
 void FormalRTEIteration < SymbolType, RankType >::computeMinimalAlphabet ( ext::set < common::ranked_symbol < SymbolType, RankType > > & alphabetF, ext::set < common::ranked_symbol < SymbolType, RankType > > & alphabetK ) const {
-	alphabetK.insert ( m_substitutionSymbol->getSymbol ( ) );
+	alphabetK.insert ( m_substitutionSymbol.getSymbol ( ) );
 	this->getChild ( )->computeMinimalAlphabet ( alphabetF, alphabetK );
 }
 
diff --git a/alib2data/src/rte/formal/FormalRTESubstitution.h b/alib2data/src/rte/formal/FormalRTESubstitution.h
index bf58641abe..b2232ab44f 100644
--- a/alib2data/src/rte/formal/FormalRTESubstitution.h
+++ b/alib2data/src/rte/formal/FormalRTESubstitution.h
@@ -48,7 +48,7 @@ class FormalRTESubstitution : public FormalRTEElement < SymbolType, RankType >,
 	/**
 	 * The substitution symbol of the node. The symbol will be substitued in left tree by right
 	 */
-	ext::smart_ptr < FormalRTESymbolSubst < SymbolType, RankType > > m_substitutionSymbol;
+	FormalRTESymbolSubst < SymbolType, RankType > m_substitutionSymbol;
 
 	/**
 	 * @copydoc regexp::FormalRTEElement < SymbolType, RankType >::accept ( ) const
@@ -210,12 +210,13 @@ public:
 	 * @copydoc regexp::FormalRTEElement < SymbolType, RankType >::normalize ( ) &&
 	 */
 	virtual ext::smart_ptr < FormalRTEElement < DefaultSymbolType, DefaultRankType > > normalize ( ) && override {
-		return ext::smart_ptr < FormalRTEElement < DefaultSymbolType, DefaultRankType > > ( new FormalRTESubstitution < DefaultSymbolType, DefaultRankType > ( std::move ( * std::move ( getLeftElement ( ) ).normalize ( ) ), std::move ( * std::move ( getRightElement ( ) ).normalize ( ) ), std::move ( * m_substitutionSymbol ).normalizeRaw ( ) ) );
+		FormalRTESymbolSubst < DefaultSymbolType, DefaultRankType > subst ( alphabet::SymbolNormalize::normalizeRankedSymbol ( std::move ( m_substitutionSymbol ).getSymbol ( ) ) );
+		return ext::smart_ptr < FormalRTEElement < DefaultSymbolType, DefaultRankType > > ( new FormalRTESubstitution < DefaultSymbolType, DefaultRankType > ( std::move ( * std::move ( getLeftElement ( ) ).normalize ( ) ), std::move ( * std::move ( getRightElement ( ) ).normalize ( ) ), std::move ( subst ) ) );
 	}
 };
 
 template < class SymbolType, class RankType >
-FormalRTESubstitution < SymbolType, RankType >::FormalRTESubstitution ( FormalRTEElement < SymbolType, RankType > && left, FormalRTEElement < SymbolType, RankType > && right, FormalRTESymbolSubst < SymbolType, RankType > substitutionSymbol ) : ext::BinaryNode < ext::smart_ptr < FormalRTEElement < SymbolType, RankType > >, ext::smart_ptr < FormalRTEElement < SymbolType, RankType > >, FormalRTESubstitution < SymbolType, RankType > > ( ext::smart_ptr < FormalRTEElement < SymbolType, RankType > > ( std::move ( left ).plunder ( ) ), ext::smart_ptr < FormalRTEElement < SymbolType, RankType > > ( std::move ( right ).plunder ( ) ) ), m_substitutionSymbol ( ext::smart_ptr < FormalRTESymbolSubst < SymbolType, RankType > > ( std::move ( substitutionSymbol ).plunder ( ) ) ) {
+FormalRTESubstitution < SymbolType, RankType >::FormalRTESubstitution ( FormalRTEElement < SymbolType, RankType > && left, FormalRTEElement < SymbolType, RankType > && right, FormalRTESymbolSubst < SymbolType, RankType > substitutionSymbol ) : ext::BinaryNode < ext::smart_ptr < FormalRTEElement < SymbolType, RankType > >, ext::smart_ptr < FormalRTEElement < SymbolType, RankType > >, FormalRTESubstitution < SymbolType, RankType > > ( ext::smart_ptr < FormalRTEElement < SymbolType, RankType > > ( std::move ( left ).plunder ( ) ), ext::smart_ptr < FormalRTEElement < SymbolType, RankType > > ( std::move ( right ).plunder ( ) ) ), m_substitutionSymbol ( std::move ( substitutionSymbol ) ) {
 }
 
 template < class SymbolType, class RankType >
@@ -234,7 +235,7 @@ const FormalRTEElement < SymbolType, RankType > & FormalRTESubstitution < Symbol
 
 template < class SymbolType, class RankType >
 const FormalRTESymbolSubst < SymbolType, RankType > & FormalRTESubstitution < SymbolType, RankType >::getSubstitutionSymbol ( ) const {
-	return * this->m_substitutionSymbol;
+	return m_substitutionSymbol;
 }
 
 template < class SymbolType, class RankType >
@@ -249,7 +250,7 @@ FormalRTEElement < SymbolType, RankType > & FormalRTESubstitution < SymbolType,
 
 template < class SymbolType, class RankType >
 FormalRTESymbolSubst < SymbolType, RankType > & FormalRTESubstitution < SymbolType, RankType >::getSubstitutionSymbol ( ) {
-	return * this->m_substitutionSymbol;
+	return m_substitutionSymbol;
 }
 
 template < class SymbolType, class RankType >
@@ -274,7 +275,7 @@ void FormalRTESubstitution < SymbolType, RankType >::setRightElement ( FormalRTE
 
 template < class SymbolType, class RankType >
 void FormalRTESubstitution < SymbolType, RankType >::setSubstitutionSymbol ( FormalRTESymbolSubst < SymbolType, RankType > symbol ) {
-	m_substitutionSymbol = ext::smart_ptr < FormalRTESymbolSubst < SymbolType, RankType > > ( std::move ( symbol ).plunder ( ) );
+	m_substitutionSymbol = std::move ( symbol );
 }
 
 template < class SymbolType, class RankType >
@@ -301,7 +302,7 @@ template < class SymbolType, class RankType >
 void FormalRTESubstitution < SymbolType, RankType >::operator >>( std::ostream & out ) const {
 	out << "(FormalRTESubstitution";
 	out << " " << getLeftElement ( );
-	out << " " << * m_substitutionSymbol;
+	out << " " << m_substitutionSymbol;
 	out << " " << getRightElement ( );
 	out << ")";
 }
@@ -312,14 +313,14 @@ bool FormalRTESubstitution < SymbolType, RankType >::testSymbol ( const common::
 
 	if ( getRightElement ( ).testSymbol ( symbol ) ) return true;
 
-	if ( m_substitutionSymbol->getSymbol ( ) == symbol ) return true;
+	if ( m_substitutionSymbol.getSymbol ( ) == symbol ) return true;
 
 	return false;
 }
 
 template < class SymbolType, class RankType >
 void FormalRTESubstitution < SymbolType, RankType >::computeMinimalAlphabet ( ext::set < common::ranked_symbol < SymbolType, RankType > > & alphabetF, ext::set < common::ranked_symbol < SymbolType, RankType > > & alphabetK ) const {
-	alphabetK.insert ( m_substitutionSymbol->getSymbol ( ) );
+	alphabetK.insert ( m_substitutionSymbol.getSymbol ( ) );
 	getLeftElement ( ).computeMinimalAlphabet ( alphabetF, alphabetK );
 	getRightElement ( ).computeMinimalAlphabet ( alphabetF, alphabetK );
 }
diff --git a/alib2data/src/rte/formal/FormalRTESymbol.h b/alib2data/src/rte/formal/FormalRTESymbol.h
index 8e4d89c781..00eedd5790 100644
--- a/alib2data/src/rte/formal/FormalRTESymbol.h
+++ b/alib2data/src/rte/formal/FormalRTESymbol.h
@@ -87,7 +87,7 @@ const common::ranked_symbol < SymbolType, RankType > & FormalRTESymbol < SymbolT
 
 template < class SymbolType, class RankType >
 common::ranked_symbol < SymbolType, RankType > && FormalRTESymbol < SymbolType, RankType >::getSymbol ( ) && {
-	return m_symbol;
+	return std::move ( m_symbol );
 }
 
 } /* namespace rte */
diff --git a/alib2data/src/rte/formal/FormalRTESymbolSubst.h b/alib2data/src/rte/formal/FormalRTESymbolSubst.h
index a5dcc9c92b..a5e12229f6 100644
--- a/alib2data/src/rte/formal/FormalRTESymbolSubst.h
+++ b/alib2data/src/rte/formal/FormalRTESymbolSubst.h
@@ -112,10 +112,6 @@ public:
 	 */
 	virtual explicit operator std::string ( ) const override;
 
-	FormalRTESymbolSubst < DefaultSymbolType, DefaultRankType > normalizeRaw ( ) && {
-		return FormalRTESymbolSubst < DefaultSymbolType, DefaultRankType > ( alphabet::SymbolNormalize::normalizeRankedSymbol ( std::move ( this->m_symbol ) ) );
-	}
-
 	/**
 	 * @copydoc regexp::FormalRTEElement < SymbolType, RankType >::normalize ( ) &&
 	 */
-- 
GitLab