5#include "libxr_def.hpp"
21template <
typename Data>
47 ASSERT(
static_cast<uint32_t
>(index) <
depth_);
52 ASSERT(
static_cast<int32_t
>(
depth_) + index >= 0);
60 [[nodiscard]] uint32_t
Size()
const {
return top_; }
74 ErrorCode
Push(
const Data &data)
81 return ErrorCode::FULL;
95 ErrorCode
Pop(Data &data)
102 return ErrorCode::EMPTY;
106 return ErrorCode::OK;
123 return ErrorCode::EMPTY;
127 return ErrorCode::OK;
145 return ErrorCode::EMPTY;
150 return ErrorCode::OK;
162 ErrorCode
Insert(
const Data &data, uint32_t index)
168 return ErrorCode::FULL;
174 return ErrorCode::OUT_OF_RANGE;
184 return ErrorCode::OK;
200 return ErrorCode::OUT_OF_RANGE;
203 for (uint32_t i = index; i <
top_ - 1; i++)
209 return ErrorCode::OK;
互斥锁类,提供线程同步机制 (Mutex class providing thread synchronization mechanisms).
ErrorCode Lock()
加锁,如果锁已被占用,则阻塞等待 (Lock the mutex, blocking if it is already locked).
void Unlock()
解锁互斥锁 (Unlock the mutex).
线程安全的栈数据结构 / Thread-safe stack data structure
ErrorCode Delete(uint32_t index)
删除指定位置的数据 / Deletes data at a specified position
uint32_t EmptySize() const
获取栈的剩余可用空间 / Returns the remaining available space in the stack
ErrorCode Peek(Data &data)
获取栈顶数据但不弹出 / Retrieves the top data of the stack without popping
uint32_t depth_
栈的最大容量 / Maximum capacity of the stack
Data & operator[](int32_t index)
获取指定索引的元素 / Retrieves the element at a specified index
ErrorCode Insert(const Data &data, uint32_t index)
在指定位置插入数据 / Inserts data at a specified position
void Reset()
重置栈 / Resets the stack
Data * stack_
栈存储数组 / Stack storage array
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)
uint32_t top_
当前栈顶索引 / Current top index of the stack
LibXR::Mutex mutex_
互斥锁,确保线程安全 / Mutex to ensure thread safety
Stack(uint32_t depth)
栈的构造函数 / Stack constructor
uint32_t Size() const
获取栈中当前元素数量 / Returns the number of elements currently in the stack