MD_CirQueue Library  1.0
Library for FIFO queue implemented as a Ring Buffer
MD_CirQueue Class Reference

#include <MD_CirQueue.h>

Public Member Functions

 MD_CirQueue (uint8_t itmQty, uint16_t itmSize)
 
 ~MD_CirQueue ()
 
void begin (void)
 
void clear ()
 
bool push (uint8_t *itm)
 
uint8_t * pop (uint8_t *itm)
 
uint8_t * peek (uint8_t *itm)
 
void setFullOverwrite (bool b)
 
bool isEmpty (void)
 
bool isFull ()
 

Detailed Description

Core object for the MD_CirQueue library

Constructor & Destructor Documentation

◆ MD_CirQueue()

MD_CirQueue::MD_CirQueue ( uint8_t  itmQty,
uint16_t  itmSize 
)

Class Constructor.

Instantiate a new instance of the class. The parameters passed are used to configure the quantity and size of queue objects.

Parameters
itmQtynumber of items allowed in the queue.
itmSizesize of each item in bytes.

◆ ~MD_CirQueue()

MD_CirQueue::~MD_CirQueue ( )

Class Destructor.

Released allocated memory and does the necessary to clean up once the queue is no longer required.

Member Function Documentation

◆ begin()

void MD_CirQueue::begin ( void  )

Initialize the object.

Initialize the object data. This needs to be called during setup() to initialize new data for the class that cannot be done during the object creation.

◆ clear()

void MD_CirQueue::clear ( )

Clear contents of buffer

Clears the buffer by resetting the head and tail pointers. Does not zero out delete data in the buffer.

◆ isEmpty()

bool MD_CirQueue::isEmpty ( void  )

Check if the buffer is empty

Returns
true if empty, false otherwise

◆ isFull()

bool MD_CirQueue::isFull ( )

Check if the buffer is full

Returns
true if full, false otherwise

◆ peek()

uint8_t* MD_CirQueue::peek ( uint8_t *  itm)

Peek at the next item in the queue

Return a copy of the first item in the queue, copied into the buffer specified, returning a pointer to the copied item. If no items are available (queue is empty), then no data is copied and the method returns a NULL pointer. This does not remove the item in the queue but gives a 'llok-ahead' capability in processing the queue.

Parameters
itma pointer to data buffer for the copied item to be saved. Data size must be size specified in the constructor.
Returns
pointer to the memory buffer or NULL if the queue is empty

◆ pop()

uint8_t* MD_CirQueue::pop ( uint8_t *  itm)

Pop an item from the queue

Return the first available item in the queue, copied into the buffer specified, returning a pointer to the copied item. If no items are available (queue is empty), then no data is copied and the method returns a NULL pointer.

Parameters
itma pointer to data buffer for the retrieved item to be saved. Data size must be size specified in the constructor.
Returns
pointer to the memory buffer or NULL if the queue is empty

◆ push()

bool MD_CirQueue::push ( uint8_t *  itm)

Push an item into the queue

Place the item passed into the end of the queue. The item will be returned to the calling program, in FIFO order, using pop(). If the buffer is already full before the push(), the behavior will depend on the the setting controlled by the setFullOverwrite() method.

Parameters
itma pointer to data buffer of the item to be saved. Data size must be size specified in the constructor.
Returns
true if the item was successfully placed in the queue, false otherwise

◆ setFullOverwrite()

void MD_CirQueue::setFullOverwrite ( bool  b)

Set queue full behavior

If the setting is set true, then push() with a full queue will overwrite the oldest item in the queue. Default behavior is not to overwrite the oldest item and fail the push() attempt.

Parameters
btrue to overwrite oldest item, false (default) to fail the push() call

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