153 lines
2.5 KiB
C++
153 lines
2.5 KiB
C++
//-------------------------------------------------------------------------------------------------------+
|
|
// 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 T> class TPDListQuene:public TQuene<T*>
|
|
{
|
|
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<T> list;
|
|
|
|
};
|
|
|
|
template<class T>
|
|
TPDListQuene<T>::TPDListQuene(long length):TQuene<T*>(length)
|
|
{
|
|
|
|
}
|
|
|
|
template<class T>
|
|
TPDListQuene<T>::~TPDListQuene()
|
|
{
|
|
|
|
}
|
|
|
|
template<class T>
|
|
T*& TPDListQuene<T>::operator[](long i)
|
|
{
|
|
return list[i];
|
|
}
|
|
|
|
template<class T>
|
|
bool TPDListQuene<T>::DeQuene(T*& t)
|
|
{
|
|
if (this->IsEmpty())
|
|
{
|
|
return false;
|
|
}
|
|
list.MoveToFirst();
|
|
t = list.GetCurData();
|
|
list.SetCurData(NULL);
|
|
list.DelCur();
|
|
return true;
|
|
}
|
|
|
|
template<class T>
|
|
bool TPDListQuene<T>::EnQuene(T* const&t)
|
|
{
|
|
if (this->IsLengthLimited() && GetLength() >= this->maxLength)
|
|
{
|
|
return false;
|
|
}
|
|
list.AddTail(t);
|
|
return true;
|
|
}
|
|
|
|
template<class T>
|
|
long TPDListQuene<T>::GetLength()
|
|
{
|
|
return list.GetLength();
|
|
}
|
|
|
|
template<class T>
|
|
bool TPDListQuene<T>::GetHeadData(T*& t)
|
|
{
|
|
if (this->IsEmpty())
|
|
{
|
|
return false;
|
|
}
|
|
|
|
list.MoveToFirst();
|
|
t = list.GetCurData();
|
|
return true;
|
|
}
|
|
|
|
template<class T>
|
|
bool TPDListQuene<T>::GetTailData(T*& t)
|
|
{
|
|
if (this->IsEmpty())
|
|
{
|
|
return false;
|
|
}
|
|
|
|
list.MoveToLast();
|
|
t = list.GetCurData();
|
|
return true;
|
|
}
|
|
|
|
template<class T>
|
|
bool TPDListQuene<T>::GetHeadData(T&t)
|
|
{
|
|
if (this->IsEmpty())
|
|
{
|
|
return false;
|
|
}
|
|
|
|
list.MoveToFirst();
|
|
t = *(list.GetCurData());
|
|
return true;
|
|
}
|
|
|
|
template<class T>
|
|
bool TPDListQuene<T>::GetTailData(T&t)
|
|
{
|
|
if (this->IsEmpty())
|
|
{
|
|
return false;
|
|
}
|
|
|
|
list.MoveToLast();
|
|
t = *(list.GetCurData());
|
|
return true;
|
|
}
|
|
|
|
template<class T>
|
|
void TPDListQuene<T>::Clear()
|
|
{
|
|
list.Clear();
|
|
}
|
|
|
|
#endif
|