Direct-BT  2.3.1
Direct-BT - Direct Bluetooth Programming.
Public Types | Public Member Functions | Static Public Attributes | List of all members
jau::ringbuffer< Value_type, NullValue_type, Size_type, use_memcpy, use_memset > Class Template Reference

Ring buffer implementation, a.k.a circular buffer, exposing lock-free get*(..) and put*(..) methods. More...

#include <ringbuffer.hpp>

Inheritance diagram for jau::ringbuffer< Value_type, NullValue_type, Size_type, use_memcpy, use_memset >:
Collaboration diagram for jau::ringbuffer< Value_type, NullValue_type, Size_type, use_memcpy, use_memset >:

Public Types

typedef Value_type value_type
 
typedef value_typepointer
 
typedef const value_typeconst_pointer
 
typedef value_typereference
 
typedef const value_typeconst_reference
 
typedef Size_type size_type
 
typedef std::make_signed< size_type >::type difference_type
 

Public Member Functions

Size_type waitForElements (const Size_type min_count, const int timeoutMS) noexcept
 Blocks until at least count elements have been put for subsequent get() and getBlocking(). More...
 
Size_type waitForFreeSlots (const Size_type min_count, const int timeoutMS) noexcept
 Blocks until at least count free slots become available for subsequent put() and putBlocking(). More...
 
std::string toString () const noexcept
 Returns a short string representation incl. More...
 
void dump (FILE *stream, std::string prefix) const noexcept
 Debug functionality - Dumps the contents of the internal array. More...
 
 ringbuffer (const NullValue_type &nullelem_, const std::vector< Value_type > &copyFrom) noexcept
 Create a full ring buffer instance w/ the given array's net capacity and content. More...
 
 ringbuffer (const NullValue_type &nullelem_, const Value_type *copyFrom, const Size_type copyFromSize) noexcept
 
 ringbuffer (const NullValue_type &nullelem_, const Size_type capacity) noexcept
 Create an empty ring buffer instance w/ the given net capacity. More...
 
 ~ringbuffer () noexcept
 
 ringbuffer (const ringbuffer &_source) noexcept
 
ringbufferoperator= (const ringbuffer &_source) noexcept
 
 ringbuffer (ringbuffer &&o) noexcept=default
 
ringbufferoperator= (ringbuffer &&o) noexcept=default
 
Size_type capacity () const noexcept
 Returns the net capacity of this ring buffer. More...
 
void clear () noexcept
 Releasing all elements by assigning nullelem. More...
 
void reset (const Value_type *copyFrom, const Size_type copyFromCount) noexcept
 clear() all elements and add all copyFrom elements thereafter. More...
 
void reset (const std::vector< Value_type > &copyFrom) noexcept
 
Size_type getSize () const noexcept
 Returns the number of elements in this ring buffer. More...
 
Size_type getFreeSlots () const noexcept
 Returns the number of free slots available to put. More...
 
bool isEmpty () const noexcept
 Returns true if this ring buffer is empty, otherwise false. More...
 
bool isFull () const noexcept
 Returns true if this ring buffer is full, otherwise false. More...
 
Value_type peek () noexcept
 Peeks the next element at the read position w/o modifying pointer, nor blocking. More...
 
bool peek (Value_type &result) noexcept
 Peeks the next element at the read position w/o modifying pointer, nor blocking. More...
 
Value_type peekBlocking (const int timeoutMS=0) noexcept
 Peeks the next element at the read position w/o modifying pointer, but with blocking. More...
 
bool peekBlocking (Value_type &result, const int timeoutMS=0) noexcept
 Peeks the next element at the read position w/o modifying pointer, but with blocking. More...
 
Value_type get () noexcept
 Dequeues the oldest enqueued element if available, otherwise null. More...
 
bool get (Value_type &result) noexcept
 Dequeues the oldest enqueued element if available, otherwise null. More...
 
Value_type getBlocking (const int timeoutMS=0) noexcept
 Dequeues the oldest enqueued element. More...
 
bool getBlocking (Value_type &result, const int timeoutMS=0) noexcept
 Dequeues the oldest enqueued element. More...
 
Size_type get (Value_type *dest, const Size_type dest_len, const Size_type min_count) noexcept
 Dequeues the oldest enqueued min(dest_len, getSize()>=min_count) elements by copying them into the given consecutive 'dest' storage. More...
 
Size_type getBlocking (Value_type *dest, const Size_type dest_len, const Size_type min_count, const int timeoutMS=0) noexcept
 Dequeues the oldest enqueued min(dest_len, getSize()>=min_count) elements by copying them into the given consecutive 'dest' storage. More...
 
bool drop (const Size_type count) noexcept
 Drops. More...
 
bool dropBlocking (const Size_type count, const int timeoutMS=0) noexcept
 Drops. More...
 
bool put (Value_type &&e) noexcept
 Enqueues the given element by moving it into this ringbuffer storage. More...
 
bool putBlocking (Value_type &&e, const int timeoutMS=0) noexcept
 Enqueues the given element by moving it into this ringbuffer storage. More...
 
bool put (const Value_type &e) noexcept
 Enqueues the given element by copying it into this ringbuffer storage. More...
 
bool putBlocking (const Value_type &e, const int timeoutMS=0) noexcept
 Enqueues the given element by copying it into this ringbuffer storage. More...
 
bool put (const Value_type *first, const Value_type *last) noexcept
 Enqueues the given range of consecutive elements by copying it into this ringbuffer storage. More...
 
