From ed2fe5fe714ca450f417d9b2f1d2c9d2e9ca54a5 Mon Sep 17 00:00:00 2001
From: Jan Travnicek <Jan.Travnicek@fit.cvut.cz>
Date: Sun, 26 Mar 2017 19:16:16 +0200
Subject: [PATCH] normalisation of alphabet data types

---
 alib2data/src/alphabet/BarSymbol.h            |  4 ++++
 alib2data/src/alphabet/BlankSymbol.h          |  4 ++++
 .../src/alphabet/BottomOfTheStackSymbol.h     |  4 ++++
 alib2data/src/alphabet/EndSymbol.h            |  4 ++++
 alib2data/src/alphabet/InitialSymbol.h        |  4 ++++
 alib2data/src/alphabet/LabeledSymbol.h        |  4 ++++
 .../src/alphabet/NonlinearVariableSymbol.h    | 16 +++++++++++++++
 alib2data/src/alphabet/RankedSymbol.h         | 10 ++++++++++
 alib2data/src/alphabet/StartSymbol.h          |  4 ++++
 .../src/alphabet/SubtreeWildcardSymbol.h      |  4 ++++
 alib2data/src/alphabet/UniqueSymbol.h         |  4 ++++
 alib2data/src/alphabet/VariablesBarSymbol.h   |  4 ++++
 alib2data/src/alphabet/ranked_symbol.hpp      | 20 +++++++++++++++++++
 13 files changed, 86 insertions(+)

diff --git a/alib2data/src/alphabet/BarSymbol.h b/alib2data/src/alphabet/BarSymbol.h
index 5b2b5a5021..cc8dd94291 100644
--- a/alib2data/src/alphabet/BarSymbol.h
+++ b/alib2data/src/alphabet/BarSymbol.h
@@ -56,6 +56,10 @@ public:
 	void compose ( std::deque < sax::Token > & out ) const;
 
 	virtual SymbolBase * inc ( ) &&;
+
+	virtual SymbolBase * normalize ( ) && {
+		return this;
+	}
 };
 
 template < typename Base >
diff --git a/alib2data/src/alphabet/BlankSymbol.h b/alib2data/src/alphabet/BlankSymbol.h
index 0d45eca1e8..5da1f16cef 100644
--- a/alib2data/src/alphabet/BlankSymbol.h
+++ b/alib2data/src/alphabet/BlankSymbol.h
@@ -56,6 +56,10 @@ public:
 	void compose ( std::deque < sax::Token > & out ) const;
 
 	virtual SymbolBase * inc ( ) &&;
+
+	virtual SymbolBase * normalize ( ) && {
+		return this;
+	}
 };
 
 template < typename Base >
diff --git a/alib2data/src/alphabet/BottomOfTheStackSymbol.h b/alib2data/src/alphabet/BottomOfTheStackSymbol.h
index 9bbef82703..2846eb61ce 100644
--- a/alib2data/src/alphabet/BottomOfTheStackSymbol.h
+++ b/alib2data/src/alphabet/BottomOfTheStackSymbol.h
@@ -56,6 +56,10 @@ public:
 	void compose ( std::deque < sax::Token > & out ) const;
 
 	virtual SymbolBase * inc ( ) &&;
+
+	virtual SymbolBase * normalize ( ) && {
+		return this;
+	}
 };
 
 template < typename Base >
diff --git a/alib2data/src/alphabet/EndSymbol.h b/alib2data/src/alphabet/EndSymbol.h
index a5f9fca8f8..b2d4968ab0 100644
--- a/alib2data/src/alphabet/EndSymbol.h
+++ b/alib2data/src/alphabet/EndSymbol.h
@@ -56,6 +56,10 @@ public:
 	void compose ( std::deque < sax::Token > & out ) const;
 
 	virtual SymbolBase * inc ( ) &&;
+
+	virtual SymbolBase * normalize ( ) && {
+		return this;
+	}
 };
 
 template < typename Base >
diff --git a/alib2data/src/alphabet/InitialSymbol.h b/alib2data/src/alphabet/InitialSymbol.h
index c619b99ad1..937d4be94f 100644
--- a/alib2data/src/alphabet/InitialSymbol.h
+++ b/alib2data/src/alphabet/InitialSymbol.h
@@ -57,6 +57,10 @@ public:
 	void compose ( std::deque < sax::Token > & out ) const;
 
 	virtual SymbolBase * inc ( ) &&;
