//-------------------------------------------------------------------------------------------------------+ // Copyright (C), 1998-2007, Beijing Tangent Software Co. Ltd. // = FileName : TListQuene 模板类 // = Version : ver2.0 // = Author : wlw // = CreateDate : 2002-09-09 // = Description: TListQuene 声明 基于单向链表的队列 // = Maintainers: // //-------------------------------------------------------------------------------------------------------+ #ifndef _TLISTQUENE_H_ #define _TLISTQUENE_H_ #ifndef _TQUENE_H_ #include "TQuene.h" #endif #ifndef _TLIST_H_ #include "TList.h" #endif template class TListQuene:public TQuene { public: TListQuene(long length = -1); virtual ~TListQuene(); //如quene为空,忽略并返回 false virtual bool DeQuene(T&t); //如果超过maxLength,忽略并返回 false virtual bool EnQuene(T const&t); virtual void Clear(); virtual long GetLength(); virtual bool GetHeadData(T&t); virtual bool GetTailData(T&t); virtual T& operator[](long i); protected: TList list; }; template TListQuene::TListQuene(long length):TQuene(length) { } template TListQuene::~TListQuene() { } template T& TListQuene::operator[](long i) { return list[i]; } template bool TListQuene::DeQuene(T&t) { if (this->IsEmpty()) { return false; } list.MoveToFirst(); t = list.GetCurData(); list.DelCur(); return true; } template bool TListQuene::EnQuene(T const&t) { if (this->IsLengthLimited() && GetLength() >= this->maxLength) { return false; } list.AddTail(t); return true; } template long TListQuene::GetLength() { return list.GetLength(); } template bool TListQuene::GetHeadData(T&t) { if (this->IsEmpty()) { return false; } list.MoveToFirst(); t = list.GetCurData(); return true; } template bool TListQuene::GetTailData(T&t) { if (this->IsEmpty()) { return false; } list.MoveToLast(); t = list.GetCurData(); return true; } template void TListQuene::Clear() { list.Clear(); } #endif