bool putBlocking (const Value_type *first, const Value_type *last, const int timeoutMS=0) noexcept
 Enqueues the given range of consecutive elementa by copying it into this ringbuffer storage. More...
 
void recapacity (const Size_type newCapacity)
 Resizes this ring buffer's capacity. More...
 

Static Public Attributes

constexpr static const bool uses_memcpy = use_memcpy
 
constexpr static const bool uses_memset = use_memset
 

Detailed Description

template<typename Value_type, typename NullValue_type, typename Size_type, bool use_memcpy = std::is_trivially_copyable_v<Value_type>, bool use_memset = std::is_integral_v<Value_type> && sizeof(Value_type)==1 && std::is_integral_v<NullValue_type> && sizeof(NullValue_type)==1>
class jau::ringbuffer< Value_type, NullValue_type, Size_type, use_memcpy, use_memset >

Ring buffer implementation, a.k.a circular buffer, exposing lock-free get*(..) and put*(..) methods.

Implementation utilizes the Always Keep One Slot Open, hence implementation maintains an internal array of capacity plus one!

Implementation is thread safe if:

Following methods acquire the global multi-read and -write mutex:

Characteristics:

EmptywritePos == readPossize == 0
FullwritePos == readPos - 1size == capacity
Empty [RW][][ ][ ][ ][ ][ ][ ] ; W==R
Avail [ ][ ][R][.][.][.][.][W] ; W > R
Avail [.][.][.][W][ ][ ][R][.] ; W <  R - 1
Full  [.][.][.][.][.][W][R][.] ; W==R-1

See also:


We would like to pass NullValue_type nullelem as a non-type template parameter of type NullValue_type, a potential Class.
However, this is only allowed in C++20 and we use C++17 for now.
Hence we have to pass NullValue_type nullelem in the constructor.
See also
jau::sc_atomic_critical
Examples
test_lfringbuffer01.cpp, and test_lfringbuffer11.cpp.

Definition at line 115 of file ringbuffer.hpp.

Member Typedef Documentation

◆ const_pointer

template<typename Value_type , typename NullValue_type , typename Size_type , bool use_memcpy = std::is_trivially_copyable_v<Value_type>, bool use_memset = std::is_integral_v<Value_type> && sizeof(Value_type)==1 && std::is_integral_v<NullValue_type> && sizeof(NullValue_type)==1>
typedef const value_type* jau::ringbuffer< Value_type, NullValue_type, Size_type, use_memcpy, use_memset >::const_pointer

Definition at line 124 of file ringbuffer.hpp.

◆ const_reference

template<typename Value_type , typename NullValue_type , typename Size_type , bool use_memcpy = std::is_trivially_copyable_v<Value_type>, bool use_memset = std::is_integral_v<Value_type> && sizeof(Value_type)==1 && std::is_integral_v<NullValue_type> && sizeof(NullValue_type)==1>
typedef const value_type& jau::ringbuffer< Value_type, NullValue_type, Size_type, use_memcpy, use_memset >::const_reference

Definition at line 126 of file ringbuffer.hpp.

◆ difference_type

template<typename Value_type , typename NullValue_type , typename Size_type , bool use_memcpy = std::is_trivially_copyable_v<Value_type>, bool use_memset = std::is_integral_v<Value_type> && sizeof(Value_type)==1 && std::is_integral_v<NullValue_type> && sizeof(NullValue_type)==1>
typedef std::make_signed<size_type>::type jau::ringbuffer< Value_type, NullValue_type, Size_type, use_memcpy, use_memset >::difference_type

Definition at line 128 of file ringbuffer.hpp.

◆ pointer

template<typename Value_type , typename NullValue_type , typename Size_type , bool use_memcpy = std::is_trivially_copyable_v<Value_type>, bool use_memset = std::is_integral_v<Value_type> && sizeof(Value_type)==1 && std::is_integral_v<NullValue_type> && sizeof(NullValue_type)==1>
typedef value_type* jau::ringbuffer< Value_type, NullValue_type, Size_type, use_memcpy, use_memset >::pointer

Definition at line 123 of file ringbuffer.hpp.

◆ reference

template<typename Value_type , typename NullValue_type , typename Size_type , bool use_memcpy = std::is_trivially_copyable_v<Value_type>, bool use_memset = std::is_integral_v<Value_type> && sizeof(Value_type)==1 && std::is_integral_v<NullValue_type> && sizeof(NullValue_type)==1>
typedef value_type& jau::ringbuffer< Value_type, NullValue_type, Size_type, use_memcpy, use_memset >::reference

Definition at line 125 of file ringbuffer.hpp.

◆ size_type

template<typename Value_type , typename NullValue_type , typename Size_type , bool use_memcpy = std::is_trivially_copyable_v<Value_type>, bool use_memset = std::is_integral_v<Value_type> && sizeof(Value_type)==1 && std::is_integral_v<NullValue_type> && sizeof(NullValue_type)==1>
typedef Size_type jau::ringbuffer< Value_type, NullValue_type, Size_type, use_memcpy, use_memset >::size_type

Definition at line 127 of file ringbuffer.hpp.

◆ value_type

template<typename Value_type , typename NullValue_type , typename Size_type , bool use_memcpy = std::is_trivially_copyable_v<Value_type>, bool use_memset = std::is_integral_v<Value_type> && sizeof(Value_type)==1 && std::is_integral_v<NullValue_type> && sizeof(NullValue_type)==1>
typedef Value_type jau::ringbuffer< Value_type, NullValue_type, Size_type, use_memcpy, use_memset >::value_type

