libxr 1.0
Want to be the best embedded framework
Loading...
Searching...
No Matches
LibXR::Queue< Data > Class Template Reference

基于 BaseQueue 的泛型队列模板类 (Generic queue template class based on BaseQueue). More...

#include <queue.hpp>

Inheritance diagram for LibXR::Queue< Data >:
Collaboration diagram for LibXR::Queue< Data >:

Public Member Functions

 Queue (size_t length)
 构造函数,初始化队列 (Constructor to initialize the queue).
 
 Queue (size_t length, uint8_t *buffer)
 构造函数,初始化队列 (Constructor to initialize the queue).
 
Dataoperator[] (int32_t index)
 访问队列中的元素 (Access an element in the queue).
 
ErrorCode Push (const Data &data)
 向队列中添加一个元素 (Push an element into the queue).
 
ErrorCode Pop (Data &data)
 从队列中移除头部元素,并获取该元素的数据 (Remove the front element from the queue and retrieve its data).
 
ErrorCode Pop ()
 仅从队列中移除头部元素,不获取数据 (Remove the front element from the queue without retrieving data).
 
ErrorCode Peek (Data &data)
 查看队列头部的元素但不移除 (Peek at the front element without removing it).
 
ErrorCode PushBatch (const Data *data, size_t size)
 批量推入多个元素 (Push multiple elements into the queue).
 
ErrorCode PopBatch (Data *data, size_t size)
 批量移除多个元素,并获取数据 (Pop multiple elements from the queue and retrieve data).
 
ErrorCode PeekBatch (Data *data, size_t size)
 批量查看多个元素但不移除 (Peek at multiple elements without removing them).
 
ErrorCode Overwrite (const Data &data)
 覆盖队列中的数据 (Overwrite the queue with new data).
 
- Public Member Functions inherited from LibXR::BaseQueue
 BaseQueue (uint16_t element_size, size_t length, uint8_t *buffer)
 构造函数,初始化队列 (Constructor to initialize the queue).
 
 BaseQueue (uint16_t element_size, size_t length)
 构造函数,初始化队列 (Constructor to initialize the queue).
 
 ~BaseQueue ()
 析构函数,释放队列内存 (Destructor to free queue memory).
 
voidoperator[] (uint32_t index)
 访问指定索引的元素 (Access an element at a specified index).
 
ErrorCode Push (const void *data)
 向队列中添加一个元素 (Push an element into the queue).
 
ErrorCode Peek (void *data)
 获取队列头部的元素但不移除 (Peek at the front element without removing it).
 
ErrorCode Pop (void *data=nullptr)
 移除队列头部的元素 (Pop the front element from the queue).
 
int GetLastElementIndex ()
 获取队列中最后一个元素的索引 (Get the index of the last element in the queue).
 
int GetFirstElementIndex ()
 获取队列中第一个元素的索引 (Get the index of the first element in the queue).
 
ErrorCode PushBatch (const void *data, size_t size)
 批量推入多个元素 (Push multiple elements into the queue).
 
ErrorCode PopBatch (void *data, size_t size)
 批量移除多个元素 (Pop multiple elements from the queue).
 
ErrorCode PeekBatch (void *data, size_t size)
 批量获取多个元素但不移除 (Peek at multiple elements without removing them).
 
ErrorCode Overwrite (const void *data)
 覆盖队列中的数据 (Overwrite the queue with new data).
 
void Reset ()
 重置队列,清空所有数据 (Reset the queue and clear all data).
 
size_t Size ()
 获取队列中的元素个数 (Get the number of elements in the queue).
 
size_t EmptySize ()
 获取队列的空闲空间 (Get the available space in the queue).
 
 BaseQueue (const BaseQueue &)=delete
 
BaseQueue operator= (const BaseQueue &)=delete
 
BaseQueue operator= (BaseQueue &)=delete
 
BaseQueue operator= (const BaseQueue &&)=delete
 
BaseQueue operator= (BaseQueue &&)=delete
 

Additional Inherited Members

- Data Fields inherited from LibXR::BaseQueue
uint8_tqueue_array_
 存储队列数据的数组 (Array storing queue data).
 
const uint16_t ELEMENT_SIZE
 每个元素的大小 (Size of each element).
 
size_t head_ = 0
 头部索引 (Head index).
 
size_t tail_ = 0
 尾部索引 (Tail index).
 
bool is_full_ = false
 队列是否已满 (Indicates if the queue is full).
 
size_t length_
 队列最大容量 (Maximum queue capacity).
 

Detailed Description

template<typename Data>
class LibXR::Queue< Data >

