2021-05-11 06:51:06 +02:00
|
|
|
|
|
|
|
#ifndef CONTAINER_HPP
|
|
|
|
#define CONTAINER_HPP
|
|
|
|
|
|
|
|
/* ************************************************************************** */
|
|
|
|
|
|
|
|
#include <stdexcept>
|
|
|
|
#include <functional>
|
|
|
|
|
|
|
|
/* ************************************************************************** */
|
|
|
|
|
|
|
|
namespace lasd {
|
|
|
|
|
|
|
|
/* ************************************************************************** */
|
|
|
|
|
|
|
|
class Container {
|
|
|
|
private:
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
2021-05-11 06:52:44 +02:00
|
|
|
ulong size = 0;
|
2021-05-11 06:51:06 +02:00
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
// Destructor
|
2021-05-11 06:52:44 +02:00
|
|
|
virtual ~Container() = default;
|
2021-05-11 06:51:06 +02:00
|
|
|
|
|
|
|
// Copy assignment
|
2021-05-11 06:52:44 +02:00
|
|
|
Container& operator=(const Container&) = delete; // Copy assignment of abstract types should not be possible.
|
2021-05-11 06:51:06 +02:00
|
|
|
|
|
|
|
// Move assignment
|
2021-05-11 06:52:44 +02:00
|
|
|
Container& operator=(Container&&) noexcept = delete;; // Move assignment of abstract types should not be possible.
|
2021-05-11 06:51:06 +02:00
|
|
|
|
|
|
|
// Comparison operators
|
2021-05-11 06:52:44 +02:00
|
|
|
bool operator==(const Container&) const noexcept = delete; // Comparison of abstract types might not be possible.
|
|
|
|
bool operator!=(const Container&&) const noexcept = delete; // Comparison of abstract types might not be possible.
|
2021-05-11 06:51:06 +02:00
|
|
|
|
|
|
|
// Specific member functions
|
2021-05-11 06:52:44 +02:00
|
|
|
virtual bool Empty() const noexcept {
|
|
|
|
return (size == 0);
|
|
|
|
} // (concrete function should not throw exceptions)
|
2021-05-11 06:51:06 +02:00
|
|
|
|
2021-05-11 06:52:44 +02:00
|
|
|
virtual ulong Size() const noexcept {
|
|
|
|
return size;
|
|
|
|
} // (concrete function should not throw exceptions)
|
2021-05-11 06:51:06 +02:00
|
|
|
|
2021-05-11 06:52:44 +02:00
|
|
|
virtual void Clear() = 0;
|
2021-05-11 06:51:06 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
template <typename Data>
|
2021-05-11 06:52:44 +02:00
|
|
|
class LinearContainer : virtual public Container{ // Must extend Container
|
2021-05-11 06:51:06 +02:00
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
// Destructor
|
2021-05-11 06:52:44 +02:00
|
|
|
virtual ~LinearContainer() = default;
|
2021-05-11 06:51:06 +02:00
|
|
|
|
|
|
|
// Copy assignment
|
2021-05-11 06:52:44 +02:00
|
|
|
LinearContainer& operator=(const LinearContainer&) = delete; // Copy assignment of abstract types should not be possible.
|
2021-05-11 06:51:06 +02:00
|
|
|
|
|
|
|
// Move assignment
|
2021-05-11 06:52:44 +02:00
|
|
|
LinearContainer& operator=(LinearContainer&&) noexcept = delete; // Move assignment of abstract types should not be possible.
|
2021-05-11 06:51:06 +02:00
|
|
|
|
|
|
|
// Comparison operators
|
2021-05-11 06:52:44 +02:00
|
|
|
bool operator==(const LinearContainer&) const noexcept = delete; // Comparison of abstract types might not be possible.
|
|
|
|
bool operator!=(const LinearContainer&) const noexcept = delete; // Comparison of abstract types might not be possible.
|
2021-05-11 06:51:06 +02:00
|
|
|
|
|
|
|
/* ************************************************************************ */
|
|
|
|
|
|
|
|
// Specific member functions
|
2021-05-11 06:52:44 +02:00
|
|
|
virtual Data& Front() const = 0; // (concrete function must throw std::length_error when empty)
|
|
|
|
virtual Data& Back() const = 0; // (concrete function must throw std::length_error when empty)
|
2021-05-11 06:51:06 +02:00
|
|
|
|
2021-05-11 06:52:44 +02:00
|
|
|
virtual Data& operator[](const ulong) const = 0; // (concrete function must throw std::out_of_range when out of range)
|
2021-05-11 06:51:06 +02:00
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
template <typename Data>
|
2021-05-11 06:52:44 +02:00
|
|
|
class TestableContainer : virtual public Container{ // Must extend Container
|
2021-05-11 06:51:06 +02:00
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
// Destructor
|
2021-05-11 06:52:44 +02:00
|
|
|
virtual ~TestableContainer() = default;
|
2021-05-11 06:51:06 +02:00
|
|
|
|
|
|
|
// Copy assignment
|
2021-05-11 06:52:44 +02:00
|
|
|
TestableContainer& operator=(const TestableContainer&) = delete; // Copy assignment of abstract types should not be possible.
|
2021-05-11 06:51:06 +02:00
|
|
|
|
|
|
|
// Move assignment
|
2021-05-11 06:52:44 +02:00
|
|
|
TestableContainer& operator=(TestableContainer&&) noexcept = delete; // Move assignment of abstract types should not be possible.
|
2021-05-11 06:51:06 +02:00
|
|
|
|
|
|
|
// Comparison operators
|
2021-05-11 06:52:44 +02:00
|
|
|
bool operator==(const TestableContainer&) const noexcept = delete; // Comparison of abstract types might not be possible.
|
|
|
|
bool operator!=(const TestableContainer&) const noexcept = delete; // Comparison of abstract types might not be possible.
|
2021-05-11 06:51:06 +02:00
|
|
|
|
|
|
|
/* ************************************************************************ */
|
|
|
|
|
|
|
|
// Specific member functions
|
2021-05-11 06:52:44 +02:00
|
|
|
virtual bool Exists(const Data&) const noexcept = 0; // (concrete function should not throw exceptions)
|
2021-05-11 06:51:06 +02:00
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
template <typename Data>
|
2021-05-11 06:52:44 +02:00
|
|
|
class MappableContainer : virtual public Container { // Must extend Container
|
2021-05-11 06:51:06 +02:00
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
// Destructor
|
2021-05-11 06:52:44 +02:00
|
|
|
virtual ~MappableContainer() = default;
|
2021-05-11 06:51:06 +02:00
|
|
|
|
|
|
|
// Copy assignment
|
2021-05-11 06:52:44 +02:00
|
|
|
MappableContainer& operator=(const MappableContainer&) = delete; // Copy assignment of abstract types should not be possible.
|
2021-05-11 06:51:06 +02:00
|
|
|
|
|
|
|
// Move assignment
|
2021-05-11 06:52:44 +02:00
|
|
|
MappableContainer& operator=(MappableContainer&&) noexcept = delete; // Move assignment of abstract types should not be possible.
|
2021-05-11 06:51:06 +02:00
|
|
|
|
|
|
|
// Comparison operators
|
2021-05-11 06:52:44 +02:00
|
|
|
bool operator==(const MappableContainer&) const noexcept = delete; // Comparison of abstract types might not be possible.
|
|
|
|
bool operator!=(const MappableContainer&) const noexcept = delete; // Comparison of abstract types might not be possible.
|
2021-05-11 06:51:06 +02:00
|
|
|
|
|
|
|
// Specific member functions
|
|
|
|
|
2021-05-11 06:52:44 +02:00
|
|
|
typedef std::function<void(Data&, void*)> MapFunctor;
|
2021-05-11 06:51:06 +02:00
|
|
|
|
2021-05-11 06:52:44 +02:00
|
|
|
virtual void MapPreOrder(const MapFunctor, void*) = 0;
|
|
|
|
virtual void MapPostOrder(const MapFunctor, void*) = 0;
|
2021-05-11 06:51:06 +02:00
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
template <typename Data>
|
2021-05-11 06:52:44 +02:00
|
|
|
class FoldableContainer : virtual public TestableContainer<Data>{ // Must extend TestableContainer
|
2021-05-11 06:51:06 +02:00
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
// Destructor
|
2021-05-11 06:52:44 +02:00
|
|
|
virtual ~FoldableContainer() = default;
|
2021-05-11 06:51:06 +02:00
|
|
|
|
|
|
|
// Copy assignment
|
2021-05-11 06:52:44 +02:00
|
|
|
FoldableContainer& operator=(const FoldableContainer&) = delete; // Copy assignment of abstract types should not be possible.
|
2021-05-11 06:51:06 +02:00
|
|
|
|
|
|
|
// Move assignment
|
2021-05-11 06:52:44 +02:00
|
|
|
FoldableContainer& operator=(FoldableContainer&&) noexcept = delete; // Move assignment of abstract types should not be possible.
|
2021-05-11 06:51:06 +02:00
|
|
|
|
|
|
|
// Comparison operators
|
2021-05-11 06:52:44 +02:00
|
|
|
bool operator==(FoldableContainer&) const noexcept = delete; // Comparison of abstract types might not be possible.
|
|
|
|
bool operator!=(FoldableContainer&) const noexcept = delete; // Comparison of abstract types might not be possible.
|
2021-05-11 06:51:06 +02:00
|
|
|
|
|
|
|
// Specific member functions
|
|
|
|
|
2021-05-11 06:52:44 +02:00
|
|
|
typedef std::function<void(const Data&, const void*, void*) noexcept> FoldFunctor;
|
2021-05-11 06:51:06 +02:00
|
|
|
|
2021-05-11 06:52:44 +02:00
|
|
|
virtual void FoldPreOrder(const FoldFunctor, const void*, void*) const = 0;
|
|
|
|
virtual void FoldPostOrder(const FoldFunctor, const void*, void*) const = 0;
|
2021-05-11 06:51:06 +02:00
|
|
|
|
2021-05-11 06:52:44 +02:00
|
|
|
virtual bool Exists(const Data&) const noexcept override; // Override TestableContainer member
|
2021-05-11 06:51:06 +02:00
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
/* ************************************************************************** */
|
|
|
|
|
|
|
|
template <typename Data>
|
2021-05-11 06:52:44 +02:00
|
|
|
class InOrderMappableContainer : virtual public MappableContainer<Data> { // Must extend MappableContainer
|
2021-05-11 06:51:06 +02:00
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
// Destructor
|
2021-05-11 06:52:44 +02:00
|
|
|
virtual ~InOrderMappableContainer() = default;
|
2021-05-11 06:51:06 +02:00
|
|
|
|
|
|
|
/* ************************************************************************ */
|
|
|
|
|
|
|
|
// Copy assignment
|
2021-05-11 06:52:44 +02:00
|
|
|
InOrderMappableContainer& operator=(const InOrderMappableContainer&) = delete; // Copy assignment of abstract types should not be possible.
|
2021-05-11 06:51:06 +02:00
|
|
|
|
|
|
|
// Move assignment
|
2021-05-11 06:52:44 +02:00
|
|
|
InOrderMappableContainer& operator=(InOrderMappableContainer&&) noexcept = delete; // Move assignment of abstract types should not be possible.
|
2021-05-11 06:51:06 +02:00
|
|
|
|
|
|
|
/* ************************************************************************ */
|
|
|
|
|
|
|
|
// Comparison operators
|
2021-05-11 06:52:44 +02:00
|
|
|
bool operator==(const InOrderMappableContainer&) const noexcept = delete; // Comparison of abstract types might not be possible.
|
|
|
|
bool operator!=(const InOrderMappableContainer&) const noexcept = delete; // Comparison of abstract types might not be possible.
|
2021-05-11 06:51:06 +02:00
|
|
|
|
|
|
|
/* ************************************************************************ */
|
|
|
|
|
|
|
|
// Specific member functions
|
2021-05-11 06:52:44 +02:00
|
|
|
virtual void MapInOrder(const typename MappableContainer<Data>::MapFunctor, void*) = 0;
|
2021-05-11 06:51:06 +02:00
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
/* ************************************************************************** */
|
|
|
|
|
|
|
|
template <typename Data>
|
2021-05-11 06:52:44 +02:00
|
|
|
class InOrderFoldableContainer : public virtual FoldableContainer<Data> { // Must extend FoldableContainer
|
2021-05-11 06:51:06 +02:00
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
// Destructor
|
2021-05-11 06:52:44 +02:00
|
|
|
virtual ~InOrderFoldableContainer() = default;
|
2021-05-11 06:51:06 +02:00
|
|
|
|
|
|
|
/* ************************************************************************ */
|
|
|
|
|
|
|
|
// Copy assignment
|
2021-05-11 06:52:44 +02:00
|
|
|
InOrderFoldableContainer& operator=(const InOrderFoldableContainer&) = delete; // Copy assignment of abstract types should not be possible.
|
2021-05-11 06:51:06 +02:00
|
|
|
|
|
|
|
// Move assignment
|
2021-05-11 06:52:44 +02:00
|
|
|
InOrderFoldableContainer& operator=(InOrderFoldableContainer&&) noexcept = delete; // Move assignment of abstract types should not be possible.
|
2021-05-11 06:51:06 +02:00
|
|
|
|
|
|
|
/* ************************************************************************ */
|
|
|
|
|
|
|
|
// Comparison operators
|
2021-05-11 06:52:44 +02:00
|
|
|
bool operator==(const InOrderFoldableContainer&) const noexcept = delete; // Comparison of abstract types might not be possible.
|
|
|
|
bool operator!=(const InOrderFoldableContainer&) const noexcept = delete; // Comparison of abstract types might not be possible.
|
2021-05-11 06:51:06 +02:00
|
|
|
|
|
|
|
/* ************************************************************************ */
|
|
|
|
|
|
|
|
// Specific member functions
|
|
|
|
|
2021-05-11 06:52:44 +02:00
|
|
|
virtual void FoldInOrder(const typename FoldableContainer<Data>::FoldFunctor, const void*, void*) const = 0;
|
2021-05-11 06:51:06 +02:00
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
/* ************************************************************************** */
|
|
|
|
|
|
|
|
template <typename Data>
|
2021-05-11 06:52:44 +02:00
|
|
|
class BreadthMappableContainer : virtual public MappableContainer<Data> { // Must extend MappableContainer
|
2021-05-11 06:51:06 +02:00
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
// Destructor
|
2021-05-11 06:52:44 +02:00
|
|
|
~BreadthMappableContainer() = default;
|
2021-05-11 06:51:06 +02:00
|
|
|
|
|
|
|
/* ************************************************************************ */
|
|
|
|
|
|
|
|
// Copy assignment
|
2021-05-11 06:52:44 +02:00
|
|
|
BreadthMappableContainer& operator=(const BreadthMappableContainer&) = delete; // Copy assignment of abstract types should not be possible.
|
2021-05-11 06:51:06 +02:00
|
|
|
|
|
|
|
// Move assignment
|
2021-05-11 06:52:44 +02:00
|
|
|
BreadthMappableContainer& operator=(BreadthMappableContainer&&) noexcept = delete; // Move assignment of abstract types should not be possible.
|
2021-05-11 06:51:06 +02:00
|
|
|
|
|
|
|
/* ************************************************************************ */
|
|
|
|
|
|
|
|
// Comparison operators
|
2021-05-11 06:52:44 +02:00
|
|
|
bool operator==(const BreadthMappableContainer&) const noexcept = delete; // Comparison of abstract types might not be possible.
|
|
|
|
bool operator!=(const BreadthMappableContainer&) const noexcept = delete; // Comparison of abstract types might not be possible.
|
2021-05-11 06:51:06 +02:00
|
|
|
|
|
|
|
/* ************************************************************************ */
|
|
|
|
|
|
|
|
// Specific member functions
|
|
|
|
|
2021-05-11 06:52:44 +02:00
|
|
|
virtual void MapBreadth(const typename MappableContainer<Data>::MapFunctor, void*) = 0;
|
2021-05-11 06:51:06 +02:00
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
/* ************************************************************************** */
|
|
|
|
|
|
|
|
template <typename Data>
|
2021-05-11 06:52:44 +02:00
|
|
|
class BreadthFoldableContainer : virtual public FoldableContainer<Data> { // Must extend FoldableContainer
|
2021-05-11 06:51:06 +02:00
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
// Destructor
|
2021-05-11 06:52:44 +02:00
|
|
|
virtual ~BreadthFoldableContainer() = default;
|
2021-05-11 06:51:06 +02:00
|
|
|
|
|
|
|
/* ************************************************************************ */
|
|
|
|
|
|
|
|
// Copy assignment
|
2021-05-11 06:52:44 +02:00
|
|
|
BreadthFoldableContainer& operator=(const BreadthFoldableContainer&) = delete; // Copy assignment of abstract types should not be possible.
|
2021-05-11 06:51:06 +02:00
|
|
|
|
|
|
|
// Move assignment
|
2021-05-11 06:52:44 +02:00
|
|
|
BreadthFoldableContainer& operator=(BreadthFoldableContainer&&) noexcept = delete; // Move assignment of abstract types should not be possible.
|
2021-05-11 06:51:06 +02:00
|
|
|
|
|
|
|
/* ************************************************************************ */
|
|
|
|
|
|
|
|
// Comparison operators
|
2021-05-11 06:52:44 +02:00
|
|
|
bool operator==(const BreadthFoldableContainer&) const noexcept = delete; // Comparison of abstract types might not be possible.
|
|
|
|
bool operator!=(const BreadthFoldableContainer&) const noexcept = delete; // Comparison of abstract types might not be possible.
|
2021-05-11 06:51:06 +02:00
|
|
|
|
|
|
|
/* ************************************************************************ */
|
|
|
|
|
|
|
|
// Specific member functions
|
|
|
|
|
2021-05-11 06:52:44 +02:00
|
|
|
using typename FoldableContainer<Data>::FoldFunctor;
|
2021-05-11 06:51:06 +02:00
|
|
|
|
2021-05-11 06:52:44 +02:00
|
|
|
virtual void FoldBreadth(const FoldFunctor, const void*, void*) const = 0;
|
2021-05-11 06:51:06 +02:00
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
/* ************************************************************************** */
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#include "container.cpp"
|
|
|
|
|
|
|
|
#endif
|