lasd/librerie/exercise3/vector/vector.hpp

80 lines
2.3 KiB
C++
Raw Normal View History

2021-04-24 16:58:05 +02:00
#ifndef VECTOR_HPP
#define VECTOR_HPP
/* ************************************************************************** */
#include "../container/container.hpp"
/* ************************************************************************** */
namespace lasd {
/* ************************************************************************** */
template <typename Data>
2021-04-24 18:39:57 +02:00
class Vector : virtual public LinearContainer<Data>,
virtual public MappableContainer<Data>,
virtual public FoldableContainer<Data>{ // Must extend LinearContainer<Data>, MappableContainer<Data>, and FoldableContainer<Data>
2021-04-24 16:58:05 +02:00
private:
protected:
2021-04-24 18:39:57 +02:00
using LinearContainer<Data>::size;
Data* Elements = nullptr;
2021-04-24 16:58:05 +02:00
public:
2021-04-24 18:39:57 +02:00
Vector() = default;
2021-04-24 16:58:05 +02:00
// Specific constructors
2021-04-24 18:39:57 +02:00
Vector(const ulong); // A vector with a given initial dimension
Vector(const LinearContainer<Data>&); // A vector obtained from a LinearContainer
2021-04-24 16:58:05 +02:00
// Copy constructor
2021-04-24 18:39:57 +02:00
Vector(const Vector&);
2021-04-24 16:58:05 +02:00
// Move constructor
2021-04-24 18:39:57 +02:00
Vector(Vector&&)noexcept;
2021-04-24 16:58:05 +02:00
// Destructor
2021-04-24 18:39:57 +02:00
~Vector();
2021-04-24 16:58:05 +02:00
// Copy assignment
2021-04-24 18:39:57 +02:00
Vector& operator=(const Vector&);
2021-04-24 16:58:05 +02:00
// Move assignment
2021-04-24 18:39:57 +02:00
Vector& operator=(Vector&&) noexcept;
2021-04-24 16:58:05 +02:00
// Comparison operators
2021-04-24 18:39:57 +02:00
bool operator==(const Vector&) const noexcept;
bool operator!=(const Vector&) const noexcept;
2021-04-24 16:58:05 +02:00
2021-04-24 18:39:57 +02:00
void Resize(const ulong); // Resize the vector to a given size
2021-04-24 16:58:05 +02:00
2021-04-24 18:39:57 +02:00
void Clear() override; // Override Container member
2021-04-24 16:58:05 +02:00
2021-04-24 18:39:57 +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-24 16:58:05 +02:00
2021-04-24 18:39:57 +02:00
Data& operator[](const ulong) const override; // Override LinearContainer member (must throw std::out_of_range when out of range)
2021-04-24 16:58:05 +02:00
2021-04-24 18:39:57 +02:00
using typename MappableContainer<Data>::MapFunctor;
2021-04-24 16:58:05 +02:00
2021-04-24 18:39:57 +02:00
void MapPreOrder(const MapFunctor, void*) override; // Override MappableContainer member
void MapPostOrder(const MapFunctor, void*) override; // Override MappableContainer member
2021-04-24 16:58:05 +02:00
2021-04-24 18:39:57 +02:00
using typename FoldableContainer<Data>::FoldFunctor;
2021-04-24 16:58:05 +02:00
2021-04-24 18:39:57 +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-04-24 16:58:05 +02:00
};
}
#include "vector.cpp"
#endif