+
+	virtual SymbolBase * normalize ( ) && {
+		return this;
+	}
 };
 
 template < typename Base >
diff --git a/alib2data/src/alphabet/LabeledSymbol.h b/alib2data/src/alphabet/LabeledSymbol.h
index 0e209446bb..11dbad4b03 100644
--- a/alib2data/src/alphabet/LabeledSymbol.h
+++ b/alib2data/src/alphabet/LabeledSymbol.h
@@ -64,6 +64,10 @@ public:
 	void compose ( std::deque < sax::Token > & out ) const;
 
 	virtual SymbolBase * inc ( ) &&;
+
+	virtual SymbolBase * normalize ( ) && {
+		return this;
+	}
 };
 
 } /* namespace alphabet */
diff --git a/alib2data/src/alphabet/NonlinearVariableSymbol.h b/alib2data/src/alphabet/NonlinearVariableSymbol.h
index 288c01e75d..c48604641c 100644
--- a/alib2data/src/alphabet/NonlinearVariableSymbol.h
+++ b/alib2data/src/alphabet/NonlinearVariableSymbol.h
@@ -14,6 +14,8 @@
 #include "SymbolFeatures.h"
 #include "UniqueSymbol.h"
 
+#include <object/AnyObject.h>
+
 namespace alphabet {
 
 /**
@@ -43,6 +45,11 @@ public:
 	 */
 	const SymbolType & getSymbol ( ) const;
 
+	/**
+	 * @return name of the symbol
+	 */
+	SymbolType & getSymbol ( );
+
 	virtual int compare ( const ObjectBase & other ) const {
 		if ( std::type_index ( typeid ( * this ) ) == std::type_index ( typeid ( other ) ) ) return this->compare ( ( decltype ( * this ) )other );
 
@@ -66,6 +73,10 @@ public:
 	void compose ( std::deque < sax::Token > & out ) const;
 
 	virtual SymbolBase * inc ( ) &&;
+
+	virtual SymbolBase * normalize ( ) && {
+		return new NonlinearVariableSymbol < > ( DefaultSymbolType ( alib::AnyObject < SymbolType > ( std::move ( this->getSymbol ( ) ) ) ) );
+	}
 };
 
 template < class SymbolType >
@@ -99,6 +110,11 @@ const SymbolType& NonlinearVariableSymbol < SymbolType >::getSymbol() const {
 	return m_symbol;
 }
 
+template < class SymbolType >
+SymbolType & NonlinearVariableSymbol < SymbolType >::getSymbol() {
+	return m_symbol;
+}
+
 template < class SymbolType >
 int NonlinearVariableSymbol < SymbolType >::compare ( const NonlinearVariableSymbol & other ) const {
 	static std::compare < decltype ( m_symbol ) > comp;
diff --git a/alib2data/src/alphabet/RankedSymbol.h b/alib2data/src/alphabet/RankedSymbol.h
index 9a527bb2ab..99073b4940 100644
--- a/alib2data/src/alphabet/RankedSymbol.h
+++ b/alib2data/src/alphabet/RankedSymbol.h
@@ -15,6 +15,8 @@
 #include "SymbolFeatures.h"
 #include "ranked_symbol.hpp"
 
+#include <object/AnyObject.h>
+
 namespace alphabet {
 
 /**
@@ -63,6 +65,14 @@ public:
 	static void compose ( std::deque < sax::Token > & out, const std::ranked_symbol < SymbolType, RankType > & input );
 
 	virtual SymbolBase * inc ( ) &&;
+
+	std::ranked_symbol < DefaultSymbolType, DefaultRankType > normalizeRaw ( std::ranked_symbol < SymbolType, RankType > && source ) {
+		return std::ranked_symbol < DefaultSymbolType, DefaultRankType > ( DefaultSymbolType ( alib::AnyObject < SymbolType > ( std::move ( source.getSymbol ( ) ) ) ), DefaultRankType ( std::move ( source.getRank ( ) ) ) );
+	}
+
+	virtual SymbolBase * normalize ( ) && {
+		return new RankedSymbol < > ( normalizeRaw ( std::move ( *this ) ) );
+	}
 };
 
 template < class SymbolType, class RankType >
diff --git a/alib2data/src/alphabet/StartSymbol.h b/alib2data/src/alphabet/StartSymbol.h
index b3ab08c130..44a830518e 100644
--- a/alib2data/src/alphabet/StartSymbol.h
+++ b/alib2data/src/alphabet/StartSymbol.h
@@ -56,6 +56,10 @@ public:
 	void compose ( std::deque < sax::Token > & out ) const;
 
 	virtual SymbolBase * inc ( ) &&;
+
+	virtual SymbolBase * normalize ( ) && {
+		return this;
+	}
 };
 
 template < typename Base >
diff --git a/alib2data/src/alphabet/SubtreeWildcardSymbol.h b/alib2data/src/alphabet/SubtreeWildcardSymbol.h
index 6fcee7dadc..b7067cbeec 100644
--- a/alib2data/src/alphabet/SubtreeWildcardSymbol.h
+++ b/alib2data/src/alphabet/SubtreeWildcardSymbol.h
@@ -57,6 +57,10 @@ public:
 	void compose ( std::deque < sax::Token > & out ) const;
 
 	virtual SymbolBase * inc ( ) &&;
+
+	virtual SymbolBase * normalize ( ) && {
+		return this;
+	}
 };
 
 template < typename Base >
diff --git a/alib2data/src/alphabet/UniqueSymbol.h b/alib2data/src/alphabet/UniqueSymbol.h
index fbd2ee13fd..7570222bfe 100644
--- a/alib2data/src/alphabet/UniqueSymbol.h
+++ b/alib2data/src/alphabet/UniqueSymbol.h
@@ -64,6 +64,10 @@ public:
 	void compose ( std::deque < sax::Token > & out ) const;
 
 	virtual SymbolBase * inc ( ) &&;
+
+	virtual SymbolBase * normalize ( ) && {
+		return this;
+	}
 };
 
 } /* namespace alphabet */
diff --git a/alib2data/src/alphabet/VariablesBarSymbol.h b/alib2data/src/alphabet/VariablesBarSymbol.h
index 78c82b8625..a2f530cd84 100644
--- a/alib2data/src/alphabet/VariablesBarSymbol.h
+++ b/alib2data/src/alphabet/VariablesBarSymbol.h
@@ -57,6 +57,10 @@ public:
 	void compose ( std::deque < sax::Token > & out ) const;
 
 	virtual SymbolBase * inc ( ) &&;
+
+	virtual SymbolBase * normalize ( ) && {
+		return this;
+	}
 };
 
 template < typename Base >
diff --git a/alib2data/src/alphabet/ranked_symbol.hpp b/alib2data/src/alphabet/ranked_symbol.hpp
index 5f8f2ebff7..1df0fe23aa 100644
--- a/alib2data/src/alphabet/ranked_symbol.hpp
+++ b/alib2data/src/alphabet/ranked_symbol.hpp
@@ -41,11 +41,21 @@ public:
 	 */
 	const SymbolType & getSymbol ( ) const;
 
+	/**
+	 * @return name of the symbol
+	 */
+	SymbolType & getSymbol ( );
+
 	/**
 	 * @return rank of the symbol
 	 */
 	const RankType & getRank ( ) const;
 
+	/**
+	 * @return rank of the symbol
+	 */
+	RankType & getRank ( );
+
 	int compare ( const ranked_symbol & other ) const;
 
 	explicit operator std::string ( ) const;
@@ -105,11 +115,21 @@ const SymbolType& ranked_symbol < SymbolType, RankType >::getSymbol() const {
 	return m_symbol;
 }
 
+template < class SymbolType, class RankType >
+SymbolType& ranked_symbol < SymbolType, RankType >::getSymbol() {
+	return m_symbol;
+}
+
 template < class SymbolType, class RankType >
 const RankType& ranked_symbol < SymbolType, RankType >::getRank() const {
 	return m_rank;
 }
 
+template < class SymbolType, class RankType >
+RankType& ranked_symbol < SymbolType, RankType >::getRank() {
+	return m_rank;
+}
+
 template < class SymbolType, class RankType >
 int ranked_symbol < SymbolType, RankType >::compare(const ranked_symbol& other) const {
 	auto first = std::tie ( m_symbol, m_rank );
-- 
GitLab