diff --git a/alib2data/src/alphabet/BlankSymbol.h b/alib2data/src/alphabet/BlankSymbol.h index 7f330893e7ea9d6a017e281033a7df19f0848721..c0942dd4a4007774de48571e6014d8deb6863434 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 eebc152cca9d73f6665ccf505e810fecc2c88c71..cfcc6c5b4c269c17b2820e24b6e41252f6f4b2d6 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 9640b4fe29aa2208f251128c468a9f9eae3dcfe6..e629d5946a22449ff899c6cb50fc6655982a2b80 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 2bc0ffc66149425a82f6a968a0c0a6dfc2207c1a..7feac2ad7b347b6a0d49d76326bf1001dcef8ca5 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 5b5bd2ff81d7463f524e0600d56d0d961990a712..0000000000000000000000000000000000000000 --- 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 8d3ae6d9772a730ac34fef26a5162cfac514281e..f111958a0d0fb072eee946d33bde3e592d7251f0 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 */