基于 BaseQueue 的泛型队列模板类 (Generic queue template class based on BaseQueue).

This class provides a type-safe queue for storing elements of type Data. It supports standard queue operations such as push, pop, peek, and batch operations. 该类提供一个类型安全的队列,用于存储 Data 类型的元素。 它支持标准的队列操作,如推入(Push)、弹出(Pop)、查看(Peek)以及批量操作。

Template Parameters
Data队列存储的数据类型 (Type of data stored in the queue).

Definition at line 353 of file queue.hpp.

Constructor & Destructor Documentation

◆ Queue() [1/2]

template<typename Data >
LibXR::Queue< Data >::Queue ( size_t  length)
inline

构造函数,初始化队列 (Constructor to initialize the queue).

Parameters
length队列的最大容量 (Maximum capacity of the queue).

Definition at line 361 of file queue.hpp.

361: BaseQueue(sizeof(Data), length) {}
BaseQueue(uint16_t element_size, size_t length, uint8_t *buffer)
构造函数,初始化队列 (Constructor to initialize the queue).
Definition queue.hpp:28
constexpr auto min(T1 a, T2 b) -> typename std::common_type< T1, T2 >::type
计算两个数的最小值

◆ Queue() [2/2]

template<typename Data >
LibXR::Queue< Data >::Queue ( size_t  length,
uint8_t buffer 
)
inline

构造函数,初始化队列 (Constructor to initialize the queue).

Parameters
length队列的最大容量 (Maximum capacity of the queue).
buffer指向缓冲区的指针 (Pointer to the buffer).

Definition at line 369 of file queue.hpp.

369: BaseQueue(sizeof(Data), length, buffer) {}

Member Function Documentation

◆ operator[]()

template<typename Data >
Data & LibXR::Queue< Data >::operator[] ( int32_t  index)
inline

访问队列中的元素 (Access an element in the queue).

This function provides indexed access to elements in the queue. If the index is positive, it is relative to head_ (front of the queue). If negative, it is relative to tail_ (end of the queue). 该函数允许使用索引访问队列中的元素。 如果索引为正,则表示从 head_(队列头部)开始的偏移量。 如果索引为负,则表示从 tail_(队列尾部)开始的偏移量。

Parameters
index访问的索引值 (Index to access).
Returns
返回索引对应的元素引用 (Reference to the element at the specified index).

Definition at line 385 of file queue.hpp.

386 {
387 if (index >= 0)
388 {
389 index = (head_ + index) % length_;
390 }
391 else
392 {
393 index = (tail_ + index + length_) % length_;
394 }
395
396 return *reinterpret_cast<Data *>(&queue_array_[index * ELEMENT_SIZE]);
397 }
size_t tail_
尾部索引 (Tail index).
Definition queue.hpp:336
size_t head_
头部索引 (Head index).
Definition queue.hpp:335
size_t length_
队列最大容量 (Maximum queue capacity).
Definition queue.hpp:338
uint8_t * queue_array_
存储队列数据的数组 (Array storing queue data).
Definition queue.hpp:333
const uint16_t ELEMENT_SIZE
每个元素的大小 (Size of each element).
Definition queue.hpp:334

◆ Overwrite()

template<typename Data >
ErrorCode LibXR::Queue< Data >::Overwrite ( const Data data)
inline

覆盖队列中的数据 (Overwrite the queue with new data).

Parameters
data新数据 (New data to overwrite the queue).
Returns
操作结果 (Operation result):
  • ErrorCode::OK 表示成功 (ErrorCode::OK on success).

Definition at line 486 of file queue.hpp.

486{ return BaseQueue::Overwrite(&data); }
ErrorCode Overwrite(const void *data)
覆盖队列中的数据 (Overwrite the queue with new data).
Definition queue.hpp:274

◆ Peek()

template<typename Data >
ErrorCode LibXR::Queue< Data >::Peek ( Data data)
inline

查看队列头部的元素但不移除 (Peek at the front element without removing it).

Parameters
data用于存储查看到的元素的引用 (Reference to store the peeked element).
Returns
操作结果 (Operation result):
  • ErrorCode::OK 表示成功 (ErrorCode::OK on success).
  • ErrorCode::EMPTY 表示队列为空 (ErrorCode::EMPTY if the queue is empty).

Definition at line 436 of file queue.hpp.

436{ return BaseQueue::Peek(&data); }
ErrorCode Peek(void *data)
获取队列头部的元素但不移除 (Peek at the front element without removing it).
Definition queue.hpp:92

◆ PeekBatch()

