Files
envi-code/SourceCode/Code2026/inc/AdsXRx/DListStack.h
T
2026-09-28 15:28:50 +08:00

131 lines
2.1 KiB
C++

//-------------------------------------------------------------------------------------------------------+
// Copyright (C), 1998-2007, SH Software Co. Ltd.
// = FileName : DListStack 模板类
// = Version : ver2.0
// = Author : zjq
// = CreateDate : 2002-09-09
// = Description: DListStack 声明 基于双向链表的堆栈
// = Maintainers:
//
//-------------------------------------------------------------------------------------------------------+
#ifndef _DLISTSTACK_H_
#define _DLISTSTACK_H_
#ifndef _STACK_H_
#include "Stack.h"
#endif
#ifndef _DUALLIST_H_
#include "DualList.h"
#endif
template<class T> class DListStack : public Stack< 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:
DualList<T> list;
};
template<class T>
DListStack<T>::DListStack(long depth) : Stack<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];
}
#endif