//-------------------------------------------------------------------------------------------------------+ // Copyright (C), 1998-2007, SH Software Co. Ltd. // = FileName : PDListStack 模板类 // = Version : ver2.0 // = Author : zjq // = CreateDate : 2002-09-09 // = Description: PDListStack 声明 基于双向指针链表的堆栈,内存外部分配,外部释放,也可自动清理 // = Maintainers: // //-------------------------------------------------------------------------------------------------------+ #ifndef _PDLISTSTACK_H_ #define _PDLISTSTACK_H_ #ifndef _STACK_H_ #include "Stack.h" #endif #ifndef _PDLIST_H_ #include "PDList.h" #endif template class PDListStack: public Stack { public: PDListStack(long depth=-1); virtual ~PDListStack(); virtual bool Pop(T*& t); virtual bool Push(T* const& t); virtual void Clear(); bool GetTopData(T& t); virtual bool GetTopData(T*& t); virtual long GetDepth(); virtual T*& operator[](long i); virtual void GoBack(); virtual void GoAhead(); protected: PDList list; }; template PDListStack::~PDListStack() { } template T*& PDListStack::operator[](long i) { return list[i]; } template PDListStack::PDListStack(long depth):Stack(depth) { } template bool PDListStack::Push(T* const& t) { if(this->IsDepthLimited() && GetDepth() >= this->maxDepth) { return false; } list[list.GetCur()+1] = t; this->oldDepth = GetDepth(); return true; } template bool PDListStack::Pop(T*& t) { if(this->IsEmpty()) { return false; } t = list.GetCurData(); list.SetCurData(NULL); list.DelCur(); this->oldDepth = GetDepth(); return true; } template bool PDListStack::GetTopData(T*& t) { if(this->IsEmpty()) { return false; } t = list.GetCurData(); return true; } template bool PDListStack::GetTopData(T& t) { if(this->IsEmpty()) { return false; } t = *(list.GetCurData()); return true; } template void PDListStack::Clear() { list.Clear(); this->oldDepth = 0; } template long PDListStack::GetDepth() { return list.GetCur()+1; } template void PDListStack::GoBack() { if(this->CanGoBack()) { list.MoveToPre(); } } template void PDListStack::GoAhead() { if(this->CanGoAhead()) { list.MoveToNext(); } } #endif