Panda3D
Loading...
Searching...
No Matches
Public Member Functions | List of all members
CircBuffer< Thing, max_size > Class Template Reference

This class implements a queue of some type via a circular buffer. More...

#include "circBuffer.h"

Public Member Functions

Thing & back ()
 Returns a reference to the last item in the queue.
 
const Thing & back () const
 Returns a reference to the last item in the queue.
 
void clear ()
 Removes all items from the queue.
 
bool empty () const
 Returns true if the buffer is empty.
 
Thing & front ()
 Returns a reference to the first item in the queue.
 
const Thing & front () const
 Returns a reference to the first item in the queue.
 
bool full () const
 Returns true if the buffer is full; if this is true, push_back() will fail.
 
Thing & operator[] (int n)
 Returns the nth element in the buffer.
 
const Thing & operator[] (int n) const
 Returns the nth element in the buffer.
 
void pop_front ()
 Removes the first item from the buffer.
 
void push_back (const Thing &t)
 Adds an item to the end of the buffer.
 
int size () const
 Returns the number of items currently in the buffer.
 

Detailed Description

template<class Thing, int max_size>
class CircBuffer< Thing, max_size >

This class implements a queue of some type via a circular buffer.

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 27 of file circBuffer.h.

Constructor & Destructor Documentation

◆ CircBuffer()

template<class Thing , int max_size>
CircBuffer< Thing, max_size >::CircBuffer ( )
inline

Definition at line 22 of file circBuffer.I.

◆ ~CircBuffer()

template<class Thing , int max_size>
CircBuffer< Thing, max_size >::~CircBuffer ( )
inline

Definition at line 31 of file circBuffer.I.

Member Function Documentation

◆ back() [1/2]

template<class Thing , int max_size>
Thing & CircBuffer< Thing, max_size >::back ( )
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 158 of file circBuffer.I.

◆ back() [2/2]

template<class Thing , int max_size>
const Thing & CircBuffer< Thing, max_size >::back ( ) const
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 146 of file circBuffer.I.

◆ clear()

template<class Thing , int max_size>
void CircBuffer< Thing, max_size >::clear ( )
inline

Removes all items from the queue.

Definition at line 183 of file circBuffer.I.

◆ empty()

template<class Thing , int max_size>
bool CircBuffer< Thing, max_size >::empty ( ) const
inline

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 53 of file circBuffer.I.

◆ front() [1/2]

template<class Thing , int max_size>
Thing & CircBuffer< Thing, max_size >::front ( )
inline

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 89 of file circBuffer.I.

◆ front() [2/2]

template<class Thing , int max_size>
const Thing & CircBuffer< Thing, max_size >::front ( ) const
inline

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 77 of file circBuffer.I.

◆ full()

template<class Thing , int max_size>
bool CircBuffer< Thing, max_size >::full ( ) const
inline

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 65 of file circBuffer.I.

◆ operator[]() [1/2]

template<class Thing , int max_size>
Thing & CircBuffer< Thing, max_size >::operator[] ( int n)
inline

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 113 of file circBuffer.I.

◆ operator[]() [2/2]

template<class Thing , int max_size>
const Thing & CircBuffer< Thing, max_size >::operator[] ( int n) const
inline

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 101 of file circBuffer.I.

◆ pop_front()

template<class Thing , int max_size>
void CircBuffer< Thing, max_size >::pop_front ( )
inline

Removes the first item from the buffer.

Definition at line 124 of file circBuffer.I.

◆ push_back()

template<class Thing , int max_size>
void CircBuffer< Thing, max_size >::push_back ( const Thing & t)
inline

Adds an item to the end of the buffer.

This may fail if full() is true.

Definition at line 168 of file circBuffer.I.

◆ size()

template<class Thing , int max_size>
int CircBuffer< Thing, max_size >::size ( ) const
inline

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 41 of file circBuffer.I.


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