//-----------------------------------------------------------------------------+ // 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 TLoopList : public TDPtrList { 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 TLoopList::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 R * TLoopList::operator [](int n) { int nLen=this->Length(); n = _LimitCycle(n, nLen); return TDPtrList::operator[](n); } template const R & TLoopList::operator [](int n) const { int nLen=this->Length(); n = _LimitCycle(n, nLen); const TDPtrList &rThis=*this; return rThis[n]; } template R * TLoopList::GetAt(int n) { int nLen = this->Length(); n = _LimitCycle(n, nLen); return TDPtrList::GetAt(n); } template const R & TLoopList::GetAt(int n) const { int nLen = this->Length(); n = _LimitCycle(n, nLen); const TDPtrList &rThis = *this; return rThis.GetAt(n); } template void TLoopList::RemoveNode(int n) { (*this)[n]; this->Remove(); } #endif