107 lines
4.2 KiB
C++
107 lines
4.2 KiB
C++
//! \addtogroup Containers
|
||
//! \{
|
||
//! \file pistack.h
|
||
//! \brief
|
||
//! \~english Declares \a PIStack
|
||
//! \~russian Объявление \a PIStack
|
||
//! \~\authors
|
||
//! \~english
|
||
//! Ivan Pelipenko peri4ko@yandex.ru;
|
||
//! Andrey Bychkov work.a.b@yandex.ru;
|
||
//! \~russian
|
||
//! Иван Пелипенко peri4ko@yandex.ru;
|
||
//! Андрей Бычков work.a.b@yandex.ru;
|
||
//! \~\}
|
||
/*
|
||
PIP - Platform Independent Primitives
|
||
Stack container
|
||
Ivan Pelipenko peri4ko@yandex.ru
|
||
|
||
This program is free software: you can redistribute it and/or modify
|
||
it under the terms of the GNU Lesser General Public License as published by
|
||
the Free Software Foundation, either version 3 of the License, or
|
||
(at your option) any later version.
|
||
|
||
This program is distributed in the hope that it will be useful,
|
||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
GNU Lesser General Public License for more details.
|
||
|
||
You should have received a copy of the GNU Lesser General Public License
|
||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||
*/
|
||
|
||
#ifndef PISTACK_H
|
||
#define PISTACK_H
|
||
|
||
#include "pideque.h"
|
||
#include "pivector.h"
|
||
|
||
//! \addtogroup Containers
|
||
//! \{
|
||
//! \class PIStack
|
||
//! \brief
|
||
//! \~english A container class inherited from the \a PIVector with stack functionality.
|
||
//! \~russian Класс контейнера наследованый от \a PIVector с функциональностью стека.
|
||
//! \~\}
|
||
//! \details
|
||
//! \~english The container is a array of elements organized according to the LIFO principle (last in, first out).
|
||
//! Adds \a push() and \pop() functions to \a PIVector.
|
||
//! \~russian Контейнер представляющий массив элементов, организованных по принципу LIFO (последним пришёл — первым вышел).
|
||
//! Добавляет к \a PIVector функции \a push() и \a pop().
|
||
//! \~\sa \a PIVector
|
||
template<typename T>
|
||
class PIStack: public PIVector<T> {
|
||
public:
|
||
//! \~english Constructs an empty array.
|
||
//! \~russian Создает пустой массив.
|
||
PIStack() {}
|
||
|
||
//! \~english Puts an element on the stack.
|
||
//! \~russian Кладёт элемент в стек.
|
||
PIVector<T> & push(const T & v) {
|
||
PIVector<T>::push_back(v);
|
||
return *this;
|
||
}
|
||
|
||
//! \~english Move an element on the stack.
|
||
//! \~russian Перемещает элемент в стек.
|
||
PIVector<T> & push(T && v) {
|
||
PIVector<T>::push_back(std::move(v));
|
||
return *this;
|
||
}
|
||
|
||
//! \~english Retrieves and returns an element from the stack.
|
||
//! \~russian Забирает и возвращает элемент из стека.
|
||
//! \~\details
|
||
//! \note
|
||
//! \~english This function assumes that the array isn't empty.
|
||
//! Otherwise will be undefined behavior.
|
||
//! \~russian Эта функция предполагает, что массив не пустой.
|
||
//! Иначе это приведёт к неопределённому поведению программы и ошибкам памяти.
|
||
T pop() { return PIVector<T>::take_back(); }
|
||
|
||
//! \~english Top element of the stack
|
||
//! \~russian Верхний элемент стека.
|
||
//! \~\details
|
||
//! \note
|
||
//! \~english Returns a reference to the top element of the stack.
|
||
//! This function assumes that the array isn't empty.
|
||
//! Otherwise will be undefined behavior.
|
||
//! \~russian Возвращает ссылку на верхний элемент стека.
|
||
//! Эта функция предполагает, что массив не пустой.
|
||
//! Иначе это приведёт к неопределённому поведению программы и ошибкам памяти.
|
||
T & top() { return PIVector<T>::back(); }
|
||
const T & top() const { return PIVector<T>::back(); }
|
||
|
||
//! \~english Converts \a PIStack to \a PIVector.
|
||
//! \~russian Преобразует \a PIStack в \a PIVector.
|
||
PIVector<T> toVector() const { return PIVector<T>(*this); }
|
||
|
||
//! \~english Converts \a PIStack to \a PIDeque.
|
||
//! \~russian Преобразует \a PIStack в \a PIDeque.
|
||
PIDeque<T> toDeque() const { return PIDeque<T>(PIVector<T>::data(), PIVector<T>::size()); }
|
||
};
|
||
|
||
#endif // PISTACK_H
|