lasd/librerie/exercise2/vector/vector.hpp

80 lines
2.3 KiB
C++
Raw Normal View History

2021-04-10 13:34:50 +02:00
#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>
2021-04-10 13:34:50 +02:00
private:
protected:
using LinearContainer<Data>::size;
Data* Elements = nullptr;
2021-04-10 13:34:50 +02:00
public:
2021-04-23 21:56:01 +02:00
Vector() = default;
2021-04-10 13:34:50 +02:00
// Specific constructors
Vector(const ulong); // A vector with a given initial dimension
Vector(const LinearContainer<Data>&); // A vector obtained from a LinearContainer
2021-04-10 13:34:50 +02:00
// Copy constructor
2021-04-23 21:56:01 +02:00
Vector(const Vector&);
2021-04-10 13:34:50 +02:00
// Move constructor
2021-04-23 21:56:01 +02:00
Vector(Vector&&)noexcept;
2021-04-10 13:34:50 +02:00
// Destructor
2021-04-23 21:56:01 +02:00
~Vector();
2021-04-10 13:34:50 +02:00
// Copy assignment
2021-04-23 21:56:01 +02:00
Vector& operator=(const Vector&);
2021-04-10 13:34:50 +02:00
// Move assignment
Vector& operator=(Vector&&) noexcept;
2021-04-10 13:34:50 +02:00
// Comparison operators
bool operator==(const Vector&) const noexcept;
bool operator!=(const Vector&) const noexcept;
2021-04-10 13:34:50 +02:00
void Resize(const ulong); // Resize the vector to a given size
2021-04-10 13:34:50 +02:00
void Clear() override; // Override Container member
2021-04-10 13:34:50 +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-10 13:34:50 +02:00
Data& operator[](const ulong) const override; // Override LinearContainer member (must throw std::out_of_range when out of range)
2021-04-10 13:34:50 +02:00
2021-04-23 21:56:01 +02:00
using typename MappableContainer<Data>::MapFunctor;
2021-04-10 13:34:50 +02:00
2021-04-23 21:56:01 +02:00
void MapPreOrder(const MapFunctor, void*) override; // Override MappableContainer member
void MapPostOrder(const MapFunctor, void*) override; // Override MappableContainer member
2021-04-10 13:34:50 +02:00
2021-04-23 21:56:01 +02:00
using typename FoldableContainer<Data>::FoldFunctor;
2021-04-10 13:34:50 +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-10 13:34:50 +02:00
};
}
#include "vector.cpp"
#endif