//! \addtogroup Containers //! \{ //! \file piqueue.h //! \brief //! \~english Declares \a PIQueue //! \~russian Объявление \a PIQueue //! \~\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 Queue 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 . */ #ifndef PIQUEUE_H #define PIQUEUE_H #include "pideque.h" #include "pivector.h" //! \addtogroup Containers //! \{ //! \class PIQueue //! \brief //! \~english A container class inherited from the \a PIDeque with queue functionality. //! \~russian Класс контейнера наследованый от \a PIDeque с функциональностью очереди. //! \~\} //! \details //! \~english The container is a array of elements organized according to the FIFO principle (first in, first out). //! Adds \a enqueue() and \dequeue() functions to \a PIDeque. //! \~russian Контейнер представляющий массив элементов, организованных по принципу FIFO (первым пришёл — первым вышел). //! Добавляет к \a PIDeque функции \a enqueue() и \a dequeue(). //! \~\sa \a PIDeque template class PIQueue: public PIDeque { public: //! \~english Constructs an empty array. //! \~russian Создает пустой массив. PIQueue() {} //! \~english Puts an element on the queue. //! \~russian Кладёт элемент в очередь. PIDeque & enqueue(const T & v) { PIDeque::push_front(v); return *this; } //! \~english Move an element on the queue. //! \~russian Перемещает элемент в очередь. PIDeque & enqueue(T && v) { PIDeque::push_front(std::move(v)); return *this; } //! \~english Retrieves and returns an element from the queue. //! \~russian Забирает и возвращает элемент из очереди. //! \~\details //! \note //! \~english This function assumes that the array isn't empty. //! Otherwise will be undefined behavior. //! \~russian Эта функция предполагает, что массив не пустой. //! Иначе это приведёт к неопределённому поведению программы и ошибкам памяти. T dequeue() { return PIDeque::take_back(); } //! \~english Head element of the queue. //! \~russian Головной (верхний) элемент очереди. //! \~\details //! \note //! \~english Returns a reference to the head element of the queue. //! This function assumes that the array isn't empty. //! Otherwise will be undefined behavior. //! \~russian Возвращает ссылку на головной (верхний) элемент очереди. //! Эта функция предполагает, что массив не пустой. //! Иначе это приведёт к неопределённому поведению программы и ошибкам памяти. T & head() { return PIDeque::back(); } const T & head() const { return PIDeque::back(); } //! \~english Tail element of the queue. //! \~russian Хвостовой (нижний) элемент очереди. //! \~\details //! \~english Returns a reference to the tail element of the queue. //! This function assumes that the array isn't empty. //! Otherwise will be undefined behavior. //! \~russian Возвращает ссылку на хвостовой (нижний) элемент очереди. //! Эта функция предполагает, что массив не пустой. //! Иначе это приведёт к неопределённому поведению программы и ошибкам памяти. T & tail() { return PIDeque::front(); } const T & tail() const { return PIDeque::front(); } //! \~english Converts \a PIQueue to \a PIVector. //! \~russian Преобразует \a PIQueue в \a PIVector. PIVector toVector() const { return PIVector(PIDeque::data(), PIDeque::size()); } //! \~english Converts \a PIQueue to \a PIDeque. //! \~russian Преобразует \a PIQueue в \a PIDeque. PIDeque toDeque() const { return PIDeque(*this); } }; #endif // PIQUEUE_H