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