107 lines
1.6 KiB
C++
107 lines
1.6 KiB
C++
//-------------------------------------------------------------------------------------------------------+
|
|
// 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 T> 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<class T>
|
|
TStack<T>::TStack(long depth)
|
|
{
|
|
maxDepth = depth;
|
|
oldDepth = 0;
|
|
}
|
|
|
|
template<class T>
|
|
TStack<T>::~TStack()
|
|
{
|
|
|
|
}
|
|
|
|
template<class T>
|
|
void TStack<T>::SetMaxDepth(long depth)
|
|
{
|
|
maxDepth = depth;
|
|
}
|
|
|
|
template<class T>
|
|
long TStack<T>::GetMaxDepth()
|
|
{
|
|
return maxDepth;
|
|
}
|
|
|
|
template<class T>
|
|
bool TStack<T>::IsDepthLimited()
|
|
{
|
|
return maxDepth >= 0;
|
|
}
|
|
|
|
template<class T>
|
|
bool TStack<T>::IsEmpty()
|
|
{
|
|
return GetDepth() == 0;
|
|
}
|
|
|
|
template<class T>
|
|
bool TStack<T>::CanGoBack()
|
|
{
|
|
return !IsEmpty();
|
|
}
|
|
|
|
template<class T>
|
|
bool TStack<T>::CanGoAhead()
|
|
{
|
|
return oldDepth > GetDepth();
|
|
}
|
|
|
|
#endif
|