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