2021-04-10 13:34:50 +02:00
|
|
|
|
|
|
|
#ifndef CONTAINER_HPP
|
|
|
|
#define CONTAINER_HPP
|
|
|
|
|
|
|
|
#include <stdexcept>
|
|
|
|
#include <functional>
|
|
|
|
|
|
|
|
namespace lasd {
|
|
|
|
|
|
|
|
class Container {
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
2021-04-11 11:01:37 +02:00
|
|
|
ulong size = 0;
|
2021-04-10 13:34:50 +02:00
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
// Destructor
|
2021-04-11 11:01:37 +02:00
|
|
|
virtual ~Container() = default;
|
2021-04-10 13:34:50 +02:00
|
|
|
|
|
|
|
// Copy assignment
|
2021-04-11 11:01:37 +02:00
|
|
|
Container& operator=(const Container&) = delete; // Copy assignment of abstract types should not be possible.
|
2021-04-10 13:34:50 +02:00
|
|
|
|
|
|
|
// Move assignment
|
2021-04-11 11:01:37 +02:00
|
|
|
Container& operator=(Container&&) noexcept = delete;; // Move assignment of abstract types should not be possible.
|
2021-04-10 13:34:50 +02:00
|
|
|
|
|
|
|
// Comparison operators
|
2021-04-11 11:01:37 +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-04-10 13:34:50 +02:00
|
|
|
|
|
|
|
// Specific member functions
|
2021-04-11 11:01:37 +02:00
|
|
|
virtual bool Empty() const noexcept {
|
|
|
|
return (size == 0);
|
|
|
|
} // (concrete function should not throw exceptions)
|
2021-04-10 13:34:50 +02:00
|
|
|
|
2021-04-11 11:01:37 +02:00
|
|
|
virtual ulong Size() const noexcept {
|
|
|
|
return size;
|
|
|
|
} // (concrete function should not throw exceptions)
|
2021-04-10 13:34:50 +02:00
|
|
|
|
2021-04-11 11:01:37 +02:00
|
|
|
virtual void Clear() = 0;
|
2021-04-10 13:34:50 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
template <typename Data>
|
2021-04-11 11:01:37 +02:00
|
|
|
class LinearContainer : virtual public Container{ // Must extend Container
|
2021-04-10 13:34:50 +02:00
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
// Destructor
|
2021-04-11 11:01:37 +02:00
|
|
|
virtual ~LinearContainer() = default;
|
2021-04-10 13:34:50 +02:00
|
|
|
|
|
|
|
// Copy assignment
|
2021-04-11 11:01:37 +02:00
|
|
|
LinearContainer& operator=(const LinearContainer&) = delete; // Copy assignment of abstract types should not be possible.
|
2021-04-10 13:34:50 +02:00
|
|
|
|
|
|
|
// Move assignment
|
2021-04-11 11:01:37 +02:00
|
|
|
LinearContainer& operator=(LinearContainer&&) noexcept = delete; // Move assignment of abstract types should not be possible.
|
2021-04-10 13:34:50 +02:00
|
|
|
|
|
|
|
// Comparison operators
|
2021-04-11 11:01:37 +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-04-10 13:34:50 +02:00
|
|
|
|
|
|
|
/* ************************************************************************ */
|
|
|
|
|
|
|
|
// Specific member functions
|
2021-04-11 11:01:37 +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-04-10 13:34:50 +02:00
|
|
|
|
2021-04-11 11:01:37 +02:00
|
|
|
virtual Data& operator[](const ulong) const = 0; // (concrete function must throw std::out_of_range when out of range)
|
2021-04-10 13:34:50 +02:00
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
template <typename Data>
|
2021-04-11 11:01:37 +02:00
|
|
|
class TestableContainer : virtual public Container{ // Must extend Container
|
2021-04-10 13:34:50 +02:00
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
// Destructor
|
2021-04-11 11:01:37 +02:00
|
|
|
virtual ~TestableContainer() = default;
|
2021-04-10 13:34:50 +02:00
|
|
|
|
|
|
|
// Copy assignment
|
2021-04-11 11:01:37 +02:00
|
|
|
TestableContainer& operator=(const TestableContainer&) = delete; // Copy assignment of abstract types should not be possible.
|
2021-04-10 13:34:50 +02:00
|
|
|
|
|
|
|
// Move assignment
|
2021-04-11 11:01:37 +02:00
|
|
|
TestableContainer& operator=(TestableContainer&&) noexcept = delete; // Move assignment of abstract types should not be possible.
|
2021-04-10 13:34:50 +02:00
|
|
|
|
|
|
|
// Comparison operators
|
2021-04-11 11:01:37 +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-04-10 13:34:50 +02:00
|
|
|
|
|
|
|
/* ************************************************************************ */
|
|
|
|
|
|
|
|
// Specific member functions
|
2021-04-11 11:01:37 +02:00
|
|
|
virtual bool Exists(const Data&) const noexcept = 0; // (concrete function should not throw exceptions)
|
2021-04-10 13:34:50 +02:00
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
template <typename Data>
|
2021-04-11 11:01:37 +02:00
|
|
|
class MappableContainer : virtual public Container { // Must extend Container
|
2021-04-10 13:34:50 +02:00
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
// Destructor
|
2021-04-11 11:01:37 +02:00
|
|
|
virtual ~MappableContainer() = default;
|
2021-04-10 13:34:50 +02:00
|
|
|
|
|
|
|
// Copy assignment
|
2021-04-11 11:01:37 +02:00
|
|
|
MappableContainer& operator=(const MappableContainer&) = delete; // Copy assignment of abstract types should not be possible.
|
2021-04-10 13:34:50 +02:00
|
|
|
|
|
|
|
// Move assignment
|
2021-04-11 11:01:37 +02:00
|
|
|
MappableContainer& operator=(MappableContainer&&) noexcept = delete; // Move assignment of abstract types should not be possible.
|
2021-04-10 13:34:50 +02:00
|
|
|
|
|
|
|
// Comparison operators
|
2021-04-11 11:01:37 +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-04-10 13:34:50 +02:00
|
|
|
|
|
|
|
// Specific member functions
|
|
|
|
|
2021-04-11 11:01:37 +02:00
|
|
|
typedef std::function<void(Data&, void*)> MapFunctor;
|
2021-04-10 13:34:50 +02:00
|
|
|
|
2021-04-11 11:01:37 +02:00
|
|
|
virtual void MapPreOrder(const MapFunctor, void*) = 0;
|
|
|
|
virtual void MapPostOrder(const MapFunctor, void*) = 0;
|
2021-04-10 13:34:50 +02:00
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
template <typename Data>
|
2021-04-11 11:01:37 +02:00
|
|
|
class FoldableContainer : virtual public TestableContainer<Data>{ // Must extend TestableContainer
|
2021-04-10 13:34:50 +02:00
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
// Destructor
|
2021-04-11 11:01:37 +02:00
|
|
|
virtual ~FoldableContainer() = default;
|
2021-04-10 13:34:50 +02:00
|
|
|
|
|
|
|
// Copy assignment
|
2021-04-11 11:01:37 +02:00
|
|
|
FoldableContainer& operator=(const FoldableContainer&) = delete; // Copy assignment of abstract types should not be possible.
|
2021-04-10 13:34:50 +02:00
|
|
|
|
|
|
|
// Move assignment
|
2021-04-11 11:01:37 +02:00
|
|
|
FoldableContainer& operator=(FoldableContainer&&) noexcept = delete; // Move assignment of abstract types should not be possible.
|
2021-04-10 13:34:50 +02:00
|
|
|
|
|
|
|
// Comparison operators
|
2021-04-11 11:01:37 +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-04-10 13:34:50 +02:00
|
|
|
|
|
|
|
// Specific member functions
|
|
|
|
|
2021-04-11 11:01:37 +02:00
|
|
|
typedef std::function<void(const Data&, const void*, void*) noexcept> FoldFunctor;
|
2021-04-10 13:34:50 +02:00
|
|
|
|
2021-04-11 11:01:37 +02:00
|
|
|
virtual void FoldPreOrder(const FoldFunctor, const void*, void*) const = 0;
|
|
|
|
virtual void FoldPostOrder(const FoldFunctor, const void*, void*) const = 0;
|
2021-04-10 13:34:50 +02:00
|
|
|
|
2021-04-11 11:01:37 +02:00
|
|
|
virtual bool Exists(const Data&) const noexcept override; // Override TestableContainer member
|
2021-04-10 13:34:50 +02:00
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
/* ************************************************************************** */
|
|
|
|
|
|
|
|
template <typename Data>
|
|
|
|
class BreadthMappableContainer { // Must extend MappableContainer
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
// ...
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
|
|
|
// ...
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
// Destructor
|
|
|
|
// ~BreadthMappableContainer() specifiers
|
|
|
|
|
|
|
|
/* ************************************************************************ */
|
|
|
|
|
|
|
|
// Copy assignment
|
|
|
|
// type operator=(argument); // Copy assignment of abstract types should not be possible.
|
|
|
|
|
|
|
|
// Move assignment
|
|
|
|
// type operator=(argument); // Move assignment of abstract types should not be possible.
|
|
|
|
|
|
|
|
/* ************************************************************************ */
|
|
|
|
|
|
|
|
// Comparison operators
|
|
|
|
// type operator==(argument) specifiers; // Comparison of abstract types might not be possible.
|
|
|
|
// type operator!=(argument) specifiers; // Comparison of abstract types might not be possible.
|
|
|
|
|
|
|
|
/* ************************************************************************ */
|
|
|
|
|
|
|
|
// Specific member functions
|
|
|
|
|
|
|
|
// using typename MappableContainer<Data>::MapFunctor;
|
|
|
|
|
|
|
|
// type MapBreadth(arguments) specifiers;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
/* ************************************************************************** */
|
|
|
|
|
|
|
|
template <typename Data>
|
|
|
|
class BreadthFoldableContainer { // Must extend FoldableContainer
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
// ...
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
|
|
|
// ...
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
// Destructor
|
|
|
|
// ~BreadthFoldableContainer() specifiers
|
|
|
|
|
|
|
|
/* ************************************************************************ */
|
|
|
|
|
|
|
|
// Copy assignment
|
|
|
|
// type operator=(argument); // Copy assignment of abstract types should not be possible.
|
|
|
|
|
|
|
|
// Move assignment
|
|
|
|
// type operator=(argument); // Move assignment of abstract types should not be possible.
|
|
|
|
|
|
|
|
/* ************************************************************************ */
|
|
|
|
|
|
|
|
// Comparison operators
|
|
|
|
// type operator==(argument) specifiers; // Comparison of abstract types might not be possible.
|
|
|
|
// type operator!=(argument) specifiers; // Comparison of abstract types might not be possible.
|
|
|
|
|
|
|
|
/* ************************************************************************ */
|
|
|
|
|
|
|
|
// Specific member functions
|
|
|
|
|
|
|
|
// using typename FoldableContainer<Data>::FoldFunctor;
|
|
|
|
|
|
|
|
// type FoldBreadth(arguments) specifiers;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
/* ************************************************************************** */
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#include "container.cpp"
|
|
|
|
|
|
|
|
#endif
|