Skip to content
Snippets Groups Projects
Commit 14455d85 authored by Jan Trávníček's avatar Jan Trávníček
Browse files

templated base of data classes

parent 0c029504
No related merge requests found
/*
* 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_ */
/*
* 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 */
......@@ -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 */
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment