#include <circBuffer.h>
Public Member Functions | |
CircBuffer () | |
~CircBuffer () | |
int | size () const |
Returns the number of items currently in the buffer. | |
bool | empty () const |
Returns true if the buffer is empty. | |
const Thing & | front () const |
Returns a reference to the first item in the queue. | |
Thing & | front () |
Returns a reference to the first item in the queue. | |
void | pop_front () |
Removes the first item from the buffer. | |
const Thing & | operator[] (int n) const |
Returns the nth element in the buffer. | |
Thing & | operator[] (int n) |
Returns the nth element in the buffer. | |
bool | full () const |
Returns true if the buffer is full; if this is true, push_back() will fail. | |
const Thing & | back () const |
Returns a reference to the last item in the queue. | |
Thing & | back () |
Returns a reference to the last item in the queue. | |
void | push_back (const Thing &t) |
Adds an item to the end of the buffer. | |
Private Attributes | |
Thing | _array [max_size+1] |
int | _in |
int | _out |
The circular buffer has the advantage that no synchronization is required when one process adds to the queue while another process extracts. It works for any kind of Thing that has a valid assignment operator and copy constructor defined.
Definition at line 47 of file circBuffer.h.
|
Definition at line 37 of file circBuffer.I. References INLINE. |
|
Definition at line 50 of file circBuffer.I. References CircBuffer< Thing, max_size >::_in, CircBuffer< Thing, max_size >::_out, and INLINE. |
|
Returns a reference to the last item in the queue. It is invalid to call this if empty() is true. It is safe to call this without synchronization primitives only from the writing thread: the thread that calls push_back(). Definition at line 266 of file circBuffer.I. |
|
Returns a reference to the last item in the queue. It is invalid to call this if empty() is true. It is safe to call this without synchronization primitives only from the writing thread: the thread that calls push_back(). Definition at line 243 of file circBuffer.I. |
|
Returns true if the buffer is empty. It is safe to call this without synchronization primitives from either the reader or the writer thread, but the result may vary without warning after the call. Definition at line 92 of file circBuffer.I. References CircBuffer< Thing, max_size >::_array, CircBuffer< Thing, max_size >::_out, INLINE, and nassertr. Referenced by CircBuffer< Thing, max_size >::front(), CircBuffer< Thing, max_size >::full(), and CircBuffer< Thing, max_size >::operator[](). |
|
Returns a reference to the first item in the queue. It is invalid to call this if empty() is true. It is safe to call this without synchronization only from the reading thread: the thread that calls pop_front(). Definition at line 156 of file circBuffer.I. References CircBuffer< Thing, max_size >::_array, CircBuffer< Thing, max_size >::_out, CircBuffer< Thing, max_size >::empty(), INLINE, and nassertv. |
|
Returns a reference to the first item in the queue. It is invalid to call this if empty() is true. It is safe to call this without synchronization only from the reading thread: the thread that calls pop_front(). Definition at line 135 of file circBuffer.I. References CircBuffer< Thing, max_size >::_array, CircBuffer< Thing, max_size >::_out, CircBuffer< Thing, max_size >::empty(), INLINE, and nassertr. |
|
Returns true if the buffer is full; if this is true, push_back() will fail. It is safe to call this without synchronization primitives from either the reader or the writer thread, but the result may vary without warning after the call. Definition at line 114 of file circBuffer.I. References CircBuffer< Thing, max_size >::_array, CircBuffer< Thing, max_size >::_out, CircBuffer< Thing, max_size >::empty(), INLINE, and nassertr. Referenced by CircBuffer< Thing, max_size >::pop_front(). |
|
Returns the nth element in the buffer. It is safe to call this without synchronization only from the reading thread: the thread that calls pop_front(). Definition at line 194 of file circBuffer.I. References CircBuffer< Thing, max_size >::_array, CircBuffer< Thing, max_size >::_in, CircBuffer< Thing, max_size >::empty(), INLINE, and nassertr. |
|
Returns the nth element in the buffer. It is safe to call this without synchronization only from the reading thread: the thread that calls pop_front(). Definition at line 175 of file circBuffer.I. References CircBuffer< Thing, max_size >::_array, CircBuffer< Thing, max_size >::_in, CircBuffer< Thing, max_size >::empty(), INLINE, and nassertr. |
|
Removes the first item from the buffer.
Definition at line 210 of file circBuffer.I. References CircBuffer< Thing, max_size >::_array, CircBuffer< Thing, max_size >::_in, CircBuffer< Thing, max_size >::full(), INLINE, and t. |
|
Adds an item to the end of the buffer. This may fail if full() is true. Definition at line 283 of file circBuffer.I. |
|
Returns the number of items currently in the buffer. This can safely be called without synchronization from either the reader or the writer thread, but the size may of course vary without warning after the call. Definition at line 71 of file circBuffer.I. References CircBuffer< Thing, max_size >::_in, CircBuffer< Thing, max_size >::_out, and INLINE. |
|
Definition at line 76 of file circBuffer.h. Referenced by CircBuffer< Thing, max_size >::empty(), CircBuffer< Thing, max_size >::front(), CircBuffer< Thing, max_size >::full(), CircBuffer< Thing, max_size >::operator[](), and CircBuffer< Thing, max_size >::pop_front(). |
|
Definition at line 77 of file circBuffer.h. Referenced by CircBuffer< Thing, max_size >::operator[](), CircBuffer< Thing, max_size >::pop_front(), CircBuffer< Thing, max_size >::size(), and CircBuffer< Thing, max_size >::~CircBuffer(). |
|
Definition at line 77 of file circBuffer.h. Referenced by CircBuffer< Thing, max_size >::empty(), CircBuffer< Thing, max_size >::front(), CircBuffer< Thing, max_size >::full(), CircBuffer< Thing, max_size >::size(), and CircBuffer< Thing, max_size >::~CircBuffer(). |