MPD  0.20.6
Public Types | Public Member Functions | Protected Member Functions | Protected Attributes
CircularBuffer< T > Class Template Reference

A circular buffer. More...

#include <ThreadInputStream.hxx>

Public Types

typedef WritableBuffer< T > Range
 
typedef Range::pointer_type pointer_type
 
typedef Range::size_type size_type
 

Public Member Functions

constexpr CircularBuffer (pointer_type _data, size_type _capacity)
 
 CircularBuffer (const CircularBuffer &other)=delete
 
void Clear ()
 
constexpr size_type GetCapacity () const
 
constexpr bool IsEmpty () const
 
constexpr bool IsFull () const
 
constexpr size_type GetSize () const
 Returns the number of elements stored in this buffer. More...
 
constexpr size_type GetSpace () const
 Returns the number of elements that can be added to this buffer. More...
 
Range Write ()
 Prepares writing. More...
 
void Append (size_type n)
 Expands the tail of the buffer, after data has been written to the buffer returned by Write(). More...
 
Range Read ()
 Return a buffer range which may be read. More...
 
void Consume (size_type n)
 Marks a chunk as consumed. More...
 

Protected Member Functions

constexpr size_type Next (size_type i) const
 

Protected Attributes

size_type head
 The next index to be read. More...
 
size_type tail
 The next index to be written to. More...
 
const size_type capacity
 
const pointer_type data
 

Detailed Description

template<typename T>
class CircularBuffer< T >

A circular buffer.

This class does not manage buffer memory. It will not allocate or free any memory, it only manages the contents of an existing buffer given to the constructor.

Everything between head and tail is valid data (may wrap around). If both are equal, then the buffer is empty. Due to this implementation detail, the buffer is empty when #size-1 items are stored; the last buffer cell cannot be used.

Definition at line 32 of file ThreadInputStream.hxx.

Member Typedef Documentation

template<typename T>
typedef Range::pointer_type CircularBuffer< T >::pointer_type

Definition at line 54 of file CircularBuffer.hxx.

template<typename T>
typedef WritableBuffer<T> CircularBuffer< T >::Range

Definition at line 53 of file CircularBuffer.hxx.

template<typename T>
typedef Range::size_type CircularBuffer< T >::size_type

Definition at line 55 of file CircularBuffer.hxx.

Constructor & Destructor Documentation

template<typename T>
constexpr CircularBuffer< T >::CircularBuffer ( pointer_type  _data,
size_type  _capacity 
)
inline

Definition at line 72 of file CircularBuffer.hxx.

template<typename T>
CircularBuffer< T >::CircularBuffer ( const CircularBuffer< T > &  other)
delete

Member Function Documentation

template<typename T>
void CircularBuffer< T >::Append ( size_type  n)
inline

Expands the tail of the buffer, after data has been written to the buffer returned by Write().

Definition at line 144 of file CircularBuffer.hxx.

template<typename T>
void CircularBuffer< T >::Clear ( )
inline

Definition at line 85 of file CircularBuffer.hxx.

template<typename T>
void CircularBuffer< T >::Consume ( size_type  n)
inline

Marks a chunk as consumed.

Definition at line 173 of file CircularBuffer.hxx.

template<typename T>
constexpr size_type CircularBuffer< T >::GetCapacity ( ) const
inline

Definition at line 89 of file CircularBuffer.hxx.

template<typename T>
constexpr size_type CircularBuffer< T >::GetSize ( ) const
inline

Returns the number of elements stored in this buffer.

Definition at line 104 of file CircularBuffer.hxx.

template<typename T>
constexpr size_type CircularBuffer< T >::GetSpace ( ) const
inline

Returns the number of elements that can be added to this buffer.

Definition at line 114 of file CircularBuffer.hxx.

template<typename T>
constexpr bool CircularBuffer< T >::IsEmpty ( ) const
inline

Definition at line 93 of file CircularBuffer.hxx.

template<typename T>
constexpr bool CircularBuffer< T >::IsFull ( ) const
inline

Definition at line 97 of file CircularBuffer.hxx.

template<typename T>
constexpr size_type CircularBuffer< T >::Next ( size_type  i) const
inlineprotected

Definition at line 78 of file CircularBuffer.hxx.

template<typename T>
Range CircularBuffer< T >::Read ( )
inline

Return a buffer range which may be read.

The buffer pointer is writable, to allow modifications while parsing.

Definition at line 163 of file CircularBuffer.hxx.

template<typename T>
Range CircularBuffer< T >::Write ( )
inline

Prepares writing.

Returns a buffer range which may be written. When you are finished, call Append().

Definition at line 126 of file CircularBuffer.hxx.

Field Documentation

template<typename T>
const size_type CircularBuffer< T >::capacity
protected

Definition at line 68 of file CircularBuffer.hxx.

template<typename T>
const pointer_type CircularBuffer< T >::data
protected

Definition at line 69 of file CircularBuffer.hxx.

template<typename T>
size_type CircularBuffer< T >::head
protected

The next index to be read.

Definition at line 61 of file CircularBuffer.hxx.

template<typename T>
size_type CircularBuffer< T >::tail
protected

The next index to be written to.

Definition at line 66 of file CircularBuffer.hxx.


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