6 : queue_array_(buffer),
7 ELEMENT_SIZE(element_size),
14 : queue_array_(new uint8_t[length * element_size]),
15 ELEMENT_SIZE(element_size),
36 ASSERT(data !=
nullptr);
40 return ErrorCode::FULL;
56 ASSERT(data !=
nullptr);
65 return ErrorCode::EMPTY;
73 return ErrorCode::EMPTY;
100 return static_cast<int>(
head_);
105 ASSERT(data !=
nullptr);
110 return ErrorCode::FULL;
113 auto tmp =
reinterpret_cast<const uint8_t *
>(data);
118 if (size > first_part)
129 return ErrorCode::OK;
136 return ErrorCode::EMPTY;
141 return ErrorCode::OK;
148 auto tmp =
reinterpret_cast<uint8_t *
>(data);
150 if (size > first_part)
158 return ErrorCode::OK;
163 ASSERT(data !=
nullptr);
167 return ErrorCode::EMPTY;
172 auto tmp =
reinterpret_cast<uint8_t *
>(data);
177 if (first_part < size)
183 return ErrorCode::OK;
188 ASSERT(data !=
nullptr);
201 return ErrorCode::OK;
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).
constexpr auto min(T1 a, T2 b) -> typename std::common_type< T1, T2 >::type
计算两个数的最小值