7#include "libxr_def.hpp"
66 ErrorCode
Push(
const void *data)
68 ASSERT(data !=
nullptr);
72 return ErrorCode::FULL;
94 ASSERT(data !=
nullptr);
103 return ErrorCode::EMPTY;
114 ErrorCode
Pop(
void *data =
nullptr)
124 return ErrorCode::OK;
128 return ErrorCode::EMPTY;
160 return static_cast<int>(
head_);
177 ASSERT(data !=
nullptr);
182 return ErrorCode::FULL;
185 auto tmp =
reinterpret_cast<const uint8_t *
>(data);
187 for (
size_t i = 0; i < size; i++)
197 return ErrorCode::OK;
212 return ErrorCode::EMPTY;
221 return ErrorCode::OK;
226 for (
size_t i = 0; i < size; i++)
235 return ErrorCode::OK;
247 ASSERT(data !=
nullptr);
251 return ErrorCode::EMPTY;
258 for (
size_t i = 0; i < size; i++)
265 return ErrorCode::OK;
276 ASSERT(data !=
nullptr);
289 return ErrorCode::OK;
352template <
typename Data>
基础队列类,提供固定大小的循环缓冲区 (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).
size_t Size()
获取队列中的元素个数 (Get the number of elements 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).
int GetFirstElementIndex()
获取队列中第一个元素的索引 (Get the index of the first element in the queue).
void * operator[](uint32_t index)
访问指定索引的元素 (Access an element at a specified index).
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).
size_t EmptySize()
获取队列的空闲空间 (Get the available space 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).
int GetLastElementIndex()
获取队列中最后一个元素的索引 (Get the index of the last element in the queue).
基于 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).
LibXR Color Control Library / LibXR终端颜色控制库
constexpr auto min(T1 a, T2 b) -> typename std::common_type< T1, T2 >::type
计算两个数的最小值