template<typename Data >
ErrorCode LibXR::Queue< Data >::PeekBatch ( Data data,
size_t  size 
)
inline

批量查看多个元素但不移除 (Peek at multiple elements without removing them).

Parameters
data指向存储数据的数组 (Pointer to the array where peeked elements will be stored).
size要查看的元素个数 (Number of elements to retrieve).
Returns
操作结果 (Operation result):
  • ErrorCode::OK 表示成功 (ErrorCode::OK on success).
  • ErrorCode::EMPTY 表示队列为空 (ErrorCode::EMPTY if the queue is empty).

Definition at line 474 of file queue.hpp.

475 {
476 return BaseQueue::PeekBatch(data, size);
477 }
ErrorCode PeekBatch(void *data, size_t size)
批量获取多个元素但不移除 (Peek at multiple elements without removing them).
Definition queue.hpp:245

◆ Pop() [1/2]

template<typename Data >
ErrorCode LibXR::Queue< Data >::Pop ( )
inline

仅从队列中移除头部元素,不获取数据 (Remove the front element from the queue without retrieving data).

Returns
操作结果 (Operation result):
  • ErrorCode::OK 表示成功 (ErrorCode::OK on success).
  • ErrorCode::EMPTY 表示队列为空 (ErrorCode::EMPTY if the queue is empty).

Definition at line 426 of file queue.hpp.

426{ return BaseQueue::Pop(); }
ErrorCode Pop(void *data=nullptr)
移除队列头部的元素 (Pop the front element from the queue).
Definition queue.hpp:114

◆ Pop() [2/2]

template<typename Data >
ErrorCode LibXR::Queue< Data >::Pop ( Data data)
inline

从队列中移除头部元素,并获取该元素的数据 (Remove the front element from the queue and retrieve its data).

Parameters
data用于存储弹出元素的引用 (Reference to store the popped element).
Returns
操作结果 (Operation result):
  • ErrorCode::OK 表示成功 (ErrorCode::OK on success).
  • ErrorCode::EMPTY 表示队列为空 (ErrorCode::EMPTY if the queue is empty).

Definition at line 417 of file queue.hpp.

417{ return BaseQueue::Pop(&data); }

◆ PopBatch()

template<typename Data >
ErrorCode LibXR::Queue< Data >::PopBatch ( Data data,
size_t  size 
)
inline

批量移除多个元素,并获取数据 (Pop multiple elements from the queue and retrieve data).

Parameters
data指向存储数据的数组 (Pointer to the array where popped elements will be stored).
size要移除的元素个数 (Number of elements to remove).
Returns
操作结果 (Operation result):
  • ErrorCode::OK 表示成功 (ErrorCode::OK on success).
  • ErrorCode::EMPTY 表示队列为空 (ErrorCode::EMPTY if the queue is empty).

Definition at line 462 of file queue.hpp.

462{ return BaseQueue::PopBatch(data, size); }
ErrorCode PopBatch(void *data, size_t size)
批量移除多个元素 (Pop multiple elements from the queue).
Definition queue.hpp:208

◆ Push()

template<typename Data >
ErrorCode LibXR::Queue< Data >::Push ( const Data data)
inline

向队列中添加一个元素 (Push an element into the queue).

Parameters
data要推入的元素 (Element to push).
Returns
操作结果 (Operation result):
  • ErrorCode::OK 表示成功 (ErrorCode::OK on success).
  • ErrorCode::FULL 表示队列已满 (ErrorCode::FULL if the queue is full).

Definition at line 407 of file queue.hpp.

407{ return BaseQueue::Push(&data); }
ErrorCode Push(const void *data)
向队列中添加一个元素 (Push an element into the queue).
Definition queue.hpp:66

◆ PushBatch()

template<typename Data >
ErrorCode LibXR::Queue< Data >::PushBatch ( const Data data,
size_t  size 
)
inline

批量推入多个元素 (Push multiple elements into the queue).

Parameters
data指向数据数组 (Pointer to the array of elements to push).
size要推入的元素个数 (Number of elements to push).
Returns
操作结果 (Operation result):
  • ErrorCode::OK 表示成功 (ErrorCode::OK on success).
  • ErrorCode::FULL 表示队列已满 (ErrorCode::FULL if the queue is full).

Definition at line 447 of file queue.hpp.

448 {
449 return BaseQueue::PushBatch(data, size);
450 }
ErrorCode PushBatch(const void *data, size_t size)
批量推入多个元素 (Push multiple elements into the queue).
Definition queue.hpp:175

The documentation for this class was generated from the following file: