2021-05-11 06:51:06 +02:00
|
|
|
|
|
|
|
#ifndef LIST_HPP
|
|
|
|
#define LIST_HPP
|
|
|
|
|
|
|
|
/* ************************************************************************** */
|
|
|
|
|
|
|
|
#include "../container/container.hpp"
|
|
|
|
|
|
|
|
/* ************************************************************************** */
|
|
|
|
|
|
|
|
namespace lasd {
|
|
|
|
|
|
|
|
/* ************************************************************************** */
|
|
|
|
|
|
|
|
template <typename Data>
|
2021-05-11 06:52:44 +02:00
|
|
|
class List : virtual public LinearContainer<Data>,
|
|
|
|
virtual public MappableContainer<Data>,
|
|
|
|
virtual public FoldableContainer<Data>{ // Must extend LinearContainer<Data>, MappableContainer<Data>, and FoldableContainer<Data>
|
2021-05-11 06:51:06 +02:00
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
2021-05-11 06:52:44 +02:00
|
|
|
using LinearContainer<Data>:: size;
|
2021-05-11 06:51:06 +02:00
|
|
|
|
|
|
|
struct Node
|
|
|
|
{
|
2021-05-11 06:52:44 +02:00
|
|
|
Data value;
|
|
|
|
Node* next = nullptr;
|
2021-05-11 06:51:06 +02:00
|
|
|
|
|
|
|
/* ********************************************************************** */
|
|
|
|
|
|
|
|
// Specific constructors
|
2021-05-11 06:52:44 +02:00
|
|
|
Node(const Data&);
|
2021-05-11 06:51:06 +02:00
|
|
|
|
|
|
|
/* ********************************************************************** */
|
|
|
|
|
|
|
|
// Copy constructor
|
2021-05-11 06:52:44 +02:00
|
|
|
Node(const Node&);
|
2021-05-11 06:51:06 +02:00
|
|
|
|
|
|
|
// Move constructor
|
2021-05-11 06:52:44 +02:00
|
|
|
Node(Node&&);
|
|
|
|
Node(Data&&);
|
2021-05-11 06:51:06 +02:00
|
|
|
|
|
|
|
/* ********************************************************************** */
|
|
|
|
|
|
|
|
// Destructor
|
2021-05-25 23:06:28 +02:00
|
|
|
virtual ~Node() = default;
|
2021-05-11 06:51:06 +02:00
|
|
|
|
|
|
|
/* ********************************************************************** */
|
|
|
|
|
|
|
|
// Comparison operators
|
2021-05-11 06:52:44 +02:00
|
|
|
bool operator==(const Node&) const noexcept;
|
|
|
|
bool operator!=(const Node&) const noexcept;
|
2021-05-11 06:51:06 +02:00
|
|
|
|
|
|
|
/* ********************************************************************** */
|
|
|
|
|
|
|
|
// Specific member functions
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2021-05-11 06:52:44 +02:00
|
|
|
struct Node* head = nullptr;
|
|
|
|
struct Node* tail = nullptr;
|
2021-05-11 06:51:06 +02:00
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
// Default constructor
|
2021-05-11 06:52:44 +02:00
|
|
|
List() = default;
|
2021-05-11 06:51:06 +02:00
|
|
|
|
|
|
|
/* ************************************************************************ */
|
|
|
|
|
|
|
|
// Specific constructor
|
2021-05-11 06:52:44 +02:00
|
|
|
List(const LinearContainer<Data>&); // A list obtained from a LinearContainer
|
2021-05-11 06:51:06 +02:00
|
|
|
|
|
|
|
/* ************************************************************************ */
|
|
|
|
|
|
|
|
// Copy constructor
|
2021-05-11 06:52:44 +02:00
|
|
|
List(const List&);
|
2021-05-11 06:51:06 +02:00
|
|
|
|
|
|
|
// Move constructor
|
2021-05-11 06:52:44 +02:00
|
|
|
List(List&&);
|
2021-05-11 06:51:06 +02:00
|
|
|
|
|
|
|
/* ************************************************************************ */
|
|
|
|
|
|
|
|
// Destructor
|
2021-05-25 23:06:28 +02:00
|
|
|
virtual ~List();
|
2021-05-11 06:51:06 +02:00
|
|
|
|
|
|
|
/* ************************************************************************ */
|
|
|
|
|
|
|
|
// Copy assignment
|
2021-05-11 06:52:44 +02:00
|
|
|
List& operator=(const List&);
|
2021-05-11 06:51:06 +02:00
|
|
|
|
|
|
|
// Move assignment
|
2021-05-11 06:52:44 +02:00
|
|
|
List& operator=(List&&) noexcept;
|
2021-05-11 06:51:06 +02:00
|
|
|
|
|
|
|
/* ************************************************************************ */
|
|
|
|
|
|
|
|
// Comparison operators
|
2021-05-11 06:52:44 +02:00
|
|
|
bool operator==(const List&) const noexcept;
|
|
|
|
bool operator!=(const List&) const noexcept;
|
2021-05-11 06:51:06 +02:00
|
|
|
|
|
|
|
/* ************************************************************************ */
|
|
|
|
|
|
|
|
// Specific member functions
|
|
|
|
|
2021-05-11 06:52:44 +02:00
|
|
|
void InsertAtFront(const Data&); // Copy of the value
|
|
|
|
void InsertAtFront(Data&&); // Move of the value
|
|
|
|
void RemoveFromFront(); // (must throw std::length_error when empty)
|
|
|
|
Data FrontNRemove(); // (must throw std::length_error when empty)
|
2021-05-11 06:51:06 +02:00
|
|
|
|
2021-05-11 06:52:44 +02:00
|
|
|
void InsertAtBack(const Data&); // Copy of the value
|
|
|
|
void InsertAtBack(Data&&); // Move of the value
|
2021-05-11 06:51:06 +02:00
|
|
|
|
|
|
|
/* ************************************************************************ */
|
|
|
|
|
|
|
|
// Specific member functions (inherited from Container)
|
|
|
|
|
2021-05-11 06:52:44 +02:00
|
|
|
void Clear() override; // Override Container member
|
2021-05-11 06:51:06 +02:00
|
|
|
|
|
|
|
/* ************************************************************************ */
|
|
|
|
|
|
|
|
// Specific member functions (inherited from LinearContainer)
|
|
|
|
|
2021-05-11 06:52:44 +02:00
|
|
|
Data& Front() const override; // Override LinearContainer member (must throw std::length_error when empty)
|
|
|
|
Data& Back() const override; // Override LinearContainer member (must throw std::length_error when empty)
|
2021-05-11 06:51:06 +02:00
|
|
|
|
2021-05-11 06:52:44 +02:00
|
|
|
Data& operator[](const ulong) const override; // Override LinearContainer member (must throw std::out_of_range when out of range)
|
2021-05-11 06:51:06 +02:00
|
|
|
|
|
|
|
/* ************************************************************************ */
|
|
|
|
|
|
|
|
// Specific member functions (inherited from MappableContainer)
|
|
|
|
|
2021-05-11 06:52:44 +02:00
|
|
|
using typename MappableContainer<Data>::MapFunctor;
|
2021-05-11 06:51:06 +02:00
|
|
|
|
2021-05-11 06:52:44 +02:00
|
|
|
void MapPreOrder(const MapFunctor, void*) override; // Override MappableContainer member
|
|
|
|
void MapPostOrder(const MapFunctor, void*) override; // Override MappableContainer member
|
2021-05-11 06:51:06 +02:00
|
|
|
|
|
|
|
/* ************************************************************************ */
|
|
|
|
|
|
|
|
// Specific member functions (inherited from FoldableContainer)
|
|
|
|
|
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
|
|
|
void FoldPreOrder(const FoldFunctor, const void*, void*) const override; // Override FoldableContainer member
|
|
|
|
void FoldPostOrder(const FoldFunctor, const void*, void*) const override; // Override FoldableContainer member
|
2021-05-11 06:51:06 +02:00
|
|
|
|
|
|
|
protected:
|
|
|
|
|
|
|
|
// Auxiliary member functions (for MappableContainer)
|
|
|
|
|
2021-05-11 06:52:44 +02:00
|
|
|
void MapPreOrder(const MapFunctor, void* , struct Node*); // Accessory function executing from one point of the list onwards
|
|
|
|
void MapPostOrder(const MapFunctor, void* , struct Node*); // Accessory function executing from one point of the list onwards
|
2021-05-11 06:51:06 +02:00
|
|
|
|
|
|
|
/* ************************************************************************ */
|
|
|
|
|
|
|
|
// Auxiliary member functions (for FoldableContainer)
|
|
|
|
|
2021-05-11 06:52:44 +02:00
|
|
|
void FoldPreOrder(const FoldFunctor, const void*, void*, struct Node*) const; // Accessory function executing from one point of the list onwards
|
|
|
|
void FoldPostOrder(const FoldFunctor, const void*, void*, struct Node*) const;; // Accessory function executing from one point of the list onwards
|
2021-05-11 06:51:06 +02:00
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
/* ************************************************************************** */
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#include "list.cpp"
|
|
|
|
|
|
|
|
#endif
|