Definition at line 122 of file ringbuffer.hpp.

Constructor & Destructor Documentation

◆ ringbuffer() [1/5]

template<typename Value_type , typename NullValue_type , typename Size_type , bool use_memcpy = std::is_trivially_copyable_v<Value_type>, bool use_memset = std::is_integral_v<Value_type> && sizeof(Value_type)==1 && std::is_integral_v<NullValue_type> && sizeof(NullValue_type)==1>
jau::ringbuffer< Value_type, NullValue_type, Size_type, use_memcpy, use_memset >::ringbuffer ( const NullValue_type &  nullelem_,
const std::vector< Value_type > &  copyFrom 
)
inlinenoexcept

Create a full ring buffer instance w/ the given array's net capacity and content.

Example for a 10 element Integer array:

 Integer[] source = new Integer[10];
 // fill source with content ..
 ringbuffer<Integer> rb = new ringbuffer<Integer>(source);

isFull() returns true on the newly created full ring buffer.

Implementation will allocate an internal array with size of array copyFrom plus one, and copy all elements from array copyFrom into the internal array.

Parameters
nullelemThe null value used to zero removed elements on get*(..) and clear()
copyFrommandatory source array determining ring buffer's net capacity() and initial content.
Exceptions
IllegalArgumentExceptionif copyFrom is nullptr

Definition at line 799 of file ringbuffer.hpp.

◆ ringbuffer() [2/5]

template<typename Value_type , typename NullValue_type , typename Size_type , bool use_memcpy = std::is_trivially_copyable_v<Value_type>, bool use_memset = std::is_integral_v<Value_type> && sizeof(Value_type)==1 && std::is_integral_v<NullValue_type> && sizeof(NullValue_type)==1>
jau::ringbuffer< Value_type, NullValue_type, Size_type, use_memcpy, use_memset >::ringbuffer ( const NullValue_type &  nullelem_,
const Value_type *  copyFrom,
const Size_type  copyFromSize 
)
inlinenoexcept
Parameters
nullelemThe null value used to zero removed elements on get*(..) and clear()
copyFrom
copyFromSize

Definition at line 812 of file ringbuffer.hpp.

◆ ringbuffer() [3/5]

template<typename Value_type , typename NullValue_type , typename Size_type , bool use_memcpy = std::is_trivially_copyable_v<Value_type>, bool use_memset = std::is_integral_v<Value_type> && sizeof(Value_type)==1 && std::is_integral_v<NullValue_type> && sizeof(NullValue_type)==1>
jau::ringbuffer< Value_type, NullValue_type, Size_type, use_memcpy, use_memset >::ringbuffer ( const NullValue_type &  nullelem_,
const Size_type  capacity 
)
inlinenoexcept

Create an empty ring buffer instance w/ the given net capacity.

Example for a 10 element Integer array:

 ringbuffer<Integer> rb = new ringbuffer<Integer>(10, Integer[].class);

isEmpty() returns true on the newly created empty ring buffer.

Implementation will allocate an internal array of size capacity plus one.

Parameters
nullelemThe null value used to zero removed elements on get*(..) and clear()
arrayTypethe array type of the created empty internal array.
capacitythe initial net capacity of the ring buffer

Definition at line 838 of file ringbuffer.hpp.

◆ ~ringbuffer()

template<typename Value_type , typename NullValue_type , typename Size_type , bool use_memcpy = std::is_trivially_copyable_v<Value_type>, bool use_memset = std::is_integral_v<Value_type> && sizeof(Value_type)==1 && std::is_integral_v<NullValue_type> && sizeof(NullValue_type)==1>
jau::ringbuffer< Value_type, NullValue_type, Size_type, use_memcpy, use_memset >::~ringbuffer ( )
inlinenoexcept

Definition at line 845 of file ringbuffer.hpp.

◆ ringbuffer() [4/5]

template<typename Value_type , typename NullValue_type , typename Size_type , bool use_memcpy = std::is_trivially_copyable_v<Value_type>, bool use_memset = std::is_integral_v<Value_type> && sizeof(Value_type)==1 && std::is_integral_v<NullValue_type> && sizeof(NullValue_type)==1>
jau::ringbuffer< Value_type, NullValue_type, Size_type, use_memcpy, use_memset >::ringbuffer ( const ringbuffer< Value_type, NullValue_type, Size_type, use_memcpy, use_memset > &  _source)
inlinenoexcept

Definition at line 852 of file ringbuffer.hpp.

◆ ringbuffer() [5/5]

template<typename Value_type , typename NullValue_type , typename Size_type , bool use_memcpy = std::is_trivially_copyable_v<Value_type>, bool use_memset = std::is_integral_v<Value_type> && sizeof(Value_type)==1 && std::is_integral_v<NullValue_type> && sizeof(NullValue_type)==1>
jau::ringbuffer< Value_type, NullValue_type, Size_type, use_memcpy, use_memset >::ringbuffer ( ringbuffer< Value_type, NullValue_type, Size_type, use_memcpy, use_memset > &&  o)
defaultnoexcept

Member Function Documentation

◆ capacity()

template<typename Value_type , typename NullValue_type , typename Size_type , bool use_memcpy = std::is_trivially_copyable_v<Value_type>, bool use_memset = std::is_integral_v<Value_type> && sizeof(Value_type)==1 && std::is_integral_v<NullValue_type> && sizeof(NullValue_type)==1>
Size_type jau::ringbuffer< Value_type, NullValue_type, Size_type, use_memcpy, use_memset >::capacity ( ) const
inlinenoexcept

