#pragma once #include "superList.h" template class SHLoopList : public PtrList { public: SHLoopList(); ~SHLoopList(){} R * operator [](int n); const R & operator [](int n) const; const R & GetAt(int n) const; R * GetAt(int n); void RemoveNode(int n); }; 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 SHLoopList::SHLoopList() { } template R * SHLoopList::operator [](int n) { int nLen=this->Length(); n = LimitCycle(n, nLen); return PtrList::operator[](n); } template const R & SHLoopList::operator [](int n) const { int nLen=this->Length(); n = LimitCycle(n, nLen); const PtrList &rThis=*this; return rThis[n]; } template R * SHLoopList::GetAt(int n) { int nLen = this->Length(); n = LimitCycle(n, nLen); return PtrList::GetAt(n); } template const R & SHLoopList::GetAt(int n) const { int nLen = this->Length(); n = LimitCycle(n, nLen); const PtrList &rThis = *this; return rThis.GetAt(n); } template void SHLoopList::RemoveNode(int n) { (*this)[n]; this->Remove(); }