Roc Toolkit internal modules
Roc Toolkit: real-time audio streaming
roc::core::RingQueue< T, EmbeddedCapacity > Class Template Reference

Queue on continuous memory buffer. More...

#include <ring_queue.h>

Inheritance diagram for roc::core::RingQueue< T, EmbeddedCapacity >:
Collaboration diagram for roc::core::RingQueue< T, EmbeddedCapacity >:

Public Member Functions

 RingQueue (core::IArena &arena, size_t max_len)
 Initialize. More...
 
bool is_valid () const
 Check that initial allocation succeeded. More...
 
size_t capacity () const
 Get maximum number of elements in queue/. More...
 
size_t size () const
 Get current number of elements in the queue. More...
 
bool is_empty ()
 Is the queue empty. More...
 
bool is_full ()
 Is the queue full. More...
 
T & front ()
 Get reference of the front element. More...
 
const T & front () const
 Get reference of the front element. More...
 
T & back ()
 Get reference of the back element. More...
 
const T & back () const
 Get reference of the back element. More...
 
void push_front (const T &x)
 Push an element to the front of the queue. More...
 
void pop_front ()
 Remove the first element from the front. More...
 
void push_back (const T &x)
 Push an element to the backside of the queue. More...
 
void pop_back ()
 Remove the first element from the back. More...
 

Detailed Description

template<class T, size_t EmbeddedCapacity = 0>
class roc::core::RingQueue< T, EmbeddedCapacity >

Queue on continuous memory buffer.

Elements are stored continuously in a memory chunk allocated using IArena, or directly in Array object when number of elements is small.

RingQueue supports inserting and removing elements to the beginning and to the end with O(1) complexity.

Template Parameters
Tdefines array element type. It should have default constructor and copy constructor.
EmbeddedCapacitydefines number of elements in the fixed-size chunk embedded directly into RingQueue object.

Definition at line 37 of file ring_queue.h.

Constructor & Destructor Documentation

◆ RingQueue()

template<class T , size_t EmbeddedCapacity = 0>
roc::core::RingQueue< T, EmbeddedCapacity >::RingQueue ( core::IArena arena,
size_t  max_len 
)
inline

Initialize.

Remarks
Preallocate buffer in arena with max_len number of elements.

Definition at line 42 of file ring_queue.h.

Member Function Documentation

◆ back() [1/2]

template<class T , size_t EmbeddedCapacity = 0>
T& roc::core::RingQueue< T, EmbeddedCapacity >::back ( )
inline

Get reference of the back element.

Precondition
Queue should not be empty.

Definition at line 109 of file ring_queue.h.

◆ back() [2/2]

template<class T , size_t EmbeddedCapacity = 0>
const T& roc::core::RingQueue< T, EmbeddedCapacity >::back ( ) const
inline

Get reference of the back element.

Precondition
Queue should not be empty.

Definition at line 119 of file ring_queue.h.

◆ capacity()

template<class T , size_t EmbeddedCapacity = 0>
size_t roc::core::RingQueue< T, EmbeddedCapacity >::capacity ( ) const
inline

Get maximum number of elements in queue/.

Definition at line 67 of file ring_queue.h.

◆ front() [1/2]

template<class T , size_t EmbeddedCapacity = 0>
T& roc::core::RingQueue< T, EmbeddedCapacity >::front ( )
inline

Get reference of the front element.

Precondition
Queue should not be empty.

Definition at line 89 of file ring_queue.h.

◆ front() [2/2]

template<class T , size_t EmbeddedCapacity = 0>
const T& roc::core::RingQueue< T, EmbeddedCapacity >::front ( ) const
inline

Get reference of the front element.

Precondition
Queue should not be empty.

Definition at line 99 of file ring_queue.h.

◆ is_empty()

template<class T , size_t EmbeddedCapacity = 0>
bool roc::core::RingQueue< T, EmbeddedCapacity >::is_empty ( )
inline

Is the queue empty.

Definition at line 77 of file ring_queue.h.

◆ is_full()

template<class T , size_t EmbeddedCapacity = 0>
bool roc::core::RingQueue< T, EmbeddedCapacity >::is_full ( )
inline

Is the queue full.

Definition at line 82 of file ring_queue.h.

◆ is_valid()

template<class T , size_t EmbeddedCapacity = 0>
bool roc::core::RingQueue< T, EmbeddedCapacity >::is_valid ( ) const
inline

Check that initial allocation succeeded.

Definition at line 62 of file ring_queue.h.

◆ pop_back()

template<class T , size_t EmbeddedCapacity = 0>
void roc::core::RingQueue< T, EmbeddedCapacity >::pop_back ( )
inline

Remove the first element from the back.

Precondition
Queue should not be empty.

Definition at line 162 of file ring_queue.h.

◆ pop_front()

template<class T , size_t EmbeddedCapacity = 0>
void roc::core::RingQueue< T, EmbeddedCapacity >::pop_front ( )
inline

Remove the first element from the front.

Precondition
Queue should not be empty.

Definition at line 140 of file ring_queue.h.

◆ push_back()

template<class T , size_t EmbeddedCapacity = 0>
void roc::core::RingQueue< T, EmbeddedCapacity >::push_back ( const T &  x)
inline

Push an element to the backside of the queue.

Precondition
Queue should not be full.

Definition at line 151 of file ring_queue.h.

◆ push_front()

template<class T , size_t EmbeddedCapacity = 0>
void roc::core::RingQueue< T, EmbeddedCapacity >::push_front ( const T &  x)
inline

Push an element to the front of the queue.

Precondition
Queue should not be full.

Definition at line 129 of file ring_queue.h.

◆ size()

template<class T , size_t EmbeddedCapacity = 0>
size_t roc::core::RingQueue< T, EmbeddedCapacity >::size ( ) const
inline

Get current number of elements in the queue.

Definition at line 72 of file ring_queue.h.


The documentation for this class was generated from the following file: