|
libxr
1.0
Want to be the best embedded framework
|
线程安全的栈数据结构 / Thread-safe stack data structure More...
#include <stack.hpp>
Public Member Functions | |
| Stack (uint32_t depth) | |
| 栈的构造函数 / Stack constructor | |
| Data & | operator[] (int32_t index) |
| 获取指定索引的元素 / Retrieves the element at a specified index | |
| uint32_t | Size () const |
| 获取栈中当前元素数量 / Returns the number of elements currently in the stack | |
| uint32_t | EmptySize () const |
| 获取栈的剩余可用空间 / Returns the remaining available space in the stack | |
| ErrorCode | Push (const Data &data) |
| 向栈中推入数据 / Pushes data onto the stack | |
| ErrorCode | Pop (Data &data) |
| 从栈中弹出数据 / Pops data from the stack | |
| ErrorCode | Pop () |
| 从栈中弹出数据(不返回数据) / Pops data from the stack (without returning data) | |
| ErrorCode | Peek (Data &data) |
| 获取栈顶数据但不弹出 / Retrieves the top data of the stack without popping | |
| ErrorCode | Insert (const Data &data, uint32_t index) |
| 在指定位置插入数据 / Inserts data at a specified position | |
| ErrorCode | Delete (uint32_t index) |
| 删除指定位置的数据 / Deletes data at a specified position | |
| void | Reset () |
| 重置栈 / Resets the stack | |
Private Attributes | |
| Data * | stack_ |
| 栈存储数组 / Stack storage array | |
| uint32_t | top_ = 0 |
| 当前栈顶索引 / Current top index of the stack | |
| uint32_t | depth_ |
| 栈的最大容量 / Maximum capacity of the stack | |
| LibXR::Mutex | mutex_ |
| 互斥锁,确保线程安全 / Mutex to ensure thread safety | |
线程安全的栈数据结构 / Thread-safe stack data structure
该类实现了一个基于数组的线程安全栈,支持基本的 Push、Pop、Peek 等操作,并使用互斥锁 (Mutex) 保护数据安全。 This class implements a thread-safe stack based on an array, supporting basic operations such as Push, Pop, and Peek, with mutex (Mutex) protection to ensure data safety.
| Data | 栈中存储的数据类型 / The type of data stored in the stack |
|
inline |
|
inline |
删除指定位置的数据 / Deletes data at a specified position
| index | 要删除的索引位置 / Index of the data to be deleted |
ErrorCode::OK,索引超出范围返回 ErrorCode::OUT_OF_RANGE / Operation result: returns ErrorCode::OK on success, ErrorCode::OUT_OF_RANGE if the index is out of range Definition at line 197 of file stack.hpp.
|
inlinenodiscard |
|
inline |
在指定位置插入数据 / Inserts data at a specified position
| data | 要插入的数据 / The data to be inserted |
| index | 插入位置索引 / Index at which the data is inserted |
ErrorCode::OK,栈满返回 ErrorCode::FULL,索引超出范围返回 ErrorCode::OUT_OF_RANGE / Operation result: returns ErrorCode::OK on success, ErrorCode::FULL if the stack is full, ErrorCode::OUT_OF_RANGE if the index is out of range
|
inline |
获取指定索引的元素 / Retrieves the element at a specified index
| index | 元素索引,支持负索引(从栈顶向下索引) / Element index, supports negative indexing (relative to the top) |
|
inline |
获取栈顶数据但不弹出 / Retrieves the top data of the stack without popping
| data | 用于存储栈顶数据 / Variable to store the retrieved data |
ErrorCode::OK,栈为空返回 ErrorCode::EMPTY / Operation result: returns ErrorCode::OK on success, ErrorCode::EMPTY if the stack is empty
|
inline |
从栈中弹出数据(不返回数据) / Pops data from the stack (without returning data)
ErrorCode::OK,栈为空返回 ErrorCode::EMPTY / Operation result: returns ErrorCode::OK on success, ErrorCode::EMPTY if the stack is empty
|
inline |
从栈中弹出数据 / Pops data from the stack
| data | 用于存储弹出的数据 / Variable to store the popped data |
ErrorCode::OK,栈为空返回 ErrorCode::EMPTY / Operation result: returns ErrorCode::OK on success, ErrorCode::EMPTY if the stack is empty
|
inline |
向栈中推入数据 / Pushes data onto the stack
| data | 要推入的元素 / The element to be pushed |
ErrorCode::OK,栈满返回 ErrorCode::FULL / Operation result: returns ErrorCode::OK on success, ErrorCode::FULL if the stack is full
|
inline |
|
inlinenodiscard |
|
private |
|
private |
|
private |
|
private |