|
libxr
1.0
Want to be the best embedded framework
|
基于 QueueBase 的泛型队列模板类。 More...
#include <basic_queue.hpp>
Public Types | |
| using | ValueType = Data |
Public Types inherited from LibXR::QueueTypedBase< Queue< Data >, Data > | |
| using | ValueType |
| 队列元素类型。 Queue element type. | |
Public Member Functions | |
| Queue (size_t length) | |
| 构造一个由内部缓冲区支撑的强类型队列。 | |
| Queue (size_t length, uint8_t *buffer) | |
| 使用外部缓冲区构造强类型队列。 | |
| Data & | operator[] (int32_t index) |
| 按逻辑索引访问队列中的元素。 | |
| ErrorCode | Peek (Data &data) |
| 查看队头元素但不出队。 | |
| ErrorCode | PushBatch (const Data *data, size_t size) |
| 批量推入多个元素。 | |
| ErrorCode | PopBatch (Data *data, size_t size) |
| 批量移除多个元素并复制到输出数组。 | |
| ErrorCode | PeekBatch (Data *data, size_t size) |
| 批量查看多个元素但不移除。 | |
| ErrorCode | Overwrite (const Data &data) |
| 清空当前状态后,用一个新元素覆盖队列内容。 | |
| size_t | MaxSize () const |
| 获取队列最大容量。 | |
Public Member Functions inherited from LibXR::QueueTypedBase< Queue< Data >, Data > | |
| ErrorCode | Push (const Data &item) |
| 推入一个强类型元素。 | |
| ErrorCode | Pop (Data &item) |
| 弹出一个强类型元素。 | |
| ErrorCode | Pop () |
| 丢弃一个队头元素。 | |
Public Member Functions inherited from LibXR::QueueBase | |
| QueueBase (uint16_t element_size, size_t length, uint8_t *buffer) | |
| 使用外部缓冲区构造队列。 | |
| QueueBase (uint16_t element_size, size_t length) | |
| 由队列内部申请缓冲区并构造队列。 | |
| ~QueueBase () | |
| 析构队列。 | |
| void * | operator[] (uint32_t index) |
| 访问指定物理槽位的原始元素地址。 | |
| ErrorCode | PushBytes (const void *data) |
| 按字节入队一个元素。 | |
| ErrorCode | PeekBytes (void *data) |
| 按字节查看队头元素但不出队。 | |
| ErrorCode | PopBytes (void *data=nullptr) |
| 按字节出队一个元素;传空指针时仅丢弃队头。 | |
| int | GetLastElementIndex () const |
| 获取当前最后一个已入队元素的物理槽位下标。 | |
| int | GetFirstElementIndex () const |
| 获取当前第一个已入队元素的物理槽位下标。 | |
| ErrorCode | PushBatchBytes (const void *data, size_t size) |
| 按字节批量入队多个元素。 | |
| ErrorCode | PopBatchBytes (void *data, size_t size) |
| 按字节批量出队多个元素。 | |
| ErrorCode | PeekBatchBytes (void *data, size_t size) |
| 按字节批量查看多个元素但不出队。 | |
| ErrorCode | OverwriteBytes (const void *data) |
| 清空当前状态后,用一个新元素覆盖队列内容。 | |
| void | Reset () |
| 重置队列状态。 | |
| size_t | Size () const |
| 获取当前已存储元素个数。 | |
| size_t | EmptySize () const |
| 获取当前剩余空槽数。 | |
| size_t | MaxSize () const |
| 获取队列最大容量。 | |
Additional Inherited Members | |
Data Fields inherited from LibXR::QueueBase | |
| uint8_t * | queue_array_ |
| 队列数据缓冲区。 Queue data buffer. | |
| const uint16_t | ELEMENT_SIZE |
| 单个元素的字节数。 Byte size of one element. | |
| size_t | head_ = 0 |
| 当前队头物理槽位下标。 Physical slot index of the current head. | |
| size_t | tail_ = 0 |
| bool | is_full_ = false |
| 当前队列是否已满。 Whether the queue is currently full. | |
| size_t | length_ |
| 队列最大容量。 Maximum queue capacity. | |
| bool | own_buffer_ |
| 是否由当前队列拥有缓冲区。 Whether this queue owns the buffer. | |
基于 QueueBase 的泛型队列模板类。
Generic queue template class based on QueueBase.
该类提供一个类型安全的队列,用于存储 Data 类型的元素。 它支持标准的队列操作,如推入(Push)、弹出(Pop)、查看(Peek)以及批量操作。 This class provides a type-safe queue for storing elements of type Data. It supports standard queue operations such as push, pop, peek, and batch operations.
| Data | 队列存储的数据类型。 Type of data stored in the queue. |
Definition at line 24 of file basic_queue.hpp.
| using LibXR::Queue< Data >::ValueType = Data |
队列元素类型。 Queue element type.
Definition at line 27 of file basic_queue.hpp.
|
inlineexplicit |
构造一个由内部缓冲区支撑的强类型队列。
Construct one typed queue backed by an internal buffer.
| length | 队列最大容量。 Maximum queue capacity. |
Definition at line 40 of file basic_queue.hpp.
|
inline |
使用外部缓冲区构造强类型队列。
Construct one typed queue with an external buffer.
| length | 队列最大容量。 Maximum queue capacity. |
| buffer | 外部缓冲区指针。 Pointer to the external buffer. |
length * sizeof(Data) 字节。 The caller must ensure that the external buffer can hold at least length * sizeof(Data) bytes. Definition at line 52 of file basic_queue.hpp.
|
inlinenodiscard |
获取队列最大容量。
Get the maximum queue capacity.
Definition at line 147 of file basic_queue.hpp.
|
inline |
按逻辑索引访问队列中的元素。
Access an element in the queue by logical index.
该函数允许使用索引访问队列中的元素。 如果索引为正,则表示从 head_(队列头部)开始的偏移量。 如果索引为负,则表示从 tail_(队列尾部)开始的偏移量。 This function provides indexed access to elements in the queue. If the index is positive, it is relative to head_ (front of the queue). If negative, it is relative to tail_ (end of the queue).
| index | 访问的逻辑索引值。 Logical index to access. |
Definition at line 68 of file basic_queue.hpp.
|
inline |
清空当前状态后,用一个新元素覆盖队列内容。
Reset the queue state and overwrite it with one new element.
| data | 用于覆盖队列的新元素。 New element used to overwrite the queue. |
ErrorCode::OK。 Returns ErrorCode::OK on success. Definition at line 140 of file basic_queue.hpp.
|
inline |
查看队头元素但不出队。
Peek the front element without removing it.
| data | 用于接收查看结果的引用。 Reference receiving the peeked element. |
ErrorCode::OK,队列空返回 ErrorCode::EMPTY。 Returns ErrorCode::OK on success and ErrorCode::EMPTY when the queue is empty. Definition at line 90 of file basic_queue.hpp.
|
inline |
批量查看多个元素但不移除。
Peek multiple elements without removing them.
| data | 指向输出数组的指针。 Pointer to the array receiving peeked elements. |
| size | 要查看的元素个数。 Number of elements to retrieve. |
ErrorCode::OK,元素不足返回 ErrorCode::EMPTY。 Returns ErrorCode::OK on success and ErrorCode::EMPTY when stored elements are insufficient. Definition at line 129 of file basic_queue.hpp.
|
inline |
批量移除多个元素并复制到输出数组。
Pop multiple elements and copy them into the output array.
| data | 指向输出数组的指针。 Pointer to the array receiving popped elements. |
| size | 要移除的元素个数。 Number of elements to remove. |
ErrorCode::OK,元素不足返回 ErrorCode::EMPTY。 Returns ErrorCode::OK on success and ErrorCode::EMPTY when stored elements are insufficient. Definition at line 115 of file basic_queue.hpp.
|
inline |
批量推入多个元素。
Push multiple elements into the queue.
| data | 指向元素数组的指针。 Pointer to the array of elements to push. |
| size | 要推入的元素个数。 Number of elements to push. |
ErrorCode::OK,空间不足返回 ErrorCode::FULL。 Returns ErrorCode::OK on success and ErrorCode::FULL when free space is insufficient. Definition at line 101 of file basic_queue.hpp.