lasd/librerie/exercise1/vector/vector.hpp

80 lines
2.3 KiB
C++

#ifndef VECTOR_HPP
#define VECTOR_HPP
/* ************************************************************************** */
#include "../container/container.hpp"
/* ************************************************************************** */
namespace lasd {
/* ************************************************************************** */
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:
protected:
using LinearContainer<Data>::size;
Data* Elements = nullptr;
public:
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
Vector(const Vector&);
// Move constructor
Vector(Vector&&)noexcept;
// Destructor
virtual ~Vector();
// Copy assignment
Vector& operator=(const Vector&);
// Move assignment
Vector& operator=(Vector&&) noexcept;
// Comparison operators
bool operator==(const Vector&) const noexcept;
bool operator!=(const Vector&) const noexcept;
void Resize(const ulong); // Resize the vector to a given size
void Clear() override; // Override Container member
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)
using typename MappableContainer<Data>::MapFunctor;
void MapPreOrder(const MapFunctor, void*) override; // Override MappableContainer member
void MapPostOrder(const MapFunctor, void*) override; // Override MappableContainer member
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