Main MRPT website > C++ reference for MRPT 1.9.9
List of all members | Public Member Functions | Private Attributes
mrpt::containers::circular_buffer< T > Class Template Reference

Detailed Description

template<typename T>
class mrpt::containers::circular_buffer< T >

A circular buffer of fixed size (defined at construction-time), implemented with a std::vector as the underlying storage.

Note
Defined in #include <mrpt/containers/circular_buffer.h>

Definition at line 25 of file circular_buffer.h.

#include <mrpt/containers/circular_buffer.h>

Inheritance diagram for mrpt::containers::circular_buffer< T >:
Inheritance graph

Public Member Functions

 circular_buffer (const size_t size)
 
void push (T d)
 Insert a copy of the given element in the buffer. More...
 
void push_ref (const T &d)
 Insert a reference of the given element in the buffer. More...
 
void push_many (T *array_elements, size_t count)
 Insert an array of elements in the buffer. More...
 
pop ()
 Retrieve an element from the buffer. More...
 
void pop (T &out_val)
 Retrieve an element from the buffer. More...
 
void pop_many (T *out_array, size_t count)
 Pop a number of elements into a user-provided array. More...
 
peek () const
 Peek (see without modifying) what is to be read from the buffer if pop() was to be called. More...
 
peek (size_t index) const
 Like peek(), but seeking ahead in the buffer (index=0 means the immediate next element, index=1 the following one, etc.) More...
 
void peek_many (T *out_array, size_t count) const
 Like peek(), for multiple elements, storing a number of elements into a user-provided array. More...
 
size_t size () const
 Return the number of elements available for read ("pop") in the buffer (this is NOT the maximum size of the internal buffer) More...
 
size_t capacity () const
 Return the maximum capacity of the buffer. More...
 
size_t available () const
 The maximum number of elements that can be written ("push") without rising an overflow error. More...
 
void clear ()
 Delete all the stored data, if any. More...
 

Private Attributes

std::vector< T > m_data
 
size_t m_size
 not "const" to allow copy/move = ops. More...
 
size_t m_next_read
 
size_t m_next_write
 

Constructor & Destructor Documentation

◆ circular_buffer()

template<typename T >
mrpt::containers::circular_buffer< T >::circular_buffer ( const size_t  size)
inline

Definition at line 34 of file circular_buffer.h.

Member Function Documentation

◆ available()

template<typename T >
size_t mrpt::containers::circular_buffer< T >::available ( ) const
inline

The maximum number of elements that can be written ("push") without rising an overflow error.

Definition at line 161 of file circular_buffer.h.

Referenced by mrpt::hwdrivers::CHokuyoURG::assureBufferHasBytes(), mrpt::hwdrivers::CGPSInterface::doProcess(), and mrpt::comms::CInterfaceFTDI::Read().

◆ capacity()

template<typename T >
size_t mrpt::containers::circular_buffer< T >::capacity ( ) const
inline

Return the maximum capacity of the buffer.

See also
size

Definition at line 157 of file circular_buffer.h.

Referenced by mrpt::hwdrivers::CHokuyoURG::assureBufferHasBytes(), mrpt::containers::circular_buffer< uint8_t >::available(), and TEST().

◆ clear()

template<typename T >
void mrpt::containers::circular_buffer< T >::clear ( )
inline

◆ peek() [1/2]

template<typename T >
T mrpt::containers::circular_buffer< T >::peek ( ) const
inline

Peek (see without modifying) what is to be read from the buffer if pop() was to be called.

Exceptions
std::out_of_rangeIf the buffer is empty.

Definition at line 109 of file circular_buffer.h.

Referenced by TEST().

◆ peek() [2/2]

template<typename T >
T mrpt::containers::circular_buffer< T >::peek ( size_t  index) const
inline

Like peek(), but seeking ahead in the buffer (index=0 means the immediate next element, index=1 the following one, etc.)

Exceptions
std::out_of_rangeIf trying to read passing the number of available elements.

Definition at line 119 of file circular_buffer.h.

◆ peek_many()

