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