113 lines
1.5 KiB
C++
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];
|
|
}
|
|
|