smplque

Container class with FIFO queue structure.

Container class with FIFO queue structure.

template <typename T, int N, class Intr> smplbuf_local
template <typename T, class Intr> smplbuf_attach
template <typename T, class Intr> smplbuf_heap

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.

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.

void some_func() {

// alloc locally
smplque_local<uint8_t, 128> q1;

// attach to existing buffer
uint8_t buf[128];
smplque_attach<uint8_t> q2;

// alloc from the HEAP
smplque_heap<uint8_t> q3;

void setup() {
  // Globally defined objects are initialized with setup()
  q1.init_local();
  q2.attach(buf, 128);
  q3.init_heap(128);
}

void some_func() {
  // Local definition of smplque_local can omit init_local()
  smplque_local<uint8_t, 128> q_local;
  ..
}

}

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 byinit_heap(). Memory allocation by the constructor is not allowed. Please call init_heap()` to use this function.

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.

最終更新