glbinding  3.3.0.0
A C++ binding for the OpenGL API, generated using the gl.xml specification.
Loading...
Searching...
No Matches
glbinding::aux::RingBuffer< T > Class Template Reference

A threadsafe queue with a single insertion and multiple extraction points. More...

#include <glbinding-aux/RingBuffer.h>

Public Types

using SizeType = unsigned int
 Numeric type employed for indices, sizes and distances.
 
using TailIdentifier = unsigned int
 Identifier type for tails.
 

Public Member Functions

 RingBuffer (SizeType maxSize)
 Constructor.
 
void resize (SizeType newSize)
 Resize buffer.
 
nextHead (bool &available) const
 Retrieve element beyond current head.
 
bool push (T &&entry)
 Add an element to the buffer, if possible.
 
bool push (T &entry)
 Add an element to the buffer, if possible.
 
TailIdentifier addTail ()
 Add a new tail to the buffer.
 
void removeTail (TailIdentifier key)
 Remove a tail from the buffer.
 
const std::vector< T >::const_iterator cbegin (TailIdentifier key) const
 Retrieve the iterator for a tail.
 
bool valid (TailIdentifier key, const typename std::vector< T >::const_iterator &it) const
 Check if iterator is valid.
 
const std::vector< T >::const_iterator next (TailIdentifier key, const typename std::vector< T >::const_iterator &it)
 Advance the iterator of a tail.
 
SizeType size (TailIdentifier key)
 Calculate distance between tail and head.
 
SizeType maxSize () const
 Query maximum size.
 
SizeType size () const
 Query current size.
 
bool isFull () const
 Query if buffer is full.
 
bool isEmpty () const
 Query if buffer is empty.
 

Protected Member Functions

SizeType next (SizeType current) const
 Calculate following index in internal buffer.
 
bool isFull (SizeType nextHead) const
 Check if head can advance.
 
SizeType lastTail () const
 Determine last (furthest behind) index still in use.
 
SizeType size (SizeType head, SizeType tail) const
 Calculate size of range between two indices.
 

Protected Attributes

std::vector< T > m_buffer
 Internal buffer.
 
SizeType m_size
 Size of buffer.
 
std::atomic< SizeTypem_head
 Index of head (newest element)
 
std::map< TailIdentifier, std::atomic< SizeType > > m_tails
 Map (identifier->index) of tails.
 

Detailed Description

template<typename T>
class glbinding::aux::RingBuffer< T >

A threadsafe queue with a single insertion and multiple extraction points.

Template Parameters
TData type stored within the buffer

Member Typedef Documentation

◆ SizeType

template<typename T >
using glbinding::aux::RingBuffer< T >::SizeType = unsigned int

Numeric type employed for indices, sizes and distances.

◆ TailIdentifier

template<typename T >
using glbinding::aux::RingBuffer< T >::TailIdentifier = unsigned int

Identifier type for tails.

Constructor & Destructor Documentation

◆ RingBuffer()

template<typename T >
glbinding::aux::RingBuffer< T >::RingBuffer ( SizeType maxSize)

Constructor.

Parameters
[in]maxSizeMaximum size for the buffer

References glbinding::aux::RingBuffer< T >::m_buffer, and glbinding::aux::RingBuffer< T >::m_size.

Member Function Documentation

◆ resize()

template<typename T >
void glbinding::aux::RingBuffer< T >::resize ( SizeType newSize)

Resize buffer.

Parameters
[in]newSizeNew maximum size for the buffer

◆ nextHead()

template<typename T >
T glbinding::aux::RingBuffer< T >::nextHead ( bool & available) const

Retrieve element beyond current head.

Parameters
[out]availabletrue if buffer has available space, false otherwise
Returns
Requested element if buffer has available space, nullptr otherwise

◆ push() [1/2]

template<typename T >
bool glbinding::aux::RingBuffer< T >::push ( T && entry)

Add an element to the buffer, if possible.

Parameters
[in]entryElement to add
Returns
true if the element could be added, false otherwise

◆ push() [2/2]

template<typename T >
bool glbinding::aux::RingBuffer< T >::push ( T & entry)

Add an element to the buffer, if possible.

Parameters
[in]entryElement to add
Returns
true if the element could be added, false otherwise

◆ addTail()

template<typename T >
RingBuffer< T >::TailIdentifier glbinding::aux::RingBuffer< T >::addTail ( )

