Files
envi-code/SourceCode/Code2026/Dimension/DListStack.h
T
gjm 164968b62e chore
把非utf8-bom编码的cpp/h文件改为 utf8 bom 编码, msvc识别utf8编码时,如果不是bom格式的,会使用当前cp_oem来解码.
2026-10-04 00:04:20 +08:00

113 lines
1.5 KiB
C++

#pragma once
#include "SHStack.h"
#include "DualPtrList.h"
template<class T> class DListStack : public SHStack< T >
{
public:
DListStack(long depth = -1);
virtual ~DListStack();
virtual bool Pop(T&t);
virtual bool Push(T const&t);
virtual void Clear();
virtual bool GetTopData(T&t);
virtual long GetDepth();
virtual T& operator[](long i);
virtual void GoBack();
virtual void GoAhead();
protected:
DualPtrList<T> list;
};
template<class T>
DListStack<T>::DListStack(long depth) : SHStack<T>(depth)
{
}
template<class T>
DListStack<T>::~DListStack()
{
}
template<class T>
bool DListStack<T>::Push(T const&t)
{
if(this->IsDepthLimited() && GetDepth() >= this->maxDepth)
{
return false;
}
list[list.GetCur()+1] = t;
this->oldDepth = GetDepth();
return true;
}
template<class T>
bool DListStack<T>::Pop(T&t)
{
if(this->IsEmpty())
{
return false;
}
t = list.GetCurData();
list.DelCur();
this->oldDepth = GetDepth();
return true;
}
template<class T>
bool DListStack<T>::GetTopData(T&t)
{
if(this->IsEmpty())
{
return false;
}
t = list.GetCurData();
return true;
}
template<class T>
void DListStack<T>::Clear()
{
list.Clear();
this->oldDepth = 0;
}
template<class T>
long DListStack<T>::GetDepth()
{
return list.GetCur() + 1;
}
template<class T>
void DListStack<T>::GoBack()
{
if(this->CanGoBack())
{
list.MoveToPre();
}
}
template<class T>
void DListStack<T>::GoAhead()
{
if(this->CanGoAhead())
{
list.MoveToNext();
}
}
template<class T>
T& DListStack<T>::operator[](long i)
{
return list[i];
}