template<typename T >
void mrpt::containers::circular_buffer< T >::peek_many ( T *  out_array,
size_t  count 
) const
inline

Like peek(), for multiple elements, storing a number of elements into a user-provided array.

Exceptions
std::out_of_rangeIf the buffer has less elements than requested.

Definition at line 130 of file circular_buffer.h.

Referenced by TEST().

◆ pop() [1/2]

template<typename T >
T mrpt::containers::circular_buffer< T >::pop ( )
inline

Retrieve an element from the buffer.

Exceptions
std::out_of_rangeIf the buffer is empty.

Definition at line 76 of file circular_buffer.h.

Referenced by mrpt::hwdrivers::CGPSInterface::parseBuffer(), mrpt::containers::circular_buffer< uint8_t >::pop_many(), mrpt::hwdrivers::CHokuyoURG::receiveResponse(), and TEST().

◆ pop() [2/2]

template<typename T >
void mrpt::containers::circular_buffer< T >::pop ( T &  out_val)
inline

Retrieve an element from the buffer.

Exceptions
std::out_of_rangeIf the buffer is empty.

Definition at line 89 of file circular_buffer.h.

◆ pop_many()

template<typename T >
void mrpt::containers::circular_buffer< T >::pop_many ( T *  out_array,
size_t  count 
)
inline

Pop a number of elements into a user-provided array.

Exceptions
std::out_of_rangeIf the buffer has less elements than requested.

Definition at line 101 of file circular_buffer.h.

Referenced by mrpt::comms::CInterfaceFTDI::Read(), and TEST().

◆ push()

template<typename T >
void mrpt::containers::circular_buffer< T >::push ( d)
inline

Insert a copy of the given element in the buffer.

Exceptions
std::out_of_rangeIf the buffer run out of space.

Definition at line 43 of file circular_buffer.h.

Referenced by mrpt::containers::circular_buffer< uint8_t >::push_many(), and TEST().

◆ push_many()

template<typename T >
void mrpt::containers::circular_buffer< T >::push_many ( T *  array_elements,
size_t  count 
)
inline

Insert an array of elements in the buffer.

Exceptions
std::out_of_rangeIf the buffer run out of space.

Definition at line 68 of file circular_buffer.h.

Referenced by mrpt::hwdrivers::CHokuyoURG::assureBufferHasBytes(), mrpt::hwdrivers::CGPSInterface::doProcess(), mrpt::comms::CInterfaceFTDI::Read(), and TEST().

◆ push_ref()

template<typename T >
void mrpt::containers::circular_buffer< T >::push_ref ( const T &  d)
inline

Insert a reference of the given element in the buffer.

Exceptions
std::out_of_rangeIf the buffer run out of space.

Definition at line 56 of file circular_buffer.h.

◆ size()

template<typename T >
size_t mrpt::containers::circular_buffer< T >::size ( ) const
inline

Return the number of elements available for read ("pop") in the buffer (this is NOT the maximum size of the internal buffer)

See also
capacity

Definition at line 146 of file circular_buffer.h.

Referenced by mrpt::hwdrivers::CHokuyoURG::assureBufferHasBytes(), mrpt::containers::circular_buffer< uint8_t >::available(), mrpt::hwdrivers::CGPSInterface::parseBuffer(), mrpt::containers::circular_buffer< uint8_t >::peek(), mrpt::comms::CInterfaceFTDI::Read(), and TEST().

Member Data Documentation

◆ m_data

template<typename T >
std::vector<T> mrpt::containers::circular_buffer< T >::m_data
private

◆ m_next_read

template<typename T >
size_t mrpt::containers::circular_buffer< T >::m_next_read
private

◆ m_next_write

template<typename T >
size_t mrpt::containers::circular_buffer< T >::m_next_write
private

◆ m_size

template<typename T >
size_t mrpt::containers::circular_buffer< T >::m_size
private



Page generated by Doxygen 1.8.17 for MRPT 1.9.9 Git: ad3a9d8ae Tue May 1 23:10:22 2018 -0700 at miƩ 12 jul 2023 10:03:34 CEST