Files
envi-code/SourceCode/Code2026/PipelineCmd/SysLayerCfg/TListQuene.h
T
2026-09-28 15:28:50 +08:00

128 lines
2.1 KiB
C++

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