Add a new tail to the buffer.

Returns
Identifier for the newly added tail

◆ removeTail()

template<typename T >
void glbinding::aux::RingBuffer< T >::removeTail ( TailIdentifier key)

Remove a tail from the buffer.

Parameters
[in]keyIdentifier for the tail to be removed

◆ cbegin()

template<typename T >
const std::vector< T >::const_iterator glbinding::aux::RingBuffer< T >::cbegin ( TailIdentifier key) const

Retrieve the iterator for a tail.

Parameters
[in]keyIdentifier for the tail
Returns
Iterator belonging to the tail
Remarks
Use RingBuffer::next() to advance the iterator

◆ valid()

template<typename T >
bool glbinding::aux::RingBuffer< T >::valid ( TailIdentifier key,
const typename std::vector< T >::const_iterator & it ) const

Check if iterator is valid.

Parameters
[in]keyIdentifier for the tail
[in]itIterator to check
Returns
true if iterator is valid, false otherwise

◆ next() [1/2]

template<typename T >
const std::vector< T >::const_iterator glbinding::aux::RingBuffer< T >::next ( TailIdentifier key,
const typename std::vector< T >::const_iterator & it )

Advance the iterator of a tail.

Parameters
[in]keyIdentifier for the tail
[in]itIterator to return in case of failure
Returns
Next iterator if tail could be advanced, it otherwise

◆ size() [1/3]

template<typename T >
RingBuffer< T >::SizeType glbinding::aux::RingBuffer< T >::size ( TailIdentifier key)

Calculate distance between tail and head.

Parameters
[in]keyIdentifier for tail
Returns
Distance between tail and head

◆ maxSize()

template<typename T >
RingBuffer< T >::SizeType glbinding::aux::RingBuffer< T >::maxSize ( ) const

Query maximum size.

Returns
Maximum size

◆ size() [2/3]

template<typename T >
RingBuffer< T >::SizeType glbinding::aux::RingBuffer< T >::size ( ) const

Query current size.

Returns
Current size (= distance of the tail furthest behind the head)

◆ isFull() [1/2]

template<typename T >
bool glbinding::aux::RingBuffer< T >::isFull ( ) const

Query if buffer is full.

Returns
true if buffer is full, false otherwise

◆ isEmpty()

template<typename T >
bool glbinding::aux::RingBuffer< T >::isEmpty ( ) const

Query if buffer is empty.

Returns
true if buffer is empty, false otherwise

◆ next() [2/2]

template<typename T >
RingBuffer< T >::SizeType glbinding::aux::RingBuffer< T >::next ( SizeType current) const
protected

Calculate following index in internal buffer.

Parameters
[in]currentBase index
Returns
Index following current

◆ isFull() [2/2]

template<typename T >
bool glbinding::aux::RingBuffer< T >::isFull ( SizeType nextHead) const
protected

Check if head can advance.

Parameters
[in]nextHeadIndex to check
Returns
true if nextHead is referenced by a tail, false otherwise

◆ lastTail()

template<typename T >
RingBuffer< T >::SizeType glbinding::aux::RingBuffer< T >::lastTail ( ) const
protected

Determine last (furthest behind) index still in use.

Returns
Last index

◆ size() [3/3]

template<typename T >
RingBuffer< T >::SizeType glbinding::aux::RingBuffer< T >::size ( SizeType head,
SizeType tail ) const
protected

Calculate size of range between two indices.

Parameters
[in]headEnd of range
[in]tailStart of range
Returns
Size of range

Member Data Documentation

◆ m_buffer

template<typename T >
std::vector<T> glbinding::aux::RingBuffer< T >::m_buffer
protected

Internal buffer.

Referenced by glbinding::aux::RingBuffer< T >::RingBuffer().

◆ m_size

template<typename T >
SizeType glbinding::aux::RingBuffer< T >::m_size
protected

Size of buffer.

Referenced by glbinding::aux::RingBuffer< T >::RingBuffer().

◆ m_head

template<typename T >
std::atomic<SizeType> glbinding::aux::RingBuffer< T >::m_head
protected

Index of head (newest element)

◆ m_tails

template<typename T >
std::map<TailIdentifier, std::atomic<SizeType> > glbinding::aux::RingBuffer< T >::m_tails
protected

Map (identifier->index) of tails.


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