smplque
Container class with FIFO queue structure.
Container class with FIFO queue structure.
smplque
is a container class that provides FIFO queue operations for memory areas specified by element type T
and memory allocation method alloc
. Since the specification of alloc
is complicated, an alias definition using using
is used.
As a rule, element types are assumed to be structures that store numbers, numerical values, etc. It is not assumed to store objects that need to be destroyed by the destructor (since there is no process to delete the object when the element is deleted from the queue).
A class Intr
can be registered to set interrupt disabling at declaration time. If this class is not specified, normal operation without interrupt disable control is performed.
Example of object declaration. Immediately after the declaration, a method call is made for initialization. The maximum size of any of these objects is 128 bytes immediately after initialization, and the initial size is 0 and nothing is stored. The maximum size cannot be changed.
Since it is a FIFO queue, it is operated using methods such as push()
,pop()
,front()
.
Access by iterator is also possible.
Declaration and initialization
Declares a container of type T
and size N
. After the declaration, call the initialization methods.
The smplque_local
allocates the area by a fixed array inside. Initialization by the constructor is also possible.
In smplque_attach
, specify the first pointer T* buf
of the buffer to be used, the initial size size
and the maximum size N
of the array. Initialization by the constructor is also possible.
smplque_heapallocates memory in the HEAP area (an area of memory that cannot be released but can be allocated at any time). Once allocated, this area cannot be released, so it is usually defined in the global area. Allocation is done by
init_heap(). Memory allocation by the constructor is not allowed. Please call
init_heap()` to use this function.
When creating a global object, initialization by the constructor is not possible (due to compiler limitation). Please call initialization functions init_local()
,attach()
,init_heap()
at the beginning of execution (setup()
is recommended).
Methods
push(), pop(), front(), back()
push()` adds an entry to the queue.
pop()` removes an entry from the queue.
front()` refers to the first entry (the first one added).
back()` refers to the last entry (the last one added).
pop_front()` refers to the first entry as a return value and deletes it from the queue.
empty(), size(), is_full()
empty()
returns true
if the array contains no elements. is_full()
returns true
when the array is full.
size()
returns the number of elements stored in the queue.
capacity()
returns the maximum number of elements stored in the queue.
clear()
Erase all elements of the queue.
operator []
element. 0
is the first element added.
Iterator
You can get an iterator by begin()
and end()
. The beginning of the iterator is the first registered element of the queue. By using the iterator, range for statements and algorithms can be used.
One application is Access by iterator focusing on a specific member of the structure axis_xyzt.
最終更新