Files
envi-code/SourceCode/Code2026/tg_shs/inc/subgeo/TPGeGDList.h
T

198 lines
3.6 KiB
C++
Raw Normal View History

2026-10-04 00:04:20 +08:00
//-----------------------------------------------------------------------------+
2026-09-28 15:28:50 +08:00
// Copyright (C), 1998-2007, Beijing Tangent Software Co. Ltd.
// = FileName : TPGeGDList.h
// = Version : ver2.0
// = Author : xlc
// = CreateDate : 2002-09-09
2026-10-04 00:04:20 +08:00
// = Description: 类的声明 双向递归链
2026-09-28 15:28:50 +08:00
// = Maintainers:
//
//-----------------------------------------------------------------------------+
#ifndef _TPGEGDLIST_H_
#define _TPGEGDLIST_H_
#ifndef _TPGEGLIST_H_
#include "TPGeGList.h"
#endif
template<class T> class TPGeGDList : public TPGeGList<T>
{
public:
TPGeGDList();
//pList!=NULL!!!
virtual void CNNext(TPGeGDList*pList);
virtual void DCNNext();
2026-10-04 00:04:20 +08:00
//释放所有前面结点,本结点成为起始结点
2026-09-28 15:28:50 +08:00
void ReleaseAllPre();
TPGeGDList<T>*Next() const;
TPGeGDList<T>*Pre() const;
TPGeGDList<T>* GetTail() const;
2026-10-04 00:04:20 +08:00
//如果是环路GetTail与GetHead结果相同
2026-09-28 15:28:50 +08:00
TPGeGDList<T>* GetHead() const;
TPGeGDList<T>* GetAt(long i) const;
const T& GetData(long i) const;
void DCNPre();
void SetPre(TPGeGDList<T>* pList) const;
2026-10-04 00:04:20 +08:00
//安全转接,自动断开所有原相关链接,pList!=NULL!!!
2026-09-28 15:28:50 +08:00
void CNPre(TPGeGDList*pList);
TPGeGDList<T>* FetchNext(long num = 1);
2026-10-04 00:04:20 +08:00
//返回新链首,如果本结点非链首,将在本结点处形成分叉!如果是环路将保持环路
2026-09-28 15:28:50 +08:00
TPGeGDList<T>* Reverse();
protected:
TPGeGDList* pre;
};
template<class T>
TPGeGDList<T>::TPGeGDList() : pre(NULL)
{
}
template<class T>
TPGeGDList<T>* TPGeGDList<T>::Next() const
{
return (TPGeGDList<T>*)this->next;
}
template<class T>
TPGeGDList<T>* TPGeGDList<T>::Pre() const
{
return pre;
}
template<class T>
TPGeGDList<T>* TPGeGDList<T>::GetTail() const
{
return (TPGeGDList<T>*)(TPGeGList<T>::GetTail());
}
template<class T>
const T& TPGeGDList<T>::GetData(long i) const
{
return GetAt(i)->GetData();
}
template<class T>
void TPGeGDList<T>::SetPre(TPGeGDList<T>* pList) const
2026-10-04 00:04:20 +08:00
{//一般不使用!
2026-09-28 15:28:50 +08:00
pre = pList;
}
template<class T>
void TPGeGDList<T>::DCNNext()
{
if (this->next != NULL)
{
this->next->SetPre(NULL);
this->next = NULL;
}
}
template<class T>
void TPGeGDList<T>::DCNPre()
{
if(pre != NULL)
{
pre->SetNext(NULL);
pre = NULL;
}
}
template<class T>
TPGeGDList<T>* TPGeGDList<T>::FetchNext(long num/* = 1*/)
{
return (TPGeGDList<T>*)(TPGeGList<T>::FetchNext(num));
}
template<class T>
void TPGeGDList<T>::CNNext(TPGeGDList*pList)
{
DCNNext();
pList->DCNPre();
this->SetNext(pList);
pList->SetPre(this);
}
template<class T>
void TPGeGDList<T>::CNPre(TPGeGDList*pList)
{
DCNPre();
pList->DCNNext();
SetPre(pList);
pList->SetNext(this);
}
template<class T>
TPGeGDList<T>* TPGeGDList<T>::GetHead() const
{
for(const TPGeGDList<T>*pCur = this; pCur->Pre() != NULL && pCur->Pre() != this; pCur = pCur->Pre());
return (TPGeGDList<T>*)this->pCur;
}
template<class T>
TPGeGDList<T>* TPGeGDList<T>::GetAt(long i) const
{
if(i >= 0)
{
return (TPGeGDList<T>*)(TPGeGList<T>::GetAt(i));
}
else
{
long count = 1;
for(TPGeGDList<T>*pCur = Pre(); count< -i && pCur != NULL; count++, pCur = pCur->Pre());
return this->pCur;
}
}
template<class T>
void TPGeGDList<T>::ReleaseAllPre()
{
TPGeGDList<T>* pHead = GetHead();
DCNPre();
delete pHead;
}
template<class T>
TPGeGDList<T>* TPGeGDList<T>::Reverse()
{
TPGeGDList<T> *pPre = this,*pCur = Next();
while(pCur != NULL && pCur != this)
{
TPGeGDList<T>* temp = pCur->Next();
pCur->SetNext(pPre);
pPre->SetPre(pCur);
pPre = pCur;
pCur = temp;
}
if(pCur == NULL)
{
this->SetNext(NULL);
pPre->SetPre(NULL);
return pPre;
}
else
{
this->SetNext(pPre);
pPre->SetPre(this);
return this;
}
}
#endif