lasd/librerie/exercise1/vector/vector.hpp

117 lines
3.5 KiB
C++
Raw Normal View History

#ifndef VECTOR_HPP
#define VECTOR_HPP
2021-04-09 10:31:22 +02:00
/* ************************************************************************** */
#include "../container/container.hpp"
2021-04-09 10:31:22 +02:00
/* ************************************************************************** */
namespace lasd {
2021-04-09 10:31:22 +02:00
/* ************************************************************************** */
template <typename Data>
class Vector : virtual public LinearContainer<Data>,
virtual public MappableContainer<Data>,
virtual public FoldableContainer<Data>{ // Must extend LinearContainer<Data>, MappableContainer<Data>, and FoldableContainer<Data>
private:
2021-04-09 10:31:22 +02:00
protected:
using LinearContainer<Data>::size;
Data* Elements = nullptr;
2021-04-09 10:31:22 +02:00
// ...
public:
// Default constructor
2021-04-09 10:31:22 +02:00
// Vector() specifiers;
Vector() = default;
/* ************************************************************************ */
// Specific constructors
Vector(const ulong); // A vector with a given initial dimension
Vector(const LinearContainer<Data>&); // A vector obtained from a LinearContainer
/* ************************************************************************ */
// Copy constructor
2021-04-09 10:31:22 +02:00
Vector(const Vector&);
// Move constructor
2021-04-09 10:31:22 +02:00
Vector(Vector&&)noexcept;
/* ************************************************************************ */
// Destructor
2021-04-09 10:31:22 +02:00
~Vector();
/* ************************************************************************ */
// Copy assignment
2021-04-09 10:31:22 +02:00
Vector& operator=(const Vector&);
// Move assignment
Vector& operator=(Vector&&) noexcept;
/* ************************************************************************ */
// Comparison operators
2021-04-09 10:31:22 +02:00
bool operator==(const Vector&) const noexcept;
bool operator!=(const Vector&) const noexcept;
/* ************************************************************************ */
// Specific member functions
void Resize(const ulong); // Resize the vector to a given size
/* ************************************************************************ */
// Specific member functions (inherited from Container)
void Clear() override; // Override Container member
/* ************************************************************************ */
// Specific member functions (inherited from LinearContainer)
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)
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)
2021-04-09 10:31:22 +02:00
using typename MappableContainer<Data>::MapFunctor;
2021-04-09 10:31:22 +02:00
void MapPreOrder(const MapFunctor, void*) override; // Override MappableContainer member
void MapPostOrder(const MapFunctor, void*) override; // Override MappableContainer member
/* ************************************************************************ */
// Specific member functions (inherited from FoldableContainer)
2021-04-09 10:31:22 +02:00
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
};
/* ************************************************************************** */
}
#include "vector.cpp"
#endif