1#include "queue_base.hpp"
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);
static void FastCopy(void *dst, const void *src, size_t size)
快速内存拷贝 / Fast memory copy
~QueueBase()
析构队列 / Destroy the queue.
size_t EmptySize() const
获取当前剩余空槽数 / Get the current free-slot count.
bool is_full_
当前队列是否已满 / Whether the queue is currently full.
ErrorCode PushBytes(const void *data)
按字节入队一个元素 / Enqueue one element by bytes.
const uint16_t ELEMENT_SIZE
单个元素的字节数 / Byte size of one element.
uint8_t * queue_array_
队列数据缓冲区 / Queue data buffer.
ErrorCode PopBatchBytes(void *data, size_t size)
按字节批量出队多个元素 / Dequeue multiple elements by bytes.
int GetLastElementIndex() const
获取当前最后一个已入队元素的物理槽位下标。 Get the physical slot index of the current last queued element.
void Reset()
重置队列状态 / Reset the queue state.
QueueBase(uint16_t element_size, size_t length, uint8_t *buffer)
使用外部缓冲区构造队列 / Construct the queue with an external buffer.
ErrorCode OverwriteBytes(const void *data)
清空当前状态后,用一个新元素覆盖队列内容。 Reset the queue state and overwrite it with one new element.
ErrorCode PeekBatchBytes(void *data, size_t size)
按字节批量查看多个元素但不出队。 Peek multiple elements by bytes without dequeuing them.
void * operator[](uint32_t index)
访问指定物理槽位的原始元素地址。 Access the raw element address of one physical slot.
size_t Size() const
获取当前已存储元素个数 / Get the current stored element count.
ErrorCode PushBatchBytes(const void *data, size_t size)
按字节批量入队多个元素 / Enqueue multiple elements by bytes.
int GetFirstElementIndex() const
获取当前第一个已入队元素的物理槽位下标。 Get the physical slot index of the current first queued element.
size_t length_
队列最大容量 / Maximum queue capacity.
size_t head_
当前队头物理槽位下标 / Physical slot index of the current head.
bool own_buffer_
是否由当前队列拥有缓冲区 / Whether this queue owns the buffer.
ErrorCode PopBytes(void *data=nullptr)
按字节出队一个元素;传空指针时仅丢弃队头。 Dequeue one element by bytes; pass null to discard the front item only.
ErrorCode PeekBytes(void *data)
按字节查看队头元素但不出队。 Peek the front element by bytes without dequeuing it.
LibXR 命名空间 / LibXR namespace.
ErrorCode
定义错误码枚举 / Defines an enumeration for error codes
@ OK
操作成功 / Operation successful
constexpr auto min(LeftType a, RightType b) -> std::common_type_t< LeftType, RightType >
计算两个数的最小值 / Computes the minimum of two numbers