7#include "libxr_def.hpp"
28 BaseQueue(uint16_t element_size,
size_t length, uint8_t *buffer)
76 ErrorCode
Push(
const void *data)
78 ASSERT(data !=
nullptr);
82 return ErrorCode::FULL;
104 ASSERT(data !=
nullptr);
109 return ErrorCode::OK;
113 return ErrorCode::EMPTY;
124 ErrorCode
Pop(
void *data =
nullptr)
128 return ErrorCode::EMPTY;
137 return ErrorCode::OK;
167 return static_cast<int>(
head_);
179 ASSERT(data !=
nullptr);
184 return ErrorCode::FULL;
187 auto tmp =
reinterpret_cast<const uint8_t *
>(data);
192 if (size > first_part)
203 return ErrorCode::OK;
218 return ErrorCode::EMPTY;
223 return ErrorCode::OK;
230 auto tmp =
reinterpret_cast<uint8_t *
>(data);
232 if (size > first_part)
240 return ErrorCode::OK;
252 ASSERT(data !=
nullptr);
256 return ErrorCode::EMPTY;
261 auto tmp =
reinterpret_cast<uint8_t *
>(data);
266 if (first_part < size)
272 return ErrorCode::OK;
283 ASSERT(data !=
nullptr);
296 return ErrorCode::OK;
312 [[nodiscard]]
size_t Size()
const
360template <
typename Data>
377 Queue(
size_t length, uint8_t *buffer) :
BaseQueue(sizeof(Data), length, buffer) {}
基础队列类,提供固定大小的循环缓冲区 (Base queue class providing a fixed-size circular buffer).
ErrorCode Pop(void *data=nullptr)
移除队列头部的元素 (Pop the front element from the queue).
bool is_full_
队列是否已满 (Indicates if the queue is full).
size_t tail_
尾部索引 (Tail index).
ErrorCode Overwrite(const void *data)
覆盖队列中的数据 (Overwrite the queue with new data).
ErrorCode Push(const void *data)
向队列中添加一个元素 (Push an element into the queue).
size_t head_
头部索引 (Head index).
size_t length_
队列最大容量 (Maximum queue capacity).
int GetLastElementIndex() const
获取队列中最后一个元素的索引 (Get the index of the last element in the queue).
size_t EmptySize() const
获取队列的空闲空间 (Get the available space in the queue).
ErrorCode PopBatch(void *data, size_t size)
批量移除多个元素 (Pop multiple elements from the queue).
BaseQueue(uint16_t element_size, size_t length, uint8_t *buffer)
构造函数,初始化队列 (Constructor to initialize the queue).
void Reset()
重置队列,清空所有数据 (Reset the queue and clear all 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).
size_t Size() const
获取队列中的元素个数 (Get the number of elements in the queue).
bool own_buffer_
是否由队列自己管理缓冲区 (Owns buffer memory).
ErrorCode Peek(void *data)
获取队列头部的元素但不移除 (Peek at the front element without removing it).
BaseQueue(uint16_t element_size, size_t length)
构造函数,初始化队列 (Constructor to initialize the queue).
~BaseQueue()
析构函数,释放队列内存 (Destructor to free queue memory).
int GetFirstElementIndex() const
获取队列中第一个元素的索引 (Get the index of the first element in the queue).
uint8_t * queue_array_
存储队列数据的数组 (Array storing queue data).
ErrorCode PushBatch(const void *data, size_t size)
批量推入多个元素 (Push multiple elements into the queue).
const uint16_t ELEMENT_SIZE
每个元素的大小 (Size of each element).
基于 BaseQueue 的泛型队列模板类 (Generic queue template class based on BaseQueue).
ErrorCode PopBatch(Data *data, size_t size)
批量移除多个元素,并获取数据 (Pop multiple elements from the queue and retrieve data).
Queue(size_t length, uint8_t *buffer)
构造函数,初始化队列 (Constructor to initialize the queue).
ErrorCode PeekBatch(Data *data, size_t size)
批量查看多个元素但不移除 (Peek at multiple elements without removing them).
ErrorCode PushBatch(const Data *data, size_t size)
批量推入多个元素 (Push multiple elements into the queue).
ErrorCode Peek(Data &data)
查看队列头部的元素但不移除 (Peek at the front element without removing it).
ErrorCode Overwrite(const Data &data)
覆盖队列中的数据 (Overwrite the queue with new data).
ErrorCode Pop()
仅从队列中移除头部元素,不获取数据 (Remove the front element from the queue without retrieving data).
Queue(size_t length)
构造函数,初始化队列 (Constructor to initialize the queue).
ErrorCode Pop(Data &data)
从队列中移除头部元素,并获取该元素的数据 (Remove the front element from the queue and retrieve its data).
Data & operator[](int32_t index)
访问队列中的元素 (Access an element in the queue).
ErrorCode Push(const Data &data)
向队列中添加一个元素 (Push an element into the queue).
constexpr auto min(T1 a, T2 b) -> typename std::common_type< T1, T2 >::type
计算两个数的最小值