lasd/librerie/exercise1/list/list.hpp

170 lines
5.3 KiB
C++
Raw Normal View History

#ifndef LIST_HPP
#define LIST_HPP
/* ************************************************************************** */
#include "../container/container.hpp"
/* ************************************************************************** */
namespace lasd {
/* ************************************************************************** */
template <typename Data>
2021-04-09 10:31:22 +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>
private:
protected:
2021-04-09 10:31:22 +02:00
using LinearContainer<Data>:: size;
struct Node
{
Data value;
2021-04-09 10:31:22 +02:00
Node* next = nullptr;
/* ********************************************************************** */
// Specific constructors
2021-04-09 19:08:43 +02:00
Node(const Data&);
/* ********************************************************************** */
// Copy constructor
Node(const Node&);
// Move constructor
Node(Node&&);
2021-04-02 20:32:13 +02:00
Node(Data&&);
/* ********************************************************************** */
// Destructor
virtual ~Node() = default;
/* ********************************************************************** */
// Comparison operators
bool operator==(const Node&) const noexcept;
bool operator!=(const Node&) const noexcept;
2021-04-09 10:31:22 +02:00
/* ********************************************************************** */
// Specific member functions
};
struct Node* head = nullptr;
struct Node* tail = nullptr;
public:
// Default constructor
List() = default;
/* ************************************************************************ */
// Specific constructor
2021-04-09 10:31:22 +02:00
List(const LinearContainer<Data>&); // A list obtained from a LinearContainer
/* ************************************************************************ */
// Copy constructor
List(const List&);
2021-04-09 10:31:22 +02:00
// Move constructor
List(List&&);
/* ************************************************************************ */
// Destructor
virtual ~List();
/* ************************************************************************ */
// Copy assignment
2021-04-09 10:31:22 +02:00
List& operator=(const List&);
// Move assignment
2021-04-09 10:31:22 +02:00
List& operator=(List&&) noexcept;
/* ************************************************************************ */
// Comparison operators
2021-04-09 10:31:22 +02:00
bool operator==(const List&) const noexcept;
bool operator!=(const List&) const noexcept;
/* ************************************************************************ */
// Specific member functions
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)
void InsertAtBack(const Data&); // Copy of the value
void InsertAtBack(Data&&); // Move of the value
/* ************************************************************************ */
// Specific member functions (inherited from Container)
2021-04-09 10:31:22 +02:00
void Clear() override; // Override Container member
/* ************************************************************************ */
// Specific member functions (inherited from LinearContainer)
2021-04-09 10:31:22 +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-04-02 20:32:13 +02:00
Data& operator[](const ulong) const override; // Override LinearContainer member (must throw std::out_of_range when out of range)
/* ************************************************************************ */
// Specific member functions (inherited from MappableContainer)
using typename MappableContainer<Data>::MapFunctor;
void MapPreOrder(const MapFunctor, void*) override; // Override MappableContainer member
void MapPostOrder(const MapFunctor, void*) override; // Override MappableContainer member
/* ************************************************************************ */
// Specific member functions (inherited from FoldableContainer)
using typename FoldableContainer<Data>::FoldFunctor;
void FoldPreOrder(const FoldFunctor, const void*, void*) const override; // Override FoldableContainer member
void FoldPostOrder(const FoldFunctor, const void*, void*) const override; // Override FoldableContainer member
protected:
// Auxiliary member functions (for MappableContainer)
2021-04-09 10:31:22 +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
/* ************************************************************************ */
// Auxiliary member functions (for FoldableContainer)
void FoldPreOrder(const FoldFunctor, const void*, void*, struct Node*) const; // Accessory function executing from one point of the list onwards
2021-04-09 10:31:22 +02:00
void FoldPostOrder(const FoldFunctor, const void*, void*, struct Node*) const;; // Accessory function executing from one point of the list onwards
};
/* ************************************************************************** */
}
#include "list.cpp"
#endif