3#include "libxr_mem.hpp"
8 : queue_array_(buffer),
9 ELEMENT_SIZE(element_size),
16 : queue_array_(new uint8_t[length * element_size]),
17 ELEMENT_SIZE(element_size),
38 ASSERT(data !=
nullptr);
58 ASSERT(data !=
nullptr);
102 return static_cast<int>(
head_);
107 ASSERT(data !=
nullptr);
115 auto tmp =
reinterpret_cast<const uint8_t*
>(data);
121 if (size > first_part)
151 auto tmp =
reinterpret_cast<uint8_t*
>(data);
154 if (size > first_part)
167 ASSERT(data !=
nullptr);
176 auto tmp =
reinterpret_cast<uint8_t*
>(data);
182 if (first_part < size)
193 ASSERT(data !=
nullptr);
bool is_full_
队列是否已满 (Indicates if the queue is full).
size_t tail_
尾部索引 (Tail index).
ErrorCode Peek(void *data)
获取队列头部的元素但不移除 (Peek at the front element without removing it).
size_t head_
头部索引 (Head index).
size_t length_
队列最大容量 (Maximum queue capacity).
ErrorCode Overwrite(const void *data)
覆盖队列中的数据 (Overwrite the queue with new data).
ErrorCode PeekBatch(void *data, size_t size)
批量获取多个元素但不移除 (Peek at multiple elements without removing them).
void * operator[](uint32_t index)
访问指定索引的元素 (Access an element at a specified index).
ErrorCode PushBatch(const void *data, size_t size)
批量推入多个元素 (Push multiple elements into the queue).
size_t Size() const
获取队列中的元素个数 (Get the number of elements in the queue).
BaseQueue(uint16_t element_size, size_t length, uint8_t *buffer)
构造函数,初始化队列 (Constructor to initialize the queue).
bool own_buffer_
是否由队列自己管理缓冲区 (Owns buffer memory).
~BaseQueue()
析构函数,释放队列内存 (Destructor to free queue memory).
int GetFirstElementIndex() const
获取队列中第一个元素的索引 (Get the index of the first element in the queue).
ErrorCode Push(const void *data)
向队列中添加一个元素 (Push an element into the queue).
ErrorCode Pop(void *data=nullptr)
移除队列头部的元素 (Pop the front element from the queue).
void Reset()
重置队列,清空所有数据 (Reset the queue and clear all data).
size_t EmptySize() const
获取队列的空闲空间 (Get the available space in the queue).
ErrorCode PopBatch(void *data, size_t size)
批量移除多个元素 (Pop multiple elements from the queue).
int GetLastElementIndex() const
获取队列中最后一个元素的索引 (Get the index of the last element in the queue).
uint8_t * queue_array_
存储队列数据的数组 (Array storing queue data).
const uint16_t ELEMENT_SIZE
每个元素的大小 (Size of each element).
static void FastCopy(void *dst, const void *src, size_t size)
快速内存拷贝 / Fast memory copy
@ OK
操作成功 | Operation successful
constexpr auto min(LeftType a, RightType b) -> std::common_type_t< LeftType, RightType >
计算两个数的最小值