lasd/librerie/exercise2/container/container.hpp

261 lines
7.6 KiB
C++
Raw Normal View History

2021-04-10 13:34:50 +02:00
#ifndef CONTAINER_HPP
#define CONTAINER_HPP
#include <stdexcept>
#include <functional>
namespace lasd {
class Container {
private:
protected:
ulong size = 0;
2021-04-10 13:34:50 +02:00
public:
// Destructor
virtual ~Container() = default;
2021-04-10 13:34:50 +02:00
// Copy assignment
Container& operator=(const Container&) = delete; // Copy assignment of abstract types should not be possible.
2021-04-10 13:34:50 +02:00
// Move assignment
Container& operator=(Container&&) noexcept = delete;; // Move assignment of abstract types should not be possible.
2021-04-10 13:34:50 +02:00
// Comparison operators
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
virtual bool Empty() const noexcept {
return (size == 0);
} // (concrete function should not throw exceptions)
2021-04-10 13:34:50 +02:00
virtual ulong Size() const noexcept {
return size;
} // (concrete function should not throw exceptions)
2021-04-10 13:34:50 +02:00
virtual void Clear() = 0;
2021-04-10 13:34:50 +02:00
};
template <typename Data>
class LinearContainer : virtual public Container{ // Must extend Container
2021-04-10 13:34:50 +02:00
private:
protected:
public:
// Destructor
virtual ~LinearContainer() = default;
2021-04-10 13:34:50 +02:00
// Copy assignment
LinearContainer& operator=(const LinearContainer&) = delete; // Copy assignment of abstract types should not be possible.
2021-04-10 13:34:50 +02:00
// Move assignment
LinearContainer& operator=(LinearContainer&&) noexcept = delete; // Move assignment of abstract types should not be possible.
2021-04-10 13:34:50 +02:00
// Comparison operators
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
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
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>
class TestableContainer : virtual public Container{ // Must extend Container
2021-04-10 13:34:50 +02:00
private:
protected:
public:
// Destructor
virtual ~TestableContainer() = default;
2021-04-10 13:34:50 +02:00
// Copy assignment
TestableContainer& operator=(const TestableContainer&) = delete; // Copy assignment of abstract types should not be possible.
2021-04-10 13:34:50 +02:00
// Move assignment
TestableContainer& operator=(TestableContainer&&) noexcept = delete; // Move assignment of abstract types should not be possible.
2021-04-10 13:34:50 +02:00
// Comparison operators
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
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>
class MappableContainer : virtual public Container { // Must extend Container
2021-04-10 13:34:50 +02:00
private:
protected:
public:
// Destructor
virtual ~MappableContainer() = default;
2021-04-10 13:34:50 +02:00
// Copy assignment
MappableContainer& operator=(const MappableContainer&) = delete; // Copy assignment of abstract types should not be possible.
2021-04-10 13:34:50 +02:00
// Move assignment
MappableContainer& operator=(MappableContainer&&) noexcept = delete; // Move assignment of abstract types should not be possible.
2021-04-10 13:34:50 +02:00
// Comparison operators
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
typedef std::function<void(Data&, void*)> MapFunctor;
2021-04-10 13:34:50 +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>
class FoldableContainer : virtual public TestableContainer<Data>{ // Must extend TestableContainer
2021-04-10 13:34:50 +02:00
private:
protected:
public:
// Destructor
virtual ~FoldableContainer() = default;
2021-04-10 13:34:50 +02:00
// Copy assignment
FoldableContainer& operator=(const FoldableContainer&) = delete; // Copy assignment of abstract types should not be possible.
2021-04-10 13:34:50 +02:00
// Move assignment
FoldableContainer& operator=(FoldableContainer&&) noexcept = delete; // Move assignment of abstract types should not be possible.
2021-04-10 13:34:50 +02:00
// Comparison operators
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
typedef std::function<void(const Data&, const void*, void*) noexcept> FoldFunctor;
2021-04-10 13:34:50 +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
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