From 831c5c64d08f61f0ee7f76a9d6fbdeab66690b5f Mon Sep 17 00:00:00 2001
From: Jan Travnicek <Jan.Travnicek@fit.cvut.cz>
Date: Tue, 12 Aug 2014 20:39:22 +0200
Subject: [PATCH] templated symbol base class

---
 alib2data/src/alphabet/BlankSymbol.h          |  4 ++
 .../src/alphabet/BottomOfTheStackSymbol.h     |  4 ++
 alib2data/src/alphabet/EndSymbol.h            |  4 ++
 alib2data/src/alphabet/LabeledSymbol.h        |  4 ++
 alib2data/src/alphabet/SymbolBase.cpp         | 71 -------------------
 alib2data/src/alphabet/SymbolBase.h           | 37 ++--------
 6 files changed, 20 insertions(+), 104 deletions(-)
 delete mode 100644 alib2data/src/alphabet/SymbolBase.cpp

diff --git a/alib2data/src/alphabet/BlankSymbol.h b/alib2data/src/alphabet/BlankSymbol.h
index 7f330893e7..c0942dd4a4 100644
--- a/alib2data/src/alphabet/BlankSymbol.h
+++ b/alib2data/src/alphabet/BlankSymbol.h
@@ -37,6 +37,10 @@ public:
 	
 	virtual operator std::string () const;
 
+	virtual int selfTypeId() const {
+		return typeId(*this);
+	}
+
 	static BlankSymbol BLANK;
 };
 
diff --git a/alib2data/src/alphabet/BottomOfTheStackSymbol.h b/alib2data/src/alphabet/BottomOfTheStackSymbol.h
index eebc152cca..cfcc6c5b4c 100644
--- a/alib2data/src/alphabet/BottomOfTheStackSymbol.h
+++ b/alib2data/src/alphabet/BottomOfTheStackSymbol.h
@@ -37,6 +37,10 @@ public:
 	
 	virtual operator std::string () const;
 
+	virtual int selfTypeId() const {
+		return typeId(*this);
+	}
+
 	static BottomOfTheStackSymbol BOTTOM_OF_THE_STACK;
 };
 
diff --git a/alib2data/src/alphabet/EndSymbol.h b/alib2data/src/alphabet/EndSymbol.h
index 9640b4fe29..e629d5946a 100644
--- a/alib2data/src/alphabet/EndSymbol.h
+++ b/alib2data/src/alphabet/EndSymbol.h
@@ -37,6 +37,10 @@ public:
 	
 	virtual operator std::string () const;
 
+	virtual int selfTypeId() const {
+		return typeId(*this);
+	}
+
 	static EndSymbol END;
 };
 
diff --git a/alib2data/src/alphabet/LabeledSymbol.h b/alib2data/src/alphabet/LabeledSymbol.h
index 2bc0ffc661..7feac2ad7b 100644
--- a/alib2data/src/alphabet/LabeledSymbol.h
+++ b/alib2data/src/alphabet/LabeledSymbol.h
@@ -47,6 +47,10 @@ public:
 	virtual void operator>>(std::ostream& out) const;
 
 	virtual operator std::string () const;
+
+	virtual int selfTypeId() const {
+		return typeId(*this);
+	}
 };
 
 } /* namespace alphabet */
