|
| Queue (const Queue &)=delete |
|
Queue & | operator= (const Queue &)=delete |
|
template<uint8_t SIZE> |
| Queue (T(&buffer)[SIZE], bool locked=false) |
| Create a new queue, based on the provided buffer array. More...
|
|
void | lock () |
| Lock this queue, ie prevent pushing any data to it. More...
|
|
void | unlock () |
| Unlock this queue, ie allow pushing data to it. More...
|
|
bool | is_locked () const |
| Check if this queue is locked, ie if pushing data to it is disabled. More...
|
|
bool | push_ (TREF item) |
| Push item to the end of this queue, provided there is still available space in its ring buffer. More...
|
|
bool | pull_ (T &item) |
| Pull an item from the beginning of this queue, if not empty, and copy it into item . More...
|
|
bool | peek_ (T &item) const |
| Peek an item from the beginning of this queue, if not empty, and copy it into item . More...
|
|
uint8_t | peek_ (T *buffer, uint8_t size) const |
| Peek up to size items from the beginning of this queue, if not empty, and copy these into buffer array. More...
|
|
template<uint8_t SIZE> |
uint8_t | peek_ (T(&buffer)[SIZE]) const |
| Peek up to SIZE items from the beginning of this queue, if not empty, and copy these into buffer array. More...
|
|
uint8_t | size () const |
| Get the maximum size of this queue. More...
|
|
bool | empty_ () const |
| Tell if this queue is currently empty. More...
|
|
bool | full_ () const |
| Tell if this queue is currently full. More...
|
|
uint8_t | items_ () const |
| Tell the current number of items currently present in this queue. More...
|
|
uint8_t | free_ () const |
| Tell the current number of available locations for items to be pushed to this queue. More...
|
|
void | clear_ () |
| Completely clear this queue. More...
|
|
bool | push (TREF item) |
| Push item to the end of this queue, provided there is still available space in its ring buffer. More...
|
|
bool | pull (T &item) |
| Pull an item from the beginning of this queue, if not empty, and copy it into item . More...
|
|
bool | peek (T &item) const |
| Peek an item from the beginning of this queue, if not empty, and copy it into item . More...
|
|
uint8_t | peek (T *buffer, uint8_t size) const |
| Peek up to size items from the beginning of this queue, if not empty, and copy these into buffer array. More...
|
|
template<uint8_t SIZE> |
uint8_t | peek (T(&buffer)[SIZE]) const |
| Peek up to SIZE items from the beginning of this queue, if not empty, and copy these into buffer array. More...
|
|
bool | empty () const |
| Tell if this queue is currently empty. More...
|
|
uint8_t | items () const |
| Tell the current number of items currently present in this queue. More...
|
|
uint8_t | free () const |
| Tell the current number of available locations for items to be pushed to this queue. More...
|
|
bool | full () const |
| Tell if this queue is currently full. More...
|
|
void | clear () |
| Completely clear this queue. More...
|
|
template<typename T_, typename TREF_ = const T_&>
class containers::Queue< T_, TREF_ >
Queue of type T_
items.
This is a FIFO (first in first out) queue, built upon a ring buffer of fixed size, passed at construction time.
This queue offers only a few operations:
- push an item at "the end" of the queue
- pull an item from "the beginning" of the queue
- clear the whole queue
- get various information without changing the queue, including peeking one or several items from the beginning of the queue without removing them
All operations exist in two flavors:
- synchronized: you should use this flavor whenever the caller cannot guarantee no interruption will occur during the operation, i.e. when the caller is neither part of an ISR, nor embedded itself in a
synchronized
block.
- not synchronized: you should use this flavor when the caller can guarantee that no interruption will occur during the operation, e.g. when called from an ISR or from within a
synchronized
block; these methods bear the same name as their synchronized counterparts, with an additional trailing **_** underscore.
- Template Parameters
-
T_ | the type of items in this queue |
TREF_ | the constant reference type of items in this queue; this is const T_& by default, but this may be changed, for small size types (one or two bytes long) to T_ itself, in order to avoid additional code to handle reference extraction of an item. This type is used by push() methods. |
Definition at line 58 of file queue.h.
template<typename T_ , typename TREF_ = const T_&>
template<uint8_t SIZE>
Create a new queue, based on the provided buffer
array.
The queue size is determined by the size of buffer
.
- Template Parameters
-
SIZE | the number of T items that buffer can hold; note that, for optimization reasons, only SIZE - 1 items can be held in the buffer. |
- Parameters
-
buffer | the buffer used by this queue to store its items |
locked | when true , prevents pushing any data to this queue |
Definition at line 78 of file queue.h.
template<typename T_ , typename TREF_ = const T_&>
Push item
to the end of this queue, provided there is still available space in its ring buffer.
This method is not synchronized, hence you must ensure it is called from an interrupt-safe context; otherwise, you should use the synchronized flavor push()
instead.
- Parameters
-
item | a constant reference to the item to be pushed to thsi queue |
- Return values
-
true | if item could be pushed |
false | if this queue is full and thus item could not be pushed |
- See also
- push()
-
pull_()
-
free_()
template<typename T_ , typename TREF_ = const T_&>
Pull an item from the beginning of this queue, if not empty, and copy it into item
.
The item is removed from the queue. This method is not synchronized, hence you must ensure it is called from an interrupt-safe context; otherwise, you should use the synchronized flavor pull()
instead.
- Parameters
-
item | a reference to the item variable that will be assigned the first element of this queue |
- Return values
-
true | if the queue is not empty and thus an item has been copied to item |
false | if this queue is empty and thus item has not changed |
- See also
- pull()
-
push_()
-
empty_()
template<typename T_ , typename TREF_ = const T_&>
Peek an item from the beginning of this queue, if not empty, and copy it into item
.
The queue is NOT modified, no item is removed from the queue. This method is not synchronized, hence you must ensure it is called from an interrupt-safe context; otherwise, you should use the synchronized flavor peek()
instead.
- Parameters
-
item | a reference to the item variable that will be assigned the first element of this queue |
- Return values
-
true | if the queue is not empty and thus an item has been copied to item |
false | if this queue is empty and thus item has not changed |
- See also
- peek()
-
pull_()
-
push_()
-
empty_()
template<typename T_ , typename TREF_ = const T_&>
Peek up to size
items from the beginning of this queue, if not empty, and copy these into buffer
array.
The queue is NOT modified, no item is removed from the queue. This method is not synchronized, hence you must ensure it is called from an interrupt-safe context; otherwise, you should use the synchronized flavor peek()
instead.
- Parameters
-
buffer | a pointer to an array of size items of type T , that will be assigned the first size elements of this queue |
size | the maximum number of items to peek from this queue and copy to buffer ; buffer size must be at least size |
- Returns
- the number of elements copied from the queue into
buffer
; this may be 0
if the queue is empty, or any number lower or equal to size
; this will be size
if the queue has at least size
elements
- See also
- peek()
-
pull_()
-
push_()
-
items_()
template<typename T_ , typename TREF_ = const T_&>
template<uint8_t SIZE>
Peek up to SIZE
items from the beginning of this queue, if not empty, and copy these into buffer
array.
The queue is NOT modified, no item is removed from the queue. This method is not synchronized, hence you must ensure it is called from an interrupt-safe context; otherwise, you should use the synchronized flavor peek()
instead.
- Template Parameters
-
SIZE | the number of items that buffer can hold; this is also the maximum number of items to peek from this queue and copy to buffer |
- Parameters
-
buffer | an array of SIZE items of type T , that will be assigned the first SIZE elements of this queue |
- Returns
- the number of elements copied from the queue into
buffer
; this may be 0
if the queue is empty, or any number lower or equal to SIZE
; this will be SIZE
if the queue has at least SIZE
elements
- See also
- peek()
-
pull_()
-
push_()
-
items_()
template<typename T_ , typename TREF_ = const T_&>
Tell if this queue is currently empty.
This method is not synchronized, hence you must ensure it is called from an interrupt-safe context; otherwise, you should use the synchronized flavor empty()
instead.
- See also
- empty()
-
free_()
-
full_()
Definition at line 233 of file queue.h.
template<typename T_ , typename TREF_ = const T_&>
Tell if this queue is currently full.
This method is not synchronized, hence you must ensure it is called from an interrupt-safe context; otherwise, you should use the synchronized flavor full()
instead.
- See also
- full()
-
free_()
Definition at line 246 of file queue.h.
template<typename T_ , typename TREF_ = const T_&>
Tell the current number of items currently present in this queue.
This method is not synchronized, hence you must ensure it is called from an interrupt-safe context; otherwise, you should use the synchronized flavor items()
instead.
- See also
- items()
-
size()
Definition at line 259 of file queue.h.
template<typename T_ , typename TREF_ = const T_&>
Tell the current number of available locations for items to be pushed to this queue.
This method is not synchronized, hence you must ensure it is called from an interrupt-safe context; otherwise, you should use the synchronized flavor free()
instead.
- See also
- free()
-
empty_()
Definition at line 275 of file queue.h.
template<typename T_ , typename TREF_ = const T_&>
Completely clear this queue.
All present items, if any, are lost. This method is not synchronized, hence you must ensure it is called from an interrupt-safe context; otherwise, you should use the synchronized flavor clear()
instead.
- See also
- clear()
-
empty_()
Definition at line 291 of file queue.h.
template<typename T_ , typename TREF_ = const T_&>
Push item
to the end of this queue, provided there is still available space in its ring buffer.
This method is synchronized, hence you can call it from an an interrupt-unsafe context; if you are sure you are in an interrupt-safe, you should use the not synchronized flavor push_()
instead.
- Parameters
-
item | a constant reference to the item to be pushed to thsi queue |
- Return values
-
true | if item could be pushed |
false | if this queue is full and thus item could not be pushed |
- See also
- push_()
-
pull()
-
free()
Definition at line 311 of file queue.h.
template<typename T_ , typename TREF_ = const T_&>
Pull an item from the beginning of this queue, if not empty, and copy it into item
.
The item is removed from the queue. This method is synchronized, hence you can call it from an an interrupt-unsafe context; if you are sure you are in an interrupt-safe, you should use the not synchronized flavor pull_()
instead.
- Parameters
-
item | a reference to the item variable that will be assigned the first element of this queue |
- Return values
-
true | if the queue is not empty and thus an item has been copied to item |
false | if this queue is empty and thus item has not changed |
- See also
- pull_()
-
push()
-
empty()
Definition at line 333 of file queue.h.
template<typename T_ , typename TREF_ = const T_&>
Peek an item from the beginning of this queue, if not empty, and copy it into item
.
The queue is NOT modified, no item is removed from the queue. This method is synchronized, hence you can call it from an an interrupt-unsafe context; if you are sure you are in an interrupt-safe, you should use the not synchronized flavor peek_()
instead.
- Parameters
-
item | a reference to the item variable that will be assigned the first element of this queue |
- Return values
-
true | if the queue is not empty and thus an item has been copied to item |
false | if this queue is empty and thus item has not changed |
- See also
- peek_()
-
pull()
-
push()
-
empty()
Definition at line 356 of file queue.h.
template<typename T_ , typename TREF_ = const T_&>
Peek up to size
items from the beginning of this queue, if not empty, and copy these into buffer
array.
The queue is NOT modified, no item is removed from the queue. This method is synchronized, hence you can call it from an an interrupt-unsafe context; if you are sure you are in an interrupt-safe, you should use the not synchronized flavor peek_()
instead.
- Parameters
-
buffer | a pointer to an array of size items of type T , that will be assigned the first size elements of this queue |
size | the maximum number of items to peek from this queue and copy to buffer ; buffer size must be at least size |
- Returns
- the number of elements copied from the queue into
buffer
; this may be 0
if the queue is empty, or any number lower or equal to size
; this will be size
if the queue has at least size
elements
- See also
- peek_()
-
pull()
-
push()
-
items()
Definition at line 382 of file queue.h.
template<typename T_ , typename TREF_ = const T_&>
template<uint8_t SIZE>
Peek up to SIZE
items from the beginning of this queue, if not empty, and copy these into buffer
array.
The queue is NOT modified, no item is removed from the queue. This method is synchronized, hence you can call it from an an interrupt-unsafe context; if you are sure you are in an interrupt-safe, you should use the not synchronized flavor peek_()
instead.
- Template Parameters
-
SIZE | the number of items that buffer can hold; this is also the maximum number of items to peek from this queue and copy to buffer |
- Parameters
-
buffer | an array of SIZE items of type T , that will be assigned the first SIZE elements of this queue |
- Returns
- the number of elements copied from the queue into
buffer
; this may be 0
if the queue is empty, or any number lower or equal to SIZE
; this will be SIZE
if the queue has at least SIZE
elements
- See also
- peek_()
-
pull()
-
push()
-
items()
Definition at line 409 of file queue.h.
template<typename T_ , typename TREF_ = const T_&>
Tell if this queue is currently empty.
This method is synchronized, hence you can call it from an an interrupt-unsafe context; if you are sure you are in an interrupt-safe, you should use the not synchronized flavor empty_()
instead.
Definition at line 420 of file queue.h.
template<typename T_ , typename TREF_ = const T_&>
Tell the current number of items currently present in this queue.
This method is synchronized, hence you can call it from an an interrupt-unsafe context; if you are sure you are in an interrupt-safe, you should use the not synchronized flavor items_()
instead.
- See also
- items_()
Definition at line 432 of file queue.h.
template<typename T_ , typename TREF_ = const T_&>
Tell the current number of available locations for items to be pushed to this queue.
This method is synchronized, hence you can call it from an an interrupt-unsafe context; if you are sure you are in an interrupt-safe, you should use the not synchronized flavor free_()
instead.
- See also
- free_()
-
empty()
Definition at line 446 of file queue.h.
template<typename T_ , typename TREF_ = const T_&>
Tell if this queue is currently full.
This method is synchronized, hence you can call it from an an interrupt-unsafe context; if you are sure you are in an interrupt-safe, you should use the not synchronized flavor full_()
instead.
- See also
- full_()
-
free()
Definition at line 459 of file queue.h.
template<typename T_ , typename TREF_ = const T_&>
Completely clear this queue.
All present items, if any, are lost. This method is synchronized, hence you can call it from an an interrupt-unsafe context; if you are sure you are in an interrupt-safe, you should use the not synchronized flavor free()
instead.
- See also
- clear_()
-
empty()
Definition at line 472 of file queue.h.