//-------------------------------------------------------------------------------------------------------+ // Copyright (C), 1998-2007, Beijing Tangent Software Co. Ltd. // = FileName : TStack 模板类 // = Version : ver2.0 // = Author : wlw // = CreateDate : 2002-09-09 // = Description: TStack 声明 堆栈抽象类 // = Maintainers: // //-------------------------------------------------------------------------------------------------------+ #ifndef _TSTACK_H_ #define _TSTACK_H_ template class TStack { public: TStack(long depth = -1); virtual ~TStack(); 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 TStack::TStack(long depth) { maxDepth = depth; oldDepth = 0; } template TStack::~TStack() { } template void TStack::SetMaxDepth(long depth) { maxDepth = depth; } template long TStack::GetMaxDepth() { return maxDepth; } template bool TStack::IsDepthLimited() { return maxDepth >= 0; } template bool TStack::IsEmpty() { return GetDepth() == 0; } template bool TStack::CanGoBack() { return !IsEmpty(); } template bool TStack::CanGoAhead() { return oldDepth > GetDepth(); } #endif