5#include "libxr_def.hpp"
21template <
typename Data>
50 ASSERT(
static_cast<uint32_t
>(index) <
depth_);
55 ASSERT(
static_cast<int32_t
>(
depth_) + index >= 0);
63 [[nodiscard]] uint32_t
Size()
const {
return top_; }
77 ErrorCode
Push(
const Data& data)
84 return ErrorCode::FULL;
98 ErrorCode
Pop(Data& data)
105 return ErrorCode::EMPTY;
109 return ErrorCode::OK;
126 return ErrorCode::EMPTY;
130 return ErrorCode::OK;
148 return ErrorCode::EMPTY;
153 return ErrorCode::OK;
165 ErrorCode
Insert(
const Data& data, uint32_t index)
171 return ErrorCode::FULL;
177 return ErrorCode::OUT_OF_RANGE;
187 return ErrorCode::OK;
203 return ErrorCode::OUT_OF_RANGE;
206 for (uint32_t i = index; i <
top_ - 1; i++)
212 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