lasd/librerie/exercise2/stack/vec/stackvec.hpp

102 lines
2.7 KiB
C++
Raw Normal View History

2021-04-10 13:34:50 +02:00
#ifndef STACKVEC_HPP
#define STACKVEC_HPP
/* ************************************************************************** */
#include "../stack.hpp"
#include "../../vector/vector.hpp"
/* ************************************************************************** */
namespace lasd {
/* ************************************************************************** */
template <typename Data>
2021-04-12 22:04:22 +02:00
class StackVec : virtual public Stack<Data>,
virtual protected Vector<Data>{ // Must extend Stack<Data> and Vector<Data>
2021-04-10 13:34:50 +02:00
private:
protected:
2021-04-21 00:14:10 +02:00
ulong stackSize = 0; // first empty cell and # of elements in the vector
2021-04-12 22:04:22 +02:00
using Vector<Data>::Elements;
2021-04-19 12:32:33 +02:00
using Vector<Data>::size; // dimension of the vector
2021-04-10 13:34:50 +02:00
public:
// Default constructor
2021-04-12 22:04:22 +02:00
StackVec();
2021-04-10 13:34:50 +02:00
/* ************************************************************************ */
// Specific constructor
2021-04-12 22:04:22 +02:00
StackVec(const LinearContainer<Data>&); // A stack obtained from a LinearContainer
2021-04-10 13:34:50 +02:00
/* ************************************************************************ */
// Copy constructor
2021-04-12 22:04:22 +02:00
StackVec(const StackVec&);
2021-04-10 13:34:50 +02:00
// Move constructor
2021-04-12 22:04:22 +02:00
StackVec(StackVec&&) noexcept;
2021-04-10 13:34:50 +02:00
/* ************************************************************************ */
// Destructor
2021-04-12 22:04:22 +02:00
virtual ~StackVec();
2021-04-10 13:34:50 +02:00
/* ************************************************************************ */
// Copy assignment
2021-04-14 08:42:18 +02:00
StackVec& operator=(const StackVec&);
2021-04-10 13:34:50 +02:00
// Move assignment
2021-04-12 22:04:22 +02:00
StackVec& operator=(StackVec&&) noexcept;
2021-04-10 13:34:50 +02:00
/* ************************************************************************ */
// Comparison operators
2021-04-12 22:04:22 +02:00
bool operator==(const StackVec&) const noexcept;
bool operator!=(const StackVec&) const noexcept;
2021-04-10 13:34:50 +02:00
/* ************************************************************************ */
// Specific member functions (inherited from Stack)
2021-04-12 22:04:22 +02:00
void Push(const Data&) override; // Override Stack member (copy of the value)
void Push(Data&&) override; // Override Stack member (move of the value)
Data& Top() const override; // Override Stack member (must throw std::length_error when empty)
void Pop() override; // Override Stack member (must throw std::length_error when empty)
Data TopNPop() override; // Override Stack member (must throw std::length_error when empty)
2021-04-10 13:34:50 +02:00
/* ************************************************************************ */
// Specific member functions (inherited from Container)
2021-04-12 22:04:22 +02:00
bool Empty() const noexcept override; // Override Container member
2021-04-10 13:34:50 +02:00
2021-04-14 08:42:18 +02:00
ulong Size() const noexcept override; // Override Container member
2021-04-10 13:34:50 +02:00
2021-04-12 22:04:22 +02:00
void Clear() override;// Override Container member
2021-04-10 13:34:50 +02:00
protected:
// Auxiliary member functions
2021-04-12 22:04:22 +02:00
void Expand();
void Reduce();
2021-04-10 13:34:50 +02:00
};
/* ************************************************************************** */
}
#include "stackvec.cpp"
#endif