Returns the net capacity of this ring buffer.

Examples
test_lfringbuffer01.cpp.

Definition at line 891 of file ringbuffer.hpp.

◆ clear()

template<typename Value_type , typename NullValue_type , typename Size_type , bool use_memcpy = std::is_trivially_copyable_v<Value_type>, bool use_memset = std::is_integral_v<Value_type> && sizeof(Value_type)==1 && std::is_integral_v<NullValue_type> && sizeof(NullValue_type)==1>
void jau::ringbuffer< Value_type, NullValue_type, Size_type, use_memcpy, use_memset >::clear ( )
inlinenoexcept

Releasing all elements by assigning nullelem.

isEmpty() will return true and getSize() will return 0 after calling this method.

Examples
test_lfringbuffer01.cpp.

Definition at line 900 of file ringbuffer.hpp.

Here is the caller graph for this function:

◆ drop()

template<typename Value_type , typename NullValue_type , typename Size_type , bool use_memcpy = std::is_trivially_copyable_v<Value_type>, bool use_memset = std::is_integral_v<Value_type> && sizeof(Value_type)==1 && std::is_integral_v<NullValue_type> && sizeof(NullValue_type)==1>
bool jau::ringbuffer< Value_type, NullValue_type, Size_type, use_memcpy, use_memset >::drop ( const Size_type  count)
inlinenoexcept

Drops.

count

oldest enqueued elements.

Method is non blocking and returns immediately;.

Parameters
countnumber of elements to drop from ringbuffer.
Returns
true if successful, otherwise false
Examples
test_lfringbuffer01.cpp.

Definition at line 1112 of file ringbuffer.hpp.

Here is the caller graph for this function:

◆ dropBlocking()

template<typename Value_type , typename NullValue_type , typename Size_type , bool use_memcpy = std::is_trivially_copyable_v<Value_type>, bool use_memset = std::is_integral_v<Value_type> && sizeof(Value_type)==1 && std::is_integral_v<NullValue_type> && sizeof(NullValue_type)==1>
bool jau::ringbuffer< Value_type, NullValue_type, Size_type, use_memcpy, use_memset >::dropBlocking ( const Size_type  count,
const int  timeoutMS = 0 
)
inlinenoexcept

Drops.

count

oldest enqueued elements.

timeoutMS defaults to zero, i.e. infinitive blocking until an element available via put.
Otherwise this methods blocks for the given milliseconds.

Parameters
countnumber of elements to drop from ringbuffer.
Returns
true if successful, otherwise false

Definition at line 1126 of file ringbuffer.hpp.

◆ dump()

template<typename Value_type , typename NullValue_type , typename Size_type , bool use_memcpy = std::is_trivially_copyable_v<Value_type>, bool use_memset = std::is_integral_v<Value_type> && sizeof(Value_type)==1 && std::is_integral_v<NullValue_type> && sizeof(NullValue_type)==1>
void jau::ringbuffer< Value_type, NullValue_type, Size_type, use_memcpy, use_memset >::dump ( FILE *  stream,
std::string  prefix 
) const
inlinenoexcept

Debug functionality - Dumps the contents of the internal array.

Definition at line 766 of file ringbuffer.hpp.

◆ get() [1/3]

template<typename Value_type , typename NullValue_type , typename Size_type , bool use_memcpy = std::is_trivially_copyable_v<Value_type>, bool use_memset = std::is_integral_v<Value_type> && sizeof(Value_type)==1 && std::is_integral_v<NullValue_type> && sizeof(NullValue_type)==1>
Value_type jau::ringbuffer< Value_type, NullValue_type, Size_type, use_memcpy, use_memset >::get ( )
inlinenoexcept

Dequeues the oldest enqueued element if available, otherwise null.

The returned ring buffer slot will be set to nullelem to release the reference and move ownership to the caller.

Method is non blocking and returns immediately;.

Returns
the oldest put element if available, otherwise nullelem.
Examples
test_lfringbuffer01.cpp.

Definition at line 1004 of file ringbuffer.hpp.

◆ get() [2/3]

template<typename Value_type , typename NullValue_type , typename Size_type , bool use_memcpy = std::is_trivially_copyable_v<Value_type>, bool use_memset = std::is_integral_v<Value_type> && sizeof(Value_type)==1 && std::is_integral_v<NullValue_type> && sizeof(NullValue_type)==1>
bool jau::ringbuffer< Value_type, NullValue_type, Size_type, use_memcpy, use_memset >::get ( Value_type &  result)
inlinenoexcept

Dequeues the oldest enqueued element if available, otherwise null.

The returned ring buffer slot will be set to nullelem to release the reference and move ownership to the caller.

Method is non blocking and returns immediately;.

Parameters
resultstorage for the resulting value if successful, otherwise nullelem if empty.
Returns
true if successful, otherwise false.

Definition at line 1021 of file ringbuffer.hpp.

◆ get() [3/3]

template<typename Value_type , typename NullValue_type , typename Size_type , bool use_memcpy = std::is_trivially_copyable_v<Value_type>, bool use_memset = std::is_integral_v<Value_type> && sizeof(Value_type)==1 && std::is_integral_v<NullValue_type> && sizeof(NullValue_type)==1>
Size_type jau::ringbuffer< Value_type, NullValue_type, Size_type, use_memcpy, use_memset >::get ( Value_type *  dest,
const Size_type  dest_len,
const Size_type  min_count 
)
inlinenoexcept

Dequeues the oldest enqueued min(dest_len, getSize()>=min_count) elements by copying them into the given consecutive 'dest' storage.

