Sirikata
Public Types | Public Member Functions | Private Member Functions | Private Attributes
Sirikata::CircularBuffer< DataType > Class Template Reference

A circular buffer. More...

#include <CircularBuffer.hpp>

Collaboration diagram for Sirikata::CircularBuffer< DataType >:

List of all members.

Public Types

typedef std::pair< bool, DataType > OptionalReturnData
 Data type for optionally returning data.

Public Member Functions

 CircularBuffer (std::size_t cap)
 Create an empty CircularBuffer with the given capacity.
 CircularBuffer (std::size_t cap, const DataType &v)
 Create a full CircularBuffer with the given capacity, with all values initialized to v.
std::size_t size () const
std::size_t capacity () const
bool empty () const
bool full () const
OptionalReturnData push (const DataType &v)
 Push the given value and, if the buffer overflows, return a copy.
DataType pop ()
 Pop an element.
const DataType & front () const
DataType & front ()
const DataType & back () const
DataType & back ()
DataType & operator[] (std::size_t i)
const DataType & operator[] (std::size_t i) const

Private Member Functions

std::size_t safeIdx (std::size_t i, int32 offset) const

Private Attributes

std::vector< DataType > mData
std::size_t mStart
std::size_t mCount

Detailed Description

template<typename DataType>
class Sirikata::CircularBuffer< DataType >

A circular buffer.

You specify a maximum number of elements for the buffer to hold and push/pop items into/out of it. If you exceed the capacity, the oldest samples still remaining are left in the buffer, and you can optionally have the value returned when you push another element.


Member Typedef Documentation

template<typename DataType>
typedef std::pair<bool, DataType> Sirikata::CircularBuffer< DataType >::OptionalReturnData

Data type for optionally returning data.

The bool indicates whether any data is returned, the second value is the value.


Constructor & Destructor Documentation

template<typename DataType>
Sirikata::CircularBuffer< DataType >::CircularBuffer ( std::size_t  cap) [inline]

Create an empty CircularBuffer with the given capacity.

template<typename DataType>
Sirikata::CircularBuffer< DataType >::CircularBuffer ( std::size_t  cap,
const DataType &  v 
) [inline]

Create a full CircularBuffer with the given capacity, with all values initialized to v.


Member Function Documentation

template<typename DataType>
const DataType& Sirikata::CircularBuffer< DataType >::back ( ) const [inline]
template<typename DataType>
DataType& Sirikata::CircularBuffer< DataType >::back ( ) [inline]
template<typename DataType>
std::size_t Sirikata::CircularBuffer< DataType >::capacity ( ) const [inline]
template<typename DataType>
bool Sirikata::CircularBuffer< DataType >::empty ( ) const [inline]
template<typename DataType>
DataType& Sirikata::CircularBuffer< DataType >::front ( ) [inline]
template<typename DataType>
const DataType& Sirikata::CircularBuffer< DataType >::front ( ) const [inline]
template<typename DataType>
bool Sirikata::CircularBuffer< DataType >::full ( ) const [inline]
template<typename DataType>
DataType& Sirikata::CircularBuffer< DataType >::operator[] ( std::size_t  i) [inline]
template<typename DataType>
const DataType& Sirikata::CircularBuffer< DataType >::operator[] ( std::size_t  i) const [inline]
template<typename DataType>
DataType Sirikata::CircularBuffer< DataType >::pop ( ) [inline]

Pop an element.

Referenced by Sirikata::CircularBuffer< SampleType >::push().

template<typename DataType>
OptionalReturnData Sirikata::CircularBuffer< DataType >::push ( const DataType &  v) [inline]

Push the given value and, if the buffer overflows, return a copy.

Referenced by Sirikata::Trace::WindowedStats< SampleType >::sample().

template<typename DataType>
std::size_t Sirikata::CircularBuffer< DataType >::safeIdx ( std::size_t  i,
int32  offset 
) const [inline, private]
template<typename DataType>
std::size_t Sirikata::CircularBuffer< DataType >::size ( ) const [inline]

Member Data Documentation

template<typename DataType>
std::size_t Sirikata::CircularBuffer< DataType >::mCount [private]
template<typename DataType>
std::vector<DataType> Sirikata::CircularBuffer< DataType >::mData [private]
template<typename DataType>
std::size_t Sirikata::CircularBuffer< DataType >::mStart [private]

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