//-------------------------------------------------------------------------------------------------------+ // Copyright (C), 1998-2007, Beijing Tangent Software Co. Ltd. // = FileName : TPDListQuene 模板类 // = Version : ver2.0 // = Author : wlw // = CreateDate : 2002-09-09 // = Description: TPDListQuene 声明 基于双向指针链表的队列,内存外部分配,外部释放,也可自动清理 // = Maintainers: // //-------------------------------------------------------------------------------------------------------+ #ifndef _TPDLISTQUENE_H_ #define _TPDLISTQUENE_H_ #ifndef _TQUENE_H_ #include "TQuene.h" #endif #ifndef _TPDLIST_H_ #include "TPDList.h" #endif template class TPDListQuene:public TQuene { public: TPDListQuene(long length = -1); virtual ~TPDListQuene(); virtual bool DeQuene(T*& t); 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); bool GetHeadData(T &t); bool GetTailData(T &t); protected: TPDList list; }; template TPDListQuene::TPDListQuene(long length):TQuene(length) { } template TPDListQuene::~TPDListQuene() { } template T*& TPDListQuene::operator[](long i) { return list[i]; } template bool TPDListQuene::DeQuene(T*& t) { if (this->IsEmpty()) { return false; } list.MoveToFirst(); t = list.GetCurData(); list.SetCurData(NULL); list.DelCur(); return true; } template bool TPDListQuene::EnQuene(T* const&t) { if (this->IsLengthLimited() && GetLength() >= this->maxLength) { return false; } list.AddTail(t); return true; } template long TPDListQuene::GetLength() { return list.GetLength(); } template bool TPDListQuene::GetHeadData(T*& t) { if (this->IsEmpty()) { return false; } list.MoveToFirst(); t = list.GetCurData(); return true; } template bool TPDListQuene::GetTailData(T*& t) { if (this->IsEmpty()) { return false; } list.MoveToLast(); t = list.GetCurData(); return true; } template bool TPDListQuene::GetHeadData(T&t) { if (this->IsEmpty()) { return false; } list.MoveToFirst(); t = *(list.GetCurData()); return true; } template bool TPDListQuene::GetTailData(T&t) { if (this->IsEmpty()) { return false; } list.MoveToLast(); t = *(list.GetCurData()); return true; } template void TPDListQuene::Clear() { list.Clear(); } #endif