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
54 [[nodiscard]] void* operator[](uint32_t index);
55
64 ErrorCode PushBytes(const void* data);
65
74 ErrorCode PeekBytes(void* data);
75
85 ErrorCode PopBytes(void* data = nullptr);
86
94 int GetLastElementIndex() const;
95
103 int GetFirstElementIndex() const;
104
114 ErrorCode PushBatchBytes(const void* data, size_t size);
115
126 ErrorCode PopBatchBytes(void* data, size_t size);
127
137 ErrorCode PeekBatchBytes(void* data, size_t size);
138
145 ErrorCode OverwriteBytes(const void* data);
146
151 void Reset();
152
158 [[nodiscard]] size_t Size() const;
159
165 [[nodiscard]] size_t EmptySize() const;
166
172 [[nodiscard]] size_t MaxSize() const { return length_; }
173
174 private:
185
186 public:
187 uint8_t* queue_array_;
188 const uint16_t ELEMENT_SIZE;
189 size_t head_ = 0;
190 size_t tail_ = 0;
192 bool is_full_ = false;
193 size_t length_;
195 false;
196};
197} // 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.
ErrorCode PopBytes(void *data=nullptr)
按字节出队一个元素;传空指针时仅丢弃队头。
ErrorCode PeekBytes(void *data)
按字节查看队头元素但不出队。
LibXR 命名空间
Definition ch32_can.hpp:14
ErrorCode
定义错误码枚举