diff --git a/alib2data/src/common/base.hpp b/alib2data/src/common/base.hpp new file mode 100644 index 0000000000000000000000000000000000000000..5d52d7db9051c8dc7b8a3dd209727bb89d474be2 --- /dev/null +++ b/alib2data/src/common/base.hpp @@ -0,0 +1,77 @@ +/* + * Base.h + * + * Created on: Apr 05, 2014 + * Author: Jan Travnicek + */ + +#ifndef BASE_H_ +#define BASE_H_ + +#include <typeinfo> +#include <ostream> + +namespace alib { + +template<typename... Types> +class base_helper; + +template<typename T> +class base_helper<T> { +public: + virtual bool operator==(const T &) const { + return false; + } + + virtual bool operator<(const T & other) const { + return typeid(*this).before(typeid(other)); + } + + virtual ~base_helper() noexcept { + + } +}; + +template<typename T, typename... Types> +class base_helper<T, Types...> : public base_helper<Types...> { +public: + using base_helper<Types...>::operator==; + using base_helper<Types...>::operator<; + + virtual bool operator==(const T &) const { + return false; + } + + virtual bool operator<(const T & other) const { + return typeid(*this).before(typeid(other)); + } +}; + +template<typename T, typename... Types> +class base : public base_helper<Types...> { +public: + using base_helper<Types...>::operator==; + using base_helper<Types...>::operator<; + + virtual T* clone() const = 0; + + virtual T* plunder() && = 0; + + virtual bool operator==(const T& other) const = 0; + + virtual bool operator<(const T& other) const = 0; + virtual bool operator>(const T& other) const = 0; + + friend std::ostream& operator<<(std::ostream& os, const T& instance) { + instance >> os; + return os; + } + + virtual void operator>>(std::ostream&) const = 0; + + virtual operator std::string () const = 0; +}; + +} /* namespace alib */ + +#endif /* BASE_H_ */ diff --git a/alib2data/src/regexp/RegExpBase.cpp b/alib2data/src/regexp/RegExpBase.cpp deleted file mode 100644 index b91b26a64caf74774b30335aada70d0a9de210a7..0000000000000000000000000000000000000000 --- a/alib2data/src/regexp/RegExpBase.cpp +++ /dev/null @@ -1,54 +0,0 @@ -/* - * RegExpBase.cpp - * - * Created on: Apr 16, 2013 - * Author: Jan Travnicek - */ - -#include "RegExpBase.h" -#include <typeinfo> - -#include "unbounded/UnboundedRegExp.h" -#include "formal/FormalRegExp.h" - -namespace regexp { - -RegExpBase::~RegExpBase() { - -} - -bool RegExpBase::operator<(const UnboundedRegExp& other) const { - return typeid(*this).before(typeid(other)); -} - -bool RegExpBase::operator<(const FormalRegExp& other) const { - return typeid(*this).before(typeid(other)); -} - -bool RegExpBase::operator>=(const RegExpBase& other) const { - return !(*this < other); -} - -bool RegExpBase::operator<=(const RegExpBase& other) const { - return !(*this > other); -} - -bool RegExpBase::operator!=(const RegExpBase& other) const { - return !(*this == other); -} - -bool RegExpBase::operator==(const UnboundedRegExp&) const { - return false; -} - -bool RegExpBase::operator==(const FormalRegExp&) const { - return false; -} - -std::ostream& operator<<(std::ostream& os, const RegExpBase& regexp) { - regexp >> os; - return os; -} - -} /* namespace regexp */ - diff --git a/alib2data/src/regexp/RegExpBase.h b/alib2data/src/regexp/RegExpBase.h index 0b29b7dffd360b3f88d41dba64279cf8d5460632..dd2340321812078df31fb778e0c2fc07566085bf 100644 --- a/alib2data/src/regexp/RegExpBase.h +++ b/alib2data/src/regexp/RegExpBase.h @@ -9,7 +9,7 @@ #define REG_EXP_BASE_H_ #include "../std/visitor.hpp" -#include <iostream> +#include "../common/base.hpp" namespace regexp { @@ -19,34 +19,7 @@ class FormalRegExp; /** * Abstract base class for all automata. */ -class RegExpBase : public std::elementBase<UnboundedRegExp, FormalRegExp> { -public: - virtual RegExpBase* clone() const = 0; - - virtual RegExpBase* plunder() && = 0; - - virtual ~RegExpBase() noexcept; - - bool operator>=(const RegExpBase& other) const; - - bool operator<=(const RegExpBase& other) const; - - bool operator !=(const RegExpBase& other) const; - - virtual bool operator==(const RegExpBase& other) const = 0; - virtual bool operator==(const FormalRegExp& other) const; - virtual bool operator==(const UnboundedRegExp& other) const; - - virtual bool operator<(const RegExpBase& other) const = 0; - virtual bool operator<(const FormalRegExp& other) const; - virtual bool operator<(const UnboundedRegExp& other) const; - virtual bool operator>(const RegExpBase& other) const = 0; - - friend std::ostream& operator<<(std::ostream& os, const RegExpBase& regexp); - - virtual void operator>>(std::ostream&) const = 0; - - virtual operator std::string () const = 0; +class RegExpBase : public alib::base<RegExpBase, UnboundedRegExp, FormalRegExp>, public std::elementBase<UnboundedRegExp, FormalRegExp> { }; } /* namespace regexp */