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