Queue handling library (designed on Arduino)
This library was designed for Arduino, yet may be compiled without change with gcc for other purposes/targets
Queue class has since start been called Queue. Unfortunately, on some platforms or when using FreeRTOS, Queue is already declared.
For compatibility purposes, Queue class has been renamed to cppQueue. Sorry for the inconvenience...
- Declare a
cppQueueinstance(size_t size_rec, uint16_t nb_recs=20, QueueType type=FIFO, bool overwrite=false, void * pQDat=NULL, size_t lenQDat=0)(calledqbelow):size_rec- size of a record in the queuenb_recs- number of records in the queuetype- queue implementation type: FIFO, LIFOoverwrite- overwrite previous records when queue is full if set to truepQDat- pointer to static data queuelenQDat- length of static data queue (in bytes)
- Push stuff to the queue using
q.push(void * rec)- returns
trueif successfully pushed into queue - returns
falseis queue is full
- returns
- Pop stuff from the queue using
q.pop(void * rec)orq.pull(void * rec)- returns
trueif successfully popped from queue - returns
falseif queue is empty
- returns
- Peek stuff from the queue using
q.peek(void * rec)- returns
trueif successfully peeked from queue - returns
falseif queue is empty
- returns
- Drop stuff from the queue using
q.drop(void)- returns
trueif successfully dropped from queue - returns
falseif queue is empty
- returns
- Peek stuff at index from the queue using
q.peekIdx(void * rec, uint16_t idx)- returns
trueif successfully peeked from queue - returns
falseif index is out of range - warning: no associated drop function, not to use with
q.drop
- returns
- Peek latest stored from the queue using
q.peekPrevious(void * rec)- returns
trueif successfully peeked from queue - returns
falseif queue is empty - warning: no associated drop function, not to use with
q.drop - note: only useful with FIFO implementation, use
q.peekinstead with a LIFO
- returns
- Other methods:
q.isInitialized():trueif initialized properly,falseotherwiseq.isEmpty():trueif empty,falseotherwiseq.isFull():trueif full,falseotherwiseq.sizeOf(): queue size in bytes (returns 0 in case queue allocation failed)q.getCount()orq.nbRecs(): number of records stored in the queueq.getRemainingCount(): number of records left in the queueq.clean()orq.flush(): remove all items in the queue
- Interrupt safe automation is not implemented in the library. You have to manually disable/enable interrupts where required.
No implementation will be made as it would be an issue when using
peek/dropmethods with LIFO implementation: if an item is put to the queue through interrupt betweenpeekanddropcalls, thedropcall would drop the wrong (newer) item. In this particular case, dropping decision must be made before re-enabling interrupts.
- SimpleQueue.ino: Simple queue example (both LIFO FIFO implementations can be tested)
- SimpleQueueStatic.ino: Simple queue example using static queue data array (both LIFO FIFO implementations can be tested)
- PointersQueue.ino: Queue of string pointers for string processing
- SerialQueue.ino: Print characters received from Serial to Serial after reception of EOT char
- QueueDuplicates.ino: Simple test to test queue duplicates before pushing to queue
- QueueIdxPeeking.ino: Simple test to test queue index picking
- RolloverTest.ino: Simple test to test queue rollover (for lib testing purposes mainly)
- LibTst.ino: flexible test (for lib testing purposes mainly)
cQueue - C implementation of this library