The returned ring buffer slot will be set to nullelem to release the reference and move ownership to the caller.

Method is non blocking and returns immediately;.

Parameters
destpointer to first storage element of count consecutive elements.
dest_lennumber of consecutive elements in dest and maximum number of elements to get
min_countminimum number of consecutive elements to get
Returns
actual number of elements received

Definition at line 1079 of file ringbuffer.hpp.

◆ getBlocking() [1/3]

template<typename Value_type , typename NullValue_type , typename Size_type , bool use_memcpy = std::is_trivially_copyable_v<Value_type>, bool use_memset = std::is_integral_v<Value_type> && sizeof(Value_type)==1 && std::is_integral_v<NullValue_type> && sizeof(NullValue_type)==1>
Value_type jau::ringbuffer< Value_type, NullValue_type, Size_type, use_memcpy, use_memset >::getBlocking ( const int  timeoutMS = 0)
inlinenoexcept

Dequeues the oldest enqueued element.

The returned ring buffer slot will be set to nullelem to release the reference and move ownership to the caller.

timeoutMS defaults to zero, i.e. infinitive blocking until an element available via put.
Otherwise this methods blocks for the given milliseconds.

Returns
the oldest put element or nullelem if timeout occurred.
Examples
test_lfringbuffer11.cpp.

Definition at line 1040 of file ringbuffer.hpp.

◆ getBlocking() [2/3]

template<typename Value_type , typename NullValue_type , typename Size_type , bool use_memcpy = std::is_trivially_copyable_v<Value_type>, bool use_memset = std::is_integral_v<Value_type> && sizeof(Value_type)==1 && std::is_integral_v<NullValue_type> && sizeof(NullValue_type)==1>
bool jau::ringbuffer< Value_type, NullValue_type, Size_type, use_memcpy, use_memset >::getBlocking ( Value_type &  result,
const int  timeoutMS = 0 
)
inlinenoexcept

Dequeues the oldest enqueued element.

The returned ring buffer slot will be set to nullelem to release the reference and move ownership to the caller.

timeoutMS defaults to zero, i.e. infinitive blocking until an element available via put.
Otherwise this methods blocks for the given milliseconds.

Parameters
resultstorage for the resulting value if successful, otherwise nullelem if empty.
Returns
true if successful, otherwise false.

Definition at line 1059 of file ringbuffer.hpp.

◆ getBlocking() [3/3]

template<typename Value_type , typename NullValue_type , typename Size_type , bool use_memcpy = std::is_trivially_copyable_v<Value_type>, bool use_memset = std::is_integral_v<Value_type> && sizeof(Value_type)==1 && std::is_integral_v<NullValue_type> && sizeof(NullValue_type)==1>
Size_type jau::ringbuffer< Value_type, NullValue_type, Size_type, use_memcpy, use_memset >::getBlocking ( Value_type *  dest,
const Size_type  dest_len,
const Size_type  min_count,
const int  timeoutMS = 0 
)
inlinenoexcept

Dequeues the oldest enqueued min(dest_len, getSize()>=min_count) elements by copying them into the given consecutive 'dest' storage.

The returned ring buffer slot will be set to nullelem to release the reference and move ownership to the caller.

timeoutMS defaults to zero, i.e. infinitive blocking until an element available via put.
Otherwise this methods blocks for the given milliseconds.

Parameters
destpointer to first storage element of count consecutive elements.
dest_lennumber of consecutive elements in dest and maximum number of elements to get
min_countminimum number of consecutive elements to get
timeoutMS
Returns
actual number of elements received

Definition at line 1100 of file ringbuffer.hpp.

◆ getFreeSlots()

template<typename Value_type , typename NullValue_type , typename Size_type , bool use_memcpy = std::is_trivially_copyable_v<Value_type>, bool use_memset = std::is_integral_v<Value_type> && sizeof(Value_type)==1 && std::is_integral_v<NullValue_type> && sizeof(NullValue_type)==1>
Size_type jau::ringbuffer< Value_type, NullValue_type, Size_type, use_memcpy, use_memset >::getFreeSlots ( ) const
inlinenoexcept

Returns the number of free slots available to put.


Examples
test_lfringbuffer01.cpp.

Definition at line 935 of file ringbuffer.hpp.

Here is the caller graph for this function:

◆ getSize()

template<typename Value_type , typename NullValue_type , typename Size_type , bool use_memcpy = std::is_trivially_copyable_v<Value_type>, bool use_memset = std::is_integral_v<Value_type> && sizeof(Value_type)==1 && std::is_integral_v<NullValue_type> && sizeof(NullValue_type)==1>
Size_type jau::ringbuffer< Value_type, NullValue_type, Size_type, use_memcpy, use_memset >::getSize ( ) const
inlinenoexcept

Returns the number of elements in this ring buffer.

Examples
test_lfringbuffer01.cpp, and test_lfringbuffer11.cpp.

Definition at line 926 of file ringbuffer.hpp.

Here is the caller graph for this function:

◆ isEmpty()

template<typename Value_type , typename NullValue_type , typename Size_type , bool use_memcpy = std::is_trivially_copyable_v<Value_type>, bool use_memset = std::is_integral_v<Value_type> && sizeof(Value_type)==1 && std::is_integral_v<NullValue_type> && sizeof(NullValue_type)==1>
bool jau::ringbuffer< Value_type, NullValue_type, Size_type, use_memcpy, use_memset >::isEmpty ( ) const
inlinenoexcept

