libxr  1.0
Want to be the best embedded framework
Loading...
Searching...
No Matches
queue_base.hpp
1#pragma once
2
3#include <cstddef>
4#include <cstdint>
5
6#include "libxr_def.hpp"
7
8namespace LibXR
9{
20{
21 public:
29 QueueBase(uint16_t element_size, size_t length, uint8_t* buffer);
30
39 QueueBase(uint16_t element_size, size_t length);
40
45 ~QueueBase();
46
53 [[nodiscard]] void* operator[](uint32_t index);
54
62 ErrorCode PushBytes(const void* data);
63
71 ErrorCode PeekBytes(void* data);
72
81 ErrorCode PopBytes(void* data = nullptr);
82
89 int GetLastElementIndex() const;
90
97 int GetFirstElementIndex() const;
98
107 ErrorCode PushBatchBytes(const void* data, size_t size);
108
118 ErrorCode PopBatchBytes(void* data, size_t size);
119
128 ErrorCode PeekBatchBytes(void* data, size_t size);
129
136 ErrorCode OverwriteBytes(const void* data);
137
142 void Reset();
143
149 [[nodiscard]] size_t Size() const;
150
156 [[nodiscard]] size_t EmptySize() const;
157
163 [[nodiscard]] size_t MaxSize() const { return length_; }
164
165 private:
176
177 public:
178 uint8_t* queue_array_;
179 const uint16_t ELEMENT_SIZE;
180 size_t head_ = 0;
181 size_t tail_ = 0;
182 bool is_full_ = false;
183 size_t length_;
184 bool own_buffer_ = false;
185};
186} // namespace LibXR
提供固定大小循环缓冲区的字节 FIFO 队列。
~QueueBase()
析构队列。
size_t EmptySize() const
获取当前剩余空槽数。
bool is_full_
当前队列是否已满。 Whether the queue is currently full.
ErrorCode PushBytes(const void *data)
按字节入队一个元素。
QueueBase & operator=(QueueBase &&)
禁止移动赋值。 Non-move-assignable.
const uint16_t ELEMENT_SIZE
单个元素的字节数。 Byte size of one element.
uint8_t * queue_array_
队列数据缓冲区。 Queue data buffer.
ErrorCode PopBatchBytes(void *data, size_t size)
按字节批量出队多个元素。
int GetLastElementIndex() const
获取当前最后一个已入队元素的物理槽位下标。
void Reset()
重置队列状态。
QueueBase(const QueueBase &)
禁止拷贝构造。 Non-copyable.
QueueBase(uint16_t element_size, size_t length, uint8_t *buffer)
使用外部缓冲区构造队列。
Definition queue_base.cpp:7
ErrorCode OverwriteBytes(const void *data)
清空当前状态后,用一个新元素覆盖队列内容。
ErrorCode PeekBatchBytes(void *data, size_t size)
按字节批量查看多个元素但不出队。
size_t MaxSize() const
获取队列最大容量。
QueueBase & operator=(QueueBase &)
禁止同类型左值赋值重载。 Non-copy-assignable overload for non-const lvalues.
void * operator[](uint32_t index)
访问指定物理槽位的原始元素地址。
QueueBase & operator=(const QueueBase &)
禁止拷贝赋值。 Non-copy-assignable.
size_t Size() const
获取当前已存储元素个数。
QueueBase & operator=(const QueueBase &&)
禁止移动赋值(const rvalue 形式)。 Non-move-assignable (const rvalue form).
ErrorCode PushBatchBytes(const void *data, size_t size)
按字节批量入队多个元素。
int GetFirstElementIndex() const
获取当前第一个已入队元素的物理槽位下标。
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.
size_t tail_
下一个待写入物理槽位下标。 Physical slot index of the next enqueue position.
ErrorCode PopBytes(void *data=nullptr)
按字节出队一个元素;传空指针时仅丢弃队头。
ErrorCode PeekBytes(void *data)
按字节查看队头元素但不出队。
LibXR 命名空间
Definition ch32_can.hpp:14
ErrorCode
定义错误码枚举