Files
envi-code/SourceCode/Code2026/tg_shs/inc/geo/TSqStack.h
T
2026-09-28 15:28:50 +08:00

137 lines
2.1 KiB
C++

//-------------------------------------------------------------------------------------------------------+
// Copyright (C), 1998-2007, Beijing Tangent Software Co. Ltd.
// = FileName : TSqStack 模板类
// = Version : ver2.0
// = Author : wlw
// = CreateDate : 2002-09-09
// = Description: TSqStack 声明 基于动态数组的堆栈
// = Maintainers:
//
//-------------------------------------------------------------------------------------------------------+
#ifndef _TSQSTACK_H_
#define _TSQSTACK_H_
#ifndef _TSTACK_H_
#include "TStack.h"
#endif
#ifndef _TSQTABLE_H_
#include "TSqTable.h"
#endif
template<class T> class TSqStack: public TStack<T>
{
public:
TSqStack(long autoAllocUnit = 100,long depth = -1);
virtual ~TSqStack();
virtual void Clear();
virtual void GoBack();
virtual void GoAhead();
virtual bool Pop(T&t);
virtual bool Push(T const&t);
virtual bool GetTopData(T&t);
virtual long GetDepth();
virtual T& operator[](long i);
protected:
TSqTable<T> table;
};
template<class T>
TSqStack<T>::~TSqStack()
{
}
template<class T>
virtual T& TSqStack<T>::operator[](long i)
{
return table[i];
}
template<class T>
TSqStack<T>::TSqStack(long autoAllocUnit,long depth)
:TStack<T>(depth),table(autoAllocUnit,autoAllocUnit)
{
}
template<class T>
bool TSqStack<T>::Push(T const&t)
{
if(this->IsDepthLimited() && this->GetDepth() >= this->maxDepth)
{
return false;
}
table[table.GetCur()+1] = t;
this->oldDepth = GetDepth();
return true;
}
template<class T>
bool TSqStack<T>::Pop(T&t)
{
if(this->IsEmpty())
{
return false;
}
t = table.GetCurData();
table.MoveToPre();
return true;
}
template<class T>
bool TSqStack<T>::GetTopData(T&t)
{
if(this->IsEmpty())
{
return false;
}
t = table.GetCurData();
return true;
}
template<class T>
void TSqStack<T>::Clear()
{
table.Clear();
this->oldDepth = 0;
}
template<class T>
long TSqStack<T>::GetDepth()
{
return table.GetCur()+1;
}
template<class T>
void TSqStack<T>::GoBack()
{
if(this->CanGoBack())
{
table.MoveToPre();
}
}
template<class T>
void TSqStack<T>::GoAhead()
{
if(this->CanGoAhead())
{
table.MoveToNext();
}
}
#endif