Returns true if this ring buffer is empty, otherwise false.

Examples
test_lfringbuffer01.cpp, and test_lfringbuffer11.cpp.

Definition at line 938 of file ringbuffer.hpp.

Here is the caller graph for this function:

◆ isFull()

template<typename Value_type , typename NullValue_type , typename Size_type , bool use_memcpy = std::is_trivially_copyable_v<Value_type>, bool use_memset = std::is_integral_v<Value_type> && sizeof(Value_type)==1 && std::is_integral_v<NullValue_type> && sizeof(NullValue_type)==1>
bool jau::ringbuffer< Value_type, NullValue_type, Size_type, use_memcpy, use_memset >::isFull ( ) const
inlinenoexcept

Returns true if this ring buffer is full, otherwise false.

Examples
test_lfringbuffer01.cpp, and test_lfringbuffer11.cpp.

Definition at line 941 of file ringbuffer.hpp.

Here is the caller graph for this function:

◆ operator=() [1/2]

template<typename Value_type , typename NullValue_type , typename Size_type , bool use_memcpy = std::is_trivially_copyable_v<Value_type>, bool use_memset = std::is_integral_v<Value_type> && sizeof(Value_type)==1 && std::is_integral_v<NullValue_type> && sizeof(NullValue_type)==1>
ringbuffer& jau::ringbuffer< Value_type, NullValue_type, Size_type, use_memcpy, use_memset >::operator= ( const ringbuffer< Value_type, NullValue_type, Size_type, use_memcpy, use_memset > &  _source)
inlinenoexcept

Definition at line 864 of file ringbuffer.hpp.

◆ operator=() [2/2]

template<typename Value_type , typename NullValue_type , typename Size_type , bool use_memcpy = std::is_trivially_copyable_v<Value_type>, bool use_memset = std::is_integral_v<Value_type> && sizeof(Value_type)==1 && std::is_integral_v<NullValue_type> && sizeof(NullValue_type)==1>
ringbuffer& jau::ringbuffer< Value_type, NullValue_type, Size_type, use_memcpy, use_memset >::operator= ( ringbuffer< Value_type, NullValue_type, Size_type, use_memcpy, use_memset > &&  o)
defaultnoexcept

◆ peek() [1/2]

template<typename Value_type , typename NullValue_type , typename Size_type , bool use_memcpy = std::is_trivially_copyable_v<Value_type>, bool use_memset = std::is_integral_v<Value_type> && sizeof(Value_type)==1 && std::is_integral_v<NullValue_type> && sizeof(NullValue_type)==1>
Value_type jau::ringbuffer< Value_type, NullValue_type, Size_type, use_memcpy, use_memset >::peek ( )
inlinenoexcept

Peeks the next element at the read position w/o modifying pointer, nor blocking.

Returns
nullelem if empty, otherwise the element which would be read next.

Definition at line 947 of file ringbuffer.hpp.

◆ peek() [2/2]

template<typename Value_type , typename NullValue_type , typename Size_type , bool use_memcpy = std::is_trivially_copyable_v<Value_type>, bool use_memset = std::is_integral_v<Value_type> && sizeof(Value_type)==1 && std::is_integral_v<NullValue_type> && sizeof(NullValue_type)==1>
bool jau::ringbuffer< Value_type, NullValue_type, Size_type, use_memcpy, use_memset >::peek ( Value_type &  result)
inlinenoexcept

Peeks the next element at the read position w/o modifying pointer, nor blocking.

Parameters
resultstorage for the resulting value if successful, otherwise nullelem if empty.
Returns
true if successful, otherwise false.

Definition at line 957 of file ringbuffer.hpp.

◆ peekBlocking() [1/2]

template<typename Value_type , typename NullValue_type , typename Size_type , bool use_memcpy = std::is_trivially_copyable_v<Value_type>, bool use_memset = std::is_integral_v<Value_type> && sizeof(Value_type)==1 && std::is_integral_v<NullValue_type> && sizeof(NullValue_type)==1>
Value_type jau::ringbuffer< Value_type, NullValue_type, Size_type, use_memcpy, use_memset >::peekBlocking ( const int  timeoutMS = 0)
inlinenoexcept

Peeks the next element at the read position w/o modifying pointer, but with blocking.

timeoutMS defaults to zero, i.e. infinitive blocking until an element available via put.
Otherwise this methods blocks for the given milliseconds.

Returns
nullelem if empty or timeout occurred, otherwise the element which would be read next.

Definition at line 972 of file ringbuffer.hpp.

◆ peekBlocking() [2/2]

template<typename Value_type , typename NullValue_type , typename Size_type , bool use_memcpy = std::is_trivially_copyable_v<Value_type>, bool use_memset = std::is_integral_v<Value_type> && sizeof(Value_type)==1 && std::is_integral_v<NullValue_type> && sizeof(NullValue_type)==1>
bool jau::ringbuffer< Value_type, NullValue_type, Size_type, use_memcpy, use_memset >::peekBlocking ( Value_type &  result,
const int  timeoutMS = 0 
)
inlinenoexcept

Peeks the next element at the read position w/o modifying pointer, but with blocking.

timeoutMS defaults to zero, i.e. infinitive blocking until an element available via put.
Otherwise this methods blocks for the given milliseconds.

Parameters
resultstorage for the resulting value if successful, otherwise nullelem if empty.
Returns
true if successful, otherwise false.

Definition at line 987 of file ringbuffer.hpp.

◆ put() [1/3]

