From 16e3e24b91139c893ddb8240523c942ffe95bf00 Mon Sep 17 00:00:00 2001
From: Jan Travnicek <Jan.Travnicek@fit.cvut.cz>
Date: Fri, 16 Dec 2016 13:12:35 +0100
Subject: [PATCH] Symbol to Label + cleanup and fixes

---
 .../src/automaton/determinize/common/RHDPDACommon.cpp  |  4 ++--
 alib2algo/src/grammar/convert/ToAutomaton.cpp          |  5 ++---
 alib2algo/src/regexp/convert/ToAutomatonGlushkov.cpp   | 10 ++++------
 .../src/regexp/convert/ToGrammarRightRGGlushkov.cpp    |  3 ---
 alib2data/src/alphabet/Symbol.cpp                      |  6 +++++-
 alib2data/src/alphabet/Symbol.h                        |  5 +++--
 alib2data/src/label/Label.cpp                          |  9 +++++++++
 alib2data/src/label/Label.h                            |  3 +++
 8 files changed, 28 insertions(+), 17 deletions(-)

diff --git a/alib2algo/src/automaton/determinize/common/RHDPDACommon.cpp b/alib2algo/src/automaton/determinize/common/RHDPDACommon.cpp
index d62e952e4f..0366207e9a 100644
--- a/alib2algo/src/automaton/determinize/common/RHDPDACommon.cpp
+++ b/alib2algo/src/automaton/determinize/common/RHDPDACommon.cpp
@@ -34,7 +34,7 @@ std::set<std::pair<label::Label, label::Label>> unpackFromStateLabel(const label
 
 label::Label packToStackSymbolLabel(std::pair<std::set<std::pair<label::Label, label::Label>>, alphabet::Symbol>&& data) {
 	label::Label res1 = packToStateLabel(std::move(data.first));
-	label::Label res2 = label::Label(label::ObjectLabel(alib::Object(std::move(data.second.getData()))));
+	label::Label res2 = label::Label(std::move(data.second));
 	return label::Label(label::LabelPairLabel(std::make_pair(std::move(res1), std::move(res2))));
 }
 
@@ -54,7 +54,7 @@ label::Label packToStackSymbolLabel(std::pair<std::set<std::pair<label::Label, l
 		label::Label res2 = label::Label(label::ObjectLabel(alib::Object(std::move(data.second.get<string::Epsilon < >>()))));
 		return label::Label(label::LabelPairLabel(std::make_pair(std::move(res1), std::move(res2))));
 	} else {
-		label::Label res2 = label::Label(label::ObjectLabel(alib::Object(std::move(data.second.get<alphabet::Symbol>().getData()))));
+		label::Label res2 = label::Label(std::move(data.second.get<alphabet::Symbol>()));
 		return label::Label(label::LabelPairLabel(std::make_pair(std::move(res1), std::move(res2))));
 	}
 }
diff --git a/alib2algo/src/grammar/convert/ToAutomaton.cpp b/alib2algo/src/grammar/convert/ToAutomaton.cpp
index 628809810e..c0985a0853 100644
--- a/alib2algo/src/grammar/convert/ToAutomaton.cpp
+++ b/alib2algo/src/grammar/convert/ToAutomaton.cpp
@@ -8,7 +8,6 @@
 
 #include <common/createUnique.hpp>
 
-#include <label/ObjectLabel.h>
 #include <label/Label.h>
 #include <label/InitialStateLabel.h>
 #include <label/FinalStateLabel.h>
