Program Listing for File LinkedQueue.h
↰ Return to documentation for file (ADS/queue/LinkedQueue.h)
/*--------------------------------------------------------------------------*/
/*--------------------------- File LinkedQueue.h ---------------------------*/
/*--------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------*/
/*----------------------------- DEFINITIONS --------------------------------*/
/*--------------------------------------------------------------------------*/
#ifndef __ADS_LinkedQueue
#define __ADS_LinkedQueue
/* self-identification: #endif constant */
/*--------------------------------------------------------------------------*/
/*------------------------------ INCLUDES ----------------------------------*/
/*--------------------------------------------------------------------------*/
#include "ADS/Contract.h"
#include "ADS/Iterators.h"
#include "ADS/memory/ObjectPool.h"
#include <cstddef>
#include <utility>
/*--------------------------------------------------------------------------*/
/*--------------------------- NAMESPACE ------------------------------------*/
/*--------------------------------------------------------------------------*/
namespace ADS {
/*--------------------------------------------------------------------------*/
/*-------------------------- CLASS LinkedQueue -----------------------------*/
/*--------------------------------------------------------------------------*/
template< class T >
class LinkedQueue {
/*--------------------------------------------------------------------------*/
public:
using Item = T;
LinkedQueue( void ) = default;
LinkedQueue( const LinkedQueue & other );
LinkedQueue( LinkedQueue && other ) noexcept;
LinkedQueue & operator=( LinkedQueue other ) noexcept;
~LinkedQueue();
void swap( LinkedQueue & other ) noexcept;
[[nodiscard]] bool empty( void ) const;
void enqueue( const T & v );
T dequeue( void );
[[nodiscard]] const T & top( void ) const;
[[nodiscard]] std::size_t size( void ) const;
[[nodiscard]] bool operator==( const LinkedQueue & o ) const;
/*--------------------------------------------------------------------------*/
private:
struct Cell {
T value;
Cell * next;
};
public:
/*------------------------- THE STANDARD INTERFACE -------------------------*/
// a constant view of the items from the front to the back, forward
using value_type = T;
using size_type = std::size_t;
using difference_type = std::ptrdiff_t;
using reference = const T &;
using const_reference = const T &;
using iterator = LinkedIterator< Cell , T , &Cell::next , &Cell::value >;
using const_iterator =
LinkedIterator< Cell , T , &Cell::next , &Cell::value >;
[[nodiscard]] const_iterator begin( void ) const {
return( const_iterator( f_front ) );
}
[[nodiscard]] const_iterator end( void ) const { return( const_iterator() ); }
[[nodiscard]] const_iterator cbegin( void ) const { return( begin() ); }
[[nodiscard]] const_iterator cend( void ) const { return( end() ); }
private:
Cell * f_front = nullptr;
Cell * f_back = nullptr;
std::size_t f_size = 0;
ObjectPool< Cell > f_pool;
}; // end( class LinkedQueue )
/*--------------------------------------------------------------------------*/
} // end( namespace ADS )
/*--------------------------------------------------------------------------*/
/*-------------------------- IMPLEMENTATION --------------------------------*/
/*--------------------------------------------------------------------------*/
#include "ADS/queue/impl/LinkedQueue.tpp"
/*--------------------------------------------------------------------------*/
#endif /* LinkedQueue.h included */
/*--------------------------------------------------------------------------*/
/*------------------------- End File LinkedQueue.h -------------------------*/
/*--------------------------------------------------------------------------*/