template<typename Value_type , typename NullValue_type , typename Size_type , bool use_memcpy = std::is_trivially_copyable_v<Value_type>, bool use_memset = std::is_integral_v<Value_type> && sizeof(Value_type)==1 && std::is_integral_v<NullValue_type> && sizeof(NullValue_type)==1>
bool jau::ringbuffer< Value_type, NullValue_type, Size_type, use_memcpy, use_memset >::put ( const Value_type &  e)
inlinenoexcept

Enqueues the given element by copying it into this ringbuffer storage.

Returns true if successful, otherwise false in case buffer is full.

Method is non blocking and returns immediately;.

Returns
true if successful, otherwise false

Definition at line 1167 of file ringbuffer.hpp.

◆ put() [2/3]

template<typename Value_type , typename NullValue_type , typename Size_type , bool use_memcpy = std::is_trivially_copyable_v<Value_type>, bool use_memset = std::is_integral_v<Value_type> && sizeof(Value_type)==1 && std::is_integral_v<NullValue_type> && sizeof(NullValue_type)==1>
bool jau::ringbuffer< Value_type, NullValue_type, Size_type, use_memcpy, use_memset >::put ( const Value_type *  first,
const Value_type *  last 
)
inlinenoexcept

Enqueues the given range of consecutive elements by copying it into this ringbuffer storage.

Returns true if successful, otherwise false in case buffer is full.

Method is non blocking and returns immediately;.

Parameters
firstpointer to first consecutive element to range of value_type [first, last)
lastpointer to last consecutive element to range of value_type [first, last)
Returns
true if successful, otherwise false

Definition at line 1196 of file ringbuffer.hpp.

◆ put() [3/3]

template<typename Value_type , typename NullValue_type , typename Size_type , bool use_memcpy = std::is_trivially_copyable_v<Value_type>, bool use_memset = std::is_integral_v<Value_type> && sizeof(Value_type)==1 && std::is_integral_v<NullValue_type> && sizeof(NullValue_type)==1>
bool jau::ringbuffer< Value_type, NullValue_type, Size_type, use_memcpy, use_memset >::put ( Value_type &&  e)
inlinenoexcept

Enqueues the given element by moving it into this ringbuffer storage.

Returns true if successful, otherwise false in case buffer is full.

Method is non blocking and returns immediately;.

Returns
true if successful, otherwise false
Examples
test_lfringbuffer01.cpp, and test_lfringbuffer11.cpp.

Definition at line 1140 of file ringbuffer.hpp.

Here is the caller graph for this function:

◆ putBlocking() [1/3]

template<typename Value_type , typename NullValue_type , typename Size_type , bool use_memcpy = std::is_trivially_copyable_v<Value_type>, bool use_memset = std::is_integral_v<Value_type> && sizeof(Value_type)==1 && std::is_integral_v<NullValue_type> && sizeof(NullValue_type)==1>
bool jau::ringbuffer< Value_type, NullValue_type, Size_type, use_memcpy, use_memset >::putBlocking ( const Value_type &  e,
const int  timeoutMS = 0 
)
inlinenoexcept

Enqueues the given element by copying it into this ringbuffer storage.

timeoutMS defaults to zero, i.e. infinitive blocking until a free slot becomes available via get.
Otherwise this methods blocks for the given milliseconds.

Returns
true if successful, otherwise false in case timeout occurred or otherwise.

Definition at line 1180 of file ringbuffer.hpp.

◆ putBlocking() [2/3]

template<typename Value_type , typename NullValue_type , typename Size_type , bool use_memcpy = std::is_trivially_copyable_v<Value_type>, bool use_memset = std::is_integral_v<Value_type> && sizeof(Value_type)==1 && std::is_integral_v<NullValue_type> && sizeof(NullValue_type)==1>
bool jau::ringbuffer< Value_type, NullValue_type, Size_type, use_memcpy, use_memset >::putBlocking ( const Value_type *  first,
const Value_type *  last,
const int  timeoutMS = 0 
)
inlinenoexcept

Enqueues the given range of consecutive elementa by copying it into this ringbuffer storage.

timeoutMS defaults to zero, i.e. infinitive blocking until a free slot becomes available via get.
Otherwise this methods blocks for the given milliseconds.

Parameters
firstpointer to first consecutive element to range of value_type [first, last)
lastpointer to last consecutive element to range of value_type [first, last)
timeoutMS
Returns
true if successful, otherwise false in case timeout occurred or otherwise.

Definition at line 1212 of file ringbuffer.hpp.

◆ putBlocking() [3/3]

template<typename Value_type , typename NullValue_type , typename Size_type , bool use_memcpy = std::is_trivially_copyable_v<Value_type>, bool use_memset = std::is_integral_v<Value_type> && sizeof(Value_type)==1 && std::is_integral_v<NullValue_type> && sizeof(NullValue_type)==1>
bool jau::ringbuffer< Value_type, NullValue_type, Size_type, use_memcpy, use_memset >::putBlocking ( Value_type &&  e,
const int  timeoutMS = 0 
)
inlinenoexcept

Enqueues the given element by moving it into this ringbuffer storage.

timeoutMS defaults to zero, i.e. infinitive blocking until a free slot becomes available via get.
Otherwise this methods blocks for the given milliseconds.

Returns
true if successful, otherwise false in case timeout occurred or otherwise.
Examples
test_lfringbuffer11.cpp.

Definition at line 1153 of file ringbuffer.hpp.

◆ recapacity()

