S3FC project page S3FC home page

Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Related Pages  

s3_ring_buffer Class Template Reference

This class implements a ring (or circular) buffer. More...

#include <s3_ring_buffer.h>

Collaboration diagram for s3_ring_buffer:

Collaboration graph
[legend]
List of all members.

Public Methods

 s3_ring_buffer (const unsigned int n_capacity)
 Construct a ring buffer with the specified capacity. More...

 s3_ring_buffer (const unsigned int n_capacity, const T &t)
 Construct a ring buffer with the specified capacity. More...

 s3_ring_buffer (const s3_ring_buffer &t)
 Copy constructor makes a deep copy. More...

 ~s3_ring_buffer ()
 Free the buffer memory. More...

void push_back (const T &element)
 Insert an element at the end of the buffer. More...

unsigned int size () const
 Return the number of elements in the buffer. More...

unsigned int get_capacity () const
 Return the capacity of the buffer. More...

bool empty () const
 Return true if the buffer is empty. More...

bool full () const
 Return true if the buffer is full. More...

T & operator[] (const unsigned int index) const
 The operator return a reference to the element indexed by index. More...

T & back (void) const throw ( s3_index_exception )
 Returns a reference to the last (i.e. More...

s3_ring_buffer & operator= (const s3_ring_buffer &t)
 The assignment operator makes a deep copy of the data. More...

bool operator== (const s3_ring_buffer &t)
 The equality operator checks whether all elements in the buffer are equal. More...


Private Attributes

unsigned int capacity
 The capacity (length) of the ring buffer. More...

unsigned int num_of_elems
 The number of elements stored in the buffer. More...

T * buffer
 The data buffer. More...

unsigned int buffer_start
 Index to the start (oldest element) of the ring buffer. More...


Detailed Description

template<typename T>
class s3_ring_buffer< T >

This class implements a ring (or circular) buffer.

The ring buffer is a fixed length storage bin, that overwrites the first elements when the buffer has reached capacity.

Definition at line 44 of file s3_ring_buffer.h.


Constructor & Destructor Documentation

template<typename T>
s3_ring_buffer< T >::s3_ring_buffer const unsigned int    n_capacity [inline]
 

Construct a ring buffer with the specified capacity.

This constructor will create an empty buffer.

Parameters:
n_capacity  The capacity of the new buffer.

Definition at line 68 of file s3_ring_buffer.h.

References buffer, buffer_start, capacity, and num_of_elems.

template<typename T>
s3_ring_buffer< T >::s3_ring_buffer const unsigned int    n_capacity,
const T &    t
[inline]
 

Construct a ring buffer with the specified capacity.

This constructor will create a buffer of size capacity and all elements will be initialized to t.

Parameters:
n_capacity  The capacity of the new buffer.
t  Initialize a vector of size capacity with this object.

Definition at line 83 of file s3_ring_buffer.h.

References buffer, buffer_start, capacity, num_of_elems, and push_back.

template<typename T>
s3_ring_buffer< T >::s3_ring_buffer const s3_ring_buffer< T > &    t [inline]
 

Copy constructor makes a deep copy.

Definition at line 98 of file s3_ring_buffer.h.

References buffer, buffer_start, capacity, get_capacity, num_of_elems, and push_back.

template<typename T>
s3_ring_buffer< T >::~s3_ring_buffer   [inline]
 

Free the buffer memory.

Definition at line 115 of file s3_ring_buffer.h.

References buffer.


Member Function Documentation

template<typename T>
T& s3_ring_buffer< T >::back void    const throw ( s3_index_exception ) [inline]
 

Returns a reference to the last (i.e.

the newest) element. If the ring buffer contains no elements, an s3_index_exception is thrown.

Returns:
A reference to the last element.
Exceptions:
s3_generic_exception  if the buffer is empty.

Definition at line 205 of file s3_ring_buffer.h.

References buffer, buffer_start, capacity, empty, full, and num_of_elems.

template<typename T>
bool s3_ring_buffer< T >::empty   const [inline]
 

Return true if the buffer is empty.

Returns:
True if the buffer is empty, false otherwise.

Definition at line 161 of file s3_ring_buffer.h.

References size.

Referenced by back.

template<typename T>
bool s3_ring_buffer< T >::full   const [inline]
 

Return true if the buffer is full.

Returns:
True if the buffer is full, false otherwise.

Definition at line 170 of file s3_ring_buffer.h.

References capacity, and size.

Referenced by back, and push_back.

template<typename T>
unsigned int s3_ring_buffer< T >::get_capacity void    const [inline]
 

Return the capacity of the buffer.

Returns:
The capacity of the buffer.

Definition at line 153 of file s3_ring_buffer.h.

References capacity.

Referenced by operator=, operator==, and s3_ring_buffer.

template<typename T>
s3_ring_buffer& s3_ring_buffer< T >::operator= const s3_ring_buffer< T > &    t [inline]
 

The assignment operator makes a deep copy of the data.

Definition at line 228 of file s3_ring_buffer.h.

References buffer, buffer_start, capacity, get_capacity, num_of_elems, push_back, and size.

template<typename T>
bool s3_ring_buffer< T >::operator== const s3_ring_buffer< T > &    t [inline]
 

The equality operator checks whether all elements in the buffer are equal.

This code should undergo further testing before being used in cruise missile operating systems, etc.

Definition at line 254 of file s3_ring_buffer.h.

References get_capacity, operator[], and size.

template<typename T>
T& s3_ring_buffer< T >::operator[] const unsigned int    index const [inline]
 

The operator return a reference to the element indexed by index.

The index is counted from the start of the buffer (i.e. the oldest element in the buffer).

Parameters:
index  The index of the element to return.
Returns:
A reference to the requested element.

Definition at line 183 of file s3_ring_buffer.h.

References buffer, buffer_start, capacity, and size.

Referenced by operator==.

template<typename T>
void s3_ring_buffer< T >::push_back const T &    element [inline]
 

Insert an element at the end of the buffer.

If the buffer is full, the first (i.e. the oldest) element is removed.

Definition at line 128 of file s3_ring_buffer.h.

References buffer, buffer_start, capacity, full, num_of_elems, and size.

Referenced by operator=, and s3_ring_buffer.

template<typename T>
unsigned int s3_ring_buffer< T >::size   const [inline]
 

Return the number of elements in the buffer.

Returns:
The number of elements stored in the buffer.

Definition at line 145 of file s3_ring_buffer.h.

References num_of_elems.

Referenced by empty, full, operator=, operator==, operator[], and push_back.


Member Data Documentation

template<typename T>
T* s3_ring_buffer::buffer [private]
 

The data buffer.

Definition at line 58 of file s3_ring_buffer.h.

Referenced by back, operator=, operator[], push_back, s3_ring_buffer, and ~s3_ring_buffer.

template<typename T>
unsigned int s3_ring_buffer::buffer_start [private]
 

Index to the start (oldest element) of the ring buffer.

Definition at line 61 of file s3_ring_buffer.h.

Referenced by back, operator=, operator[], push_back, and s3_ring_buffer.

template<typename T>
unsigned int s3_ring_buffer::capacity [private]
 

The capacity (length) of the ring buffer.

Definition at line 52 of file s3_ring_buffer.h.

Referenced by back, full, get_capacity, operator=, operator[], push_back, and s3_ring_buffer.

template<typename T>
unsigned int s3_ring_buffer::num_of_elems [private]
 

The number of elements stored in the buffer.

Definition at line 55 of file s3_ring_buffer.h.

Referenced by back, operator=, push_back, s3_ring_buffer, and size.


The documentation for this class was generated from the following file:
Send comments to: s3fc@stonethree.com SourceForge Logo