Files
pip/libs/main/containers/pistack.h
Бычков Андрей eddef26b5e doc PIMap PIStack PIQueue done
2022-09-02 09:44:47 +03:00

102 lines
4.1 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
//! \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 "pivector.h"
#include "pideque.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