template<typename Value_type , typename NullValue_type , typename Size_type , bool use_memcpy = std::is_trivially_copyable_v<Value_type>, bool use_memset = std::is_integral_v<Value_type> && sizeof(Value_type)==1 && std::is_integral_v<NullValue_type> && sizeof(NullValue_type)==1>
void jau::ringbuffer< Value_type, NullValue_type, Size_type, use_memcpy, use_memset >::recapacity ( const Size_type  newCapacity)
inline

Resizes this ring buffer's capacity.

New capacity must be greater than current size.

Examples
test_lfringbuffer01.cpp.

Definition at line 1222 of file ringbuffer.hpp.

◆ reset() [1/2]

template<typename Value_type , typename NullValue_type , typename Size_type , bool use_memcpy = std::is_trivially_copyable_v<Value_type>, bool use_memset = std::is_integral_v<Value_type> && sizeof(Value_type)==1 && std::is_integral_v<NullValue_type> && sizeof(NullValue_type)==1>
void jau::ringbuffer< Value_type, NullValue_type, Size_type, use_memcpy, use_memset >::reset ( const std::vector< Value_type > &  copyFrom)
inlinenoexcept

Definition at line 918 of file ringbuffer.hpp.

◆ reset() [2/2]

template<typename Value_type , typename NullValue_type , typename Size_type , bool use_memcpy = std::is_trivially_copyable_v<Value_type>, bool use_memset = std::is_integral_v<Value_type> && sizeof(Value_type)==1 && std::is_integral_v<NullValue_type> && sizeof(NullValue_type)==1>
void jau::ringbuffer< Value_type, NullValue_type, Size_type, use_memcpy, use_memset >::reset ( const Value_type *  copyFrom,
const Size_type  copyFromCount 
)
inlinenoexcept

clear() all elements and add all copyFrom elements thereafter.

Parameters
copyFromMandatory array w/ length capacity() to be copied into the internal array.
Examples
test_lfringbuffer01.cpp.

Definition at line 911 of file ringbuffer.hpp.

Here is the caller graph for this function:

◆ toString()

template<typename Value_type , typename NullValue_type , typename Size_type , bool use_memcpy = std::is_trivially_copyable_v<Value_type>, bool use_memset = std::is_integral_v<Value_type> && sizeof(Value_type)==1 && std::is_integral_v<NullValue_type> && sizeof(NullValue_type)==1>
std::string jau::ringbuffer< Value_type, NullValue_type, Size_type, use_memcpy, use_memset >::toString ( ) const
inlinenoexcept

Returns a short string representation incl.

size/capacity and internal r/w index (impl. dependent).

Examples
test_lfringbuffer01.cpp, and test_lfringbuffer11.cpp.

Definition at line 758 of file ringbuffer.hpp.

Here is the caller graph for this function:

◆ waitForElements()

template<typename Value_type , typename NullValue_type , typename Size_type , bool use_memcpy = std::is_trivially_copyable_v<Value_type>, bool use_memset = std::is_integral_v<Value_type> && sizeof(Value_type)==1 && std::is_integral_v<NullValue_type> && sizeof(NullValue_type)==1>
Size_type jau::ringbuffer< Value_type, NullValue_type, Size_type, use_memcpy, use_memset >::waitForElements ( const Size_type  min_count,
const int  timeoutMS 
)
inlinenoexcept

Blocks until at least count elements have been put for subsequent get() and getBlocking().

Parameters
min_countminimum number of put slots
timeoutMS
Returns
the number of put elements, available for get() and getBlocking()

Definition at line 701 of file ringbuffer.hpp.

◆ waitForFreeSlots()

template<typename Value_type , typename NullValue_type , typename Size_type , bool use_memcpy = std::is_trivially_copyable_v<Value_type>, bool use_memset = std::is_integral_v<Value_type> && sizeof(Value_type)==1 && std::is_integral_v<NullValue_type> && sizeof(NullValue_type)==1>
Size_type jau::ringbuffer< Value_type, NullValue_type, Size_type, use_memcpy, use_memset >::waitForFreeSlots ( const Size_type  min_count,
const int  timeoutMS 
)
inlinenoexcept

Blocks until at least count free slots become available for subsequent put() and putBlocking().

Parameters
min_countminimum number of free slots
timeoutMS
Returns
the number of free slots, available for put() and putBlocking()

Definition at line 733 of file ringbuffer.hpp.

Member Data Documentation

◆ uses_memcpy

template<typename Value_type , typename NullValue_type , typename Size_type , bool use_memcpy = std::is_trivially_copyable_v<Value_type>, bool use_memset = std::is_integral_v<Value_type> && sizeof(Value_type)==1 && std::is_integral_v<NullValue_type> && sizeof(NullValue_type)==1>
constexpr static const bool jau::ringbuffer< Value_type, NullValue_type, Size_type, use_memcpy, use_memset >::uses_memcpy = use_memcpy
staticconstexpr
Examples
test_lfringbuffer01.cpp.

Definition at line 117 of file ringbuffer.hpp.

◆ uses_memset

template<typename Value_type , typename NullValue_type , typename Size_type , bool use_memcpy = std::is_trivially_copyable_v<Value_type>, bool use_memset = std::is_integral_v<Value_type> && sizeof(Value_type)==1 && std::is_integral_v<NullValue_type> && sizeof(NullValue_type)==1>
constexpr static const bool jau::ringbuffer< Value_type, NullValue_type, Size_type, use_memcpy, use_memset >::uses_memset = use_memset
staticconstexpr
Examples
test_lfringbuffer01.cpp.

Definition at line 118 of file ringbuffer.hpp.


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