94 lines
1.2 KiB
C++
94 lines
1.2 KiB
C++
#pragma once
|
|
template<class T> class SHStack
|
|
{
|
|
public:
|
|
|
|
SHStack(long depth = -1);
|
|
|
|
virtual ~SHStack();
|
|
|
|
virtual bool Pop(T&t) = 0;
|
|
|
|
virtual bool Push(T const&t) = 0;
|
|
|
|
virtual void GoBack() = 0;
|
|
|
|
virtual void GoAhead() = 0;
|
|
|
|
virtual void Clear() = 0;
|
|
|
|
virtual long GetDepth() = 0;
|
|
|
|
virtual bool GetTopData(T&t) = 0;
|
|
|
|
virtual T& operator[](long i) = 0;
|
|
|
|
void SetMaxDepth(long depth);
|
|
|
|
long GetMaxDepth();
|
|
|
|
bool IsDepthLimited();
|
|
|
|
bool IsEmpty();
|
|
|
|
bool CanGoBack();
|
|
|
|
bool CanGoAhead();
|
|
|
|
protected:
|
|
|
|
long maxDepth;
|
|
|
|
long oldDepth;
|
|
};
|
|
|
|
template<class T>
|
|
SHStack<T>::SHStack(long depth)
|
|
{
|
|
maxDepth = depth;
|
|
oldDepth = 0;
|
|
}
|
|
|
|
template<class T>
|
|
SHStack<T>::~SHStack()
|
|
{
|
|
|
|
}
|
|
|
|
template<class T>
|
|
void SHStack<T>::SetMaxDepth(long depth)
|
|
{
|
|
maxDepth = depth;
|
|
}
|
|
|
|
template<class T>
|
|
long SHStack<T>::GetMaxDepth()
|
|
{
|
|
return maxDepth;
|
|
}
|
|
|
|
template<class T>
|
|
bool SHStack<T>::IsDepthLimited()
|
|
{
|
|
return maxDepth >= 0;
|
|
}
|
|
|
|
template<class T>
|
|
bool SHStack<T>::IsEmpty()
|
|
{
|
|
return GetDepth() == 0;
|
|
}
|
|
|
|
template<class T>
|
|
bool SHStack<T>::CanGoBack()
|
|
{
|
|
return !IsEmpty();
|
|
}
|
|
|
|
template<class T>
|
|
bool SHStack<T>::CanGoAhead()
|
|
{
|
|
return oldDepth > GetDepth();
|
|
}
|
|
|