109 lines
1.7 KiB
C++
109 lines
1.7 KiB
C++
//-----------------------------------------------------------------------------+
|
|
// Copyright (C), 1998-2007, Beijing Tangent Software Co. Ltd.
|
|
// = FileName : TLoopList Ä£°åÀà
|
|
// = Version : ver2.0
|
|
// = Author : wlw
|
|
// = CreateDate : 2002-09-09
|
|
// = Description: TLoopList ÉùÃ÷
|
|
// = Maintainers:
|
|
//
|
|
//-----------------------------------------------------------------------------+
|
|
#ifndef _TLOOPLIST_H_
|
|
#define _TLOOPLIST_H_
|
|
|
|
#ifndef _TDPTRLIST_H_
|
|
#include "TDPtrList.h"
|
|
#endif
|
|
|
|
template <class R>
|
|
class TLoopList : public TDPtrList<R>
|
|
{
|
|
public:
|
|
|
|
TLoopList();
|
|
~TLoopList(){}
|
|
|
|
R * operator [](int n);
|
|
|
|
const R & operator [](int n) const;
|
|
|
|
|
|
const R & GetAt(int n) const;
|
|
R * GetAt(int n);
|
|
|
|
void RemoveNode(int n);
|
|
|
|
};
|
|
|
|
template <class R>
|
|
TLoopList<R>::TLoopList()
|
|
{
|
|
|
|
}
|
|
|
|
namespace
|
|
{
|
|
int _LimitCycle(int n, int nLen)
|
|
{
|
|
if (n < 0)
|
|
{
|
|
n += nLen;
|
|
}
|
|
else if (n >= nLen)
|
|
{
|
|
n -= nLen;
|
|
}
|
|
else
|
|
{
|
|
return n;
|
|
}
|
|
|
|
return _LimitCycle(n, nLen);
|
|
}
|
|
|
|
}
|
|
|
|
template <class R>
|
|
R * TLoopList<R>::operator [](int n)
|
|
{
|
|
int nLen=this->Length();
|
|
n = _LimitCycle(n, nLen);
|
|
return TDPtrList<R>::operator[](n);
|
|
}
|
|
|
|
template <class R>
|
|
const R & TLoopList<R>::operator [](int n) const
|
|
{
|
|
int nLen=this->Length();
|
|
n = _LimitCycle(n, nLen);
|
|
const TDPtrList<R> &rThis=*this;
|
|
return rThis[n];
|
|
}
|
|
|
|
template <class R>
|
|
R * TLoopList<R>::GetAt(int n)
|
|
{
|
|
int nLen = this->Length();
|
|
n = _LimitCycle(n, nLen);
|
|
return TDPtrList<R>::GetAt(n);
|
|
}
|
|
|
|
template <class R>
|
|
const R & TLoopList<R>::GetAt(int n) const
|
|
{
|
|
int nLen = this->Length();
|
|
n = _LimitCycle(n, nLen);
|
|
const TDPtrList<R> &rThis = *this;
|
|
return rThis.GetAt(n);
|
|
}
|
|
|
|
template <class R>
|
|
void TLoopList<R>::RemoveNode(int n)
|
|
{
|
|
(*this)[n];
|
|
this->Remove();
|
|
}
|
|
|
|
|
|
#endif
|