@@ -27,7 +26,7 @@ automaton::NFA < > ToAutomaton::convert(const grammar::LeftRG < > & grammar) {
 
 	// step 2
 	for(const auto& symbol : grammar.getNonterminalAlphabet()) {
-		label::Label state( label::ObjectLabel ( alib::Object ( symbol.getData() ) ));
+		label::Label state( symbol );
 		states.insert(state);
 		stateMap.insert(std::make_pair(symbol, state));
 	}
@@ -70,7 +69,7 @@ automaton::NFA < > ToAutomaton::convert(const grammar::RightRG < > & grammar) {
 
 	// step2
 	for(const auto& symbol : grammar.getNonterminalAlphabet()) {
-		label::Label state( label::ObjectLabel ( alib::Object ( symbol.getData() ) ));
+		label::Label state( symbol );
 		states.insert(state);
 		stateMap.insert(std::make_pair(symbol, state));
 	}
diff --git a/alib2algo/src/regexp/convert/ToAutomatonGlushkov.cpp b/alib2algo/src/regexp/convert/ToAutomatonGlushkov.cpp
index 9accdd3034..2ba2376700 100644
--- a/alib2algo/src/regexp/convert/ToAutomatonGlushkov.cpp
+++ b/alib2algo/src/regexp/convert/ToAutomatonGlushkov.cpp
@@ -9,10 +9,8 @@
 
 #include "label/Label.h"
 #include "label/LabelPairLabel.h"
-#include "label/ObjectLabel.h"
 #include <automaton/Automaton.h>
 
-#include "object/Object.h"
 #include <global/GlobalData.h>
 
 #include "../glushkov/GlushkovFirst.h"
@@ -48,24 +46,24 @@ automaton::NFA < > ToAutomatonGlushkov::convert ( const regexp::UnboundedRegExp
 
 	 // step 5
 	for ( auto const & symbol : indexedRegExp.getAlphabet ( ) )
-		automaton.addState ( label::Label ( label::ObjectLabel ( alib::Object ( symbol.getData ( ) ) ) ) );
+		automaton.addState ( label::Label ( symbol ) );
 
 	 // step 6
 	for ( auto const & symbol : first )
-		automaton.addTransition ( q0, regexp::GlushkovIndexate::getSymbolFromGlushkovPair ( symbol.getSymbol ( ) ), label::Label ( label::ObjectLabel ( alib::Object ( symbol.getSymbol ( ).getData ( ) ) ) ) );
+		automaton.addTransition ( q0, regexp::GlushkovIndexate::getSymbolFromGlushkovPair ( symbol.getSymbol ( ) ), label::Label ( symbol.getSymbol ( ) ) );
 
 	for ( const auto & x : indexedRegExp.getAlphabet ( ) )
 		for ( const auto & f : regexp::GlushkovFollow::follow ( indexedRegExp, UnboundedRegExpSymbol < alphabet::Symbol > ( x ) ) ) {
 			const alphabet::Symbol & p = x;
 			const alphabet::Symbol & q = f.getSymbol ( );
 
-			automaton.addTransition ( label::Label ( label::ObjectLabel ( alib::Object ( p.getData ( ) ) ) ), regexp::GlushkovIndexate::getSymbolFromGlushkovPair ( q ), label::Label ( label::ObjectLabel ( alib::Object ( q.getData ( ) ) ) ) );
+			automaton.addTransition ( label::Label ( p ), regexp::GlushkovIndexate::getSymbolFromGlushkovPair ( q ), label::Label ( q ) );
 		}
 
 	// step 7
 
 	for ( auto const & symbol : last )
-		automaton.addFinalState ( label::Label ( label::ObjectLabel ( alib::Object ( symbol.getSymbol ( ).getData ( ) ) ) ) );
+		automaton.addFinalState ( label::Label ( symbol.getSymbol ( ) ) );
 
 	if ( regexp::properties::RegExpEpsilon::languageContainsEpsilon ( regexp ) )
 		automaton.addFinalState ( q0 );
diff --git a/alib2algo/src/regexp/convert/ToGrammarRightRGGlushkov.cpp b/alib2algo/src/regexp/convert/ToGrammarRightRGGlushkov.cpp
index f9c1d3fbb4..5787d75864 100644
--- a/alib2algo/src/regexp/convert/ToGrammarRightRGGlushkov.cpp
+++ b/alib2algo/src/regexp/convert/ToGrammarRightRGGlushkov.cpp
@@ -12,9 +12,6 @@
 #include <alphabet/InitialSymbol.h>
 
 #include <label/LabelPairLabel.h>
-#include <label/ObjectLabel.h>
-
-#include <object/Object.h>
 
 #include "../glushkov/GlushkovFollow.h"
 #include "../glushkov/GlushkovIndexate.h"
diff --git a/alib2data/src/alphabet/Symbol.cpp b/alib2data/src/alphabet/Symbol.cpp
index 9d5828dbb7..5d188ac29f 100644
--- a/alib2data/src/alphabet/Symbol.cpp
+++ b/alib2data/src/alphabet/Symbol.cpp
@@ -8,6 +8,7 @@
 #include "Symbol.h"
 #include "LabeledSymbol.h"
 #include <core/xmlApi.hpp>
+#include "label/Label.h"
 
 namespace alphabet {
 
@@ -15,7 +16,10 @@ void Symbol::inc ( ) {
 	this->operator ++ ( );
 }
 
-Symbol::Symbol ( label::Label label ) : alib::WrapperBase < SymbolBase > ( alphabet::LabeledSymbol { std::move ( label ) } ) {
+Symbol::Symbol ( const label::Label & label ) : alib::WrapperBase < SymbolBase > ( alphabet::LabeledSymbol { label } ) {
+}
+
+Symbol::Symbol ( label::Label && label ) : alib::WrapperBase < SymbolBase > ( alphabet::LabeledSymbol { std::move ( label ) } ) {
 }
 
 Symbol::Symbol ( int number ) : Symbol ( label::Label ( number ) ) {
diff --git a/alib2data/src/alphabet/Symbol.h b/alib2data/src/alphabet/Symbol.h
index 6a2012e6d8..9ee50e0d24 100644
--- a/alib2data/src/alphabet/Symbol.h
+++ b/alib2data/src/alphabet/Symbol.h
@@ -14,7 +14,7 @@
 #include <set>
 #include <string>
 
-#include <label/Label.h>
+#include <label/LabelFeatures.h>
 
 namespace alphabet {
 
@@ -25,7 +25,8 @@ class Symbol : public alib::WrapperBase < SymbolBase > {
 	using alib::WrapperBase < SymbolBase >::WrapperBase;
 
 public:
-	explicit Symbol ( label::Label label );
+	explicit Symbol ( const label::Label & label );
+	explicit Symbol ( label::Label && label );
 	explicit Symbol ( int number );
 	explicit Symbol ( char character );
 	explicit Symbol ( std::string string );
diff --git a/alib2data/src/label/Label.cpp b/alib2data/src/label/Label.cpp
index fe4eb5af54..752f31a6d1 100644
--- a/alib2data/src/label/Label.cpp
+++ b/alib2data/src/label/Label.cpp
@@ -10,6 +10,9 @@
 #include "LabelPairLabel.h"
 #include <primitive/Primitive.h>
 #include <core/xmlApi.hpp>
+#include <object/Object.h>
+#include "ObjectLabel.h"
+#include <alphabet/Symbol.h>
 
 namespace label {
 
@@ -17,6 +20,12 @@ void Label::inc ( ) {
 	this->operator ++ ();
 }
 
+Label::Label ( const alphabet::Symbol & symbol ) : alib::WrapperBase < LabelBase > ( label::ObjectLabel ( alib::Object ( symbol.getData ( ) ) ) ) {
+}
+
+Label::Label ( alphabet::Symbol && symbol ) : alib::WrapperBase < LabelBase > ( label::ObjectLabel ( alib::Object ( std::move ( symbol.getData ( ) ) ) ) ) {
+}
+
 Label::Label ( int number ) : alib::WrapperBase < LabelBase > ( label::PrimitiveLabel ( primitive::Primitive ( number ) ) ) {
 }
 
diff --git a/alib2data/src/label/Label.h b/alib2data/src/label/Label.h
index e9f1524327..aa0e2ba4d0 100644
--- a/alib2data/src/label/Label.h
+++ b/alib2data/src/label/Label.h
@@ -12,6 +12,7 @@
 #include "LabelBase.h"
 
 #include <set>
+#include <alphabet/SymbolFeatures.h>
 
 namespace label {
 
@@ -22,6 +23,8 @@ class Label : public alib::WrapperBase < LabelBase > {
 	using alib::WrapperBase < LabelBase >::WrapperBase;
 
 public:
+	explicit Label ( const alphabet::Symbol & );
+	explicit Label ( alphabet::Symbol && );
 	explicit Label ( label::Label label1, label::Label label2 );
 	explicit Label ( int number );
 	explicit Label ( int number1, int number2 );
-- 
GitLab