diff --git a/alib2data/src/alphabet/SymbolBase.cpp b/alib2data/src/alphabet/SymbolBase.cpp
deleted file mode 100644
index 5b5bd2ff81..0000000000
--- a/alib2data/src/alphabet/SymbolBase.cpp
+++ /dev/null
@@ -1,71 +0,0 @@
-/*
- * SymbolBase.cpp
- *
- *  Created on: Mar 26, 2013
- *      Author: Jan Travnicek
- */
-
-#include "SymbolBase.h"
-#include <typeinfo>
-
-#include "LabeledSymbol.h"
-#include "BlankSymbol.h"
-#include "BottomOfTheStackSymbol.h"
-#include "EndSymbol.h"
-
-namespace alphabet {
-
-SymbolBase::~SymbolBase() noexcept {
-
-}
-
-bool SymbolBase::operator>=(const SymbolBase& other) const {
-	return !(*this < other);
-}
-
-bool SymbolBase::operator<=(const SymbolBase& other) const {
-	return !(*this > other);
-}
-
-bool SymbolBase::operator !=(const SymbolBase& other) const {
-	return !(*this == other);
-}
-
-std::ostream& operator<<(std::ostream& out, const SymbolBase& symbol) {
-	symbol >> out;
-	return out;
-}
-
-bool SymbolBase::operator==(const LabeledSymbol&) const {
-	return false;
-}
-
-bool SymbolBase::operator==(const BlankSymbol&) const {
-	return false;
-}
-
-bool SymbolBase::operator==(const BottomOfTheStackSymbol&) const {
-	return false;
-}
-
-bool SymbolBase::operator==(const EndSymbol&) const {
-	return false;
-}
-
-bool SymbolBase::operator<(const LabeledSymbol& other) const {
-	return typeid(*this).before(typeid(other));
-}
-
-bool SymbolBase::operator<(const BlankSymbol& other) const {
-	return typeid(*this).before(typeid(other));
-}
-
-bool SymbolBase::operator<(const BottomOfTheStackSymbol& other) const {
-	return typeid(*this).before(typeid(other));
-}
-
-bool SymbolBase::operator<(const EndSymbol& other) const {
-	return typeid(*this).before(typeid(other));
-}
-
-} /* namespace alphabet */
diff --git a/alib2data/src/alphabet/SymbolBase.h b/alib2data/src/alphabet/SymbolBase.h
index 8d3ae6d977..f111958a0d 100644
--- a/alib2data/src/alphabet/SymbolBase.h
+++ b/alib2data/src/alphabet/SymbolBase.h
@@ -8,9 +8,10 @@
 #ifndef SYMBOL_BASE_H_
 #define SYMBOL_BASE_H_
 
+#include "../std/variant.hpp"
 #include "../label/LabelBase.h"
-#include <ostream>
-	
+#include "../common/base.hpp"
+
 namespace alphabet {
 
 class LabeledSymbol;
@@ -21,37 +22,7 @@ class EndSymbol;
 /**
  * Represents symbol in an alphabet.
  */
-class SymbolBase : public std::elementBase<LabeledSymbol, BlankSymbol, BottomOfTheStackSymbol, EndSymbol> {
-public:
-	virtual ~SymbolBase() noexcept;
-
-	virtual SymbolBase* clone() const = 0;
-	virtual SymbolBase* plunder() && = 0;
-
-	bool operator>=(const SymbolBase& other) const;
-
-	bool operator<=(const SymbolBase& other) const;
-
-	bool operator !=(const SymbolBase& other) const;
-
-	virtual bool operator==(const SymbolBase& other) const = 0;
-	virtual bool operator==(const LabeledSymbol& other) const;
-	virtual bool operator==(const BlankSymbol& other) const;
-	virtual bool operator==(const BottomOfTheStackSymbol& other) const;
-	virtual bool operator==(const EndSymbol& other) const;
-
-	virtual bool operator<(const SymbolBase& other) const = 0;
-	virtual bool operator<(const LabeledSymbol& other) const;
-	virtual bool operator<(const BlankSymbol& other) const;
-	virtual bool operator<(const BottomOfTheStackSymbol& other) const;
-	virtual bool operator<(const EndSymbol& other) const;
-	virtual bool operator>(const SymbolBase& other) const = 0;
-
-	friend std::ostream& operator<<(std::ostream&, const SymbolBase&);
-
-	virtual void operator>>(std::ostream& out) const = 0;
-
-	virtual operator std::string () const = 0;
+class SymbolBase : public alib::base<SymbolBase, LabeledSymbol, BlankSymbol, BottomOfTheStackSymbol, EndSymbol>, public std::elementBase<LabeledSymbol, BlankSymbol, BottomOfTheStackSymbol, EndSymbol> {
 };
 
 } /* namespace alphabet */
-- 
GitLab