Version 0.0.2, +05:30 09:00:52 PM 19-05-2024, Sunday
CSE_CircularBuffer
- The main class for wrapping the data and functions of the library.
This constructor creates a new CSE_CircularBuffer
object. The array for this object can be dynamically allocated or passed as a parameter. There are two overloads. An example object cbuffer
will be used throughout the documentation. Since this is a templated class, the user must also pass a data type.
CSE_CircularBuffer <CSE_CB_t> cbuffer (int length);
CSE_CB_t
: A valid data type. eg.int
orfloat
.int length
: The number of data items you need in the buffer.
CSE_CircularBuffer
object.
CSE_CircularBuffer <CSE_CB_t> cbuffer (CSE_CB_t* buffer, int length);
CSE_CB_t
: A valid data type. eg.int
orfloat
.CSE_CB_t* buffer
: A pointer to an array ofCSE_CB_t
objects.int length
: The number of data items you need in the buffer.
CSE_CircularBuffer
object.
Destroys the CSE_CircularBuffer
object. If memory is allocated for the buffer, it will be freed.
cbuffer.~CSE_CircularBuffer();
None
None
Returns the index of the head of the buffer.
int head = cbuffer.getHead();
None
int
: The index of the head of the buffer.
Returns the index of the tail of the buffer.
int tail = cbuffer.getTail();
None
int
: The index of the tail of the buffer.
Returns the capacity of the buffer which indicates the total number of data items that can be stored in the buffer.
int capacity = cbuffer.getCapacity();
None
int
: The capacity of the buffer.
Checks if the buffer is full.
bool full = cbuffer.isFull();
None
bool
:true
if the buffer is full,false
otherwise.
Checks if the buffer is empty.
bool empty = cbuffer.isEmpty();
None
bool
:true
if the buffer is empty,false
otherwise.
Returns the number of occupied data items in the buffer.
int occupied = cbuffer.getOccupiedLength();
None
int
: The number of occupied data items in the buffer.
Returns the number of vacant data items in the buffer.
int vacant = cbuffer.getVacantLength();
None
int
: The number of vacant data items in the buffer.
Pushes a new data item into the buffer. The data is pushed to head
end of the buffer. There are two overloads. You can either push a single data or push an array of data. You can also specify the order of the data in the array.
cbuffer.push (CSE_CB_t data);
CSE_CB_t data
: Data of typeCSE_CB_t
. If your data type is anint
, for example, then the data passed should be anint
.
int
:0
if successful,-1
otherwise.
cbuffer.push (CSE_CB_t* data, int length, int dataOrder);
CSE_CB_t* data
: A pointer to an array ofCSE_CB_t
data.int length
: The number of data items in the array.int dataOrder
: The order of the data in the buffer.0
for same order,1
for reverse order. Default value is0
.
int
:0
if successful,-1
otherwise.
Pops one or more data items from the buffer. The data is popped from the tail
end of the buffer. There are two overloads. You can either pop a single data or pop an array of data. You can also specify the order of the data in the array.
cbuffer.pop (CSE_CB_t* data);
CSE_CB_t* data
: A pointer to a destination variable ofCSE_CB_t
type.
int
:0
if successful,-1
otherwise. The operation can fail with-1
, if the buffer is empty.
cbuffer.pop (CSE_CB_t* data, int length);
CSE_CB_t* data
: A pointer to a destination array ofCSE_CB_t
type.int length
: The number of data items to pop. The destination array must be large enough to holdlength
data items.
int
: Number of data popped, if successful,-1
otherwise. The operation can fail with-1
, if the buffer is empty. If there is not enough data in the buffer, the function returns the number of data popped before the buffer became empty.
This copies the data from the circular buffer to a linear buffer specified by the user. This operation doesn't pop the data from the circular buffer. The target buffer must have enough space to hold the data. The length
is optional and if set to 0
, the entire circular buffer is copied up to maxlen
. If the data in the circular buffer is less than maxlen
, then the empty data is set to 0
in the target buffer. dataOrder
is also optional and determines the order of the data in the target buffer. If set to 0
, the data is copied in the same order as in the circular buffer. If set to 1
, the data is copied in reverse order. This function returns the number of data items copied (excluding the empty data).
int bufferCopy (CSE_CB_t* data, int length, int dataOrder);
CSE_CB_t* data
: A pointer to a destination array ofCSE_CB_t
type.int length
: The number of data items to copy. The destination array must be large enough to holdlength
data items.int dataOrder
: The order of the data in the target buffer.0
for same order,1
for reverse order. Default value is0
.
int
: Number of data copied, if successful,-1
otherwise.
Clears the buffer by setting the head
and tail
to 0
. This operation does not clear the data in the memory.
cbuffer.clear();
None
int
: The number of data present in the buffer before clearing.
Peeks the buffer by reading a single data without popping it from the buffer.
cbuffer.peek (CSE_CB_t* data);
CSE_CB_t* data
: A pointer to a destination variable ofCSE_CB_t
type.
int
:0
if successful,-1
otherwise.