#include "StdAfx.h" #include "CLink.h" CLink::CLink() { mNext = NULL; mPrev = NULL; } CLink::CLink(CLink* prev) { mNext = NULL; mPrev = prev; if (prev) prev->SetNext(this); } /*virtual*/ CLink::~CLink() { } void CLink::InsertAt(CLink* before) { if (!mNext) { mNext = before; if (before) before->mPrev = this; } else { CLink *tmp = mNext; mNext = before; tmp->mPrev = before; before->mNext = tmp; } } void CLink::Remove() { CLink *prev = mPrev; CLink *next = mNext; mNext = NULL; mPrev = NULL; if (prev) prev->mNext = next; if (next) next->mPrev = prev; } void CLink::RemoveLink() { Remove(); } unsigned int CLink::Count() const { unsigned int n = 1; CLink *i = mNext; while (i) { n++; i = i->GetNext(); } return n; } CLinkIterator::CLinkIterator(CLink* start) : mStart(start) , mCurrent(NULL) { } /*virtual*/ CLinkIterator::~CLinkIterator() { } BOOL CLinkIterator::Current(CLink** p) { if (mCurrent) { *p = mCurrent; return true; } return false; } BOOL CLinkIterator::Prev(CLink** p) { if (mCurrent) { mCurrent = mCurrent->mPrev; return Current(p); } return false; } BOOL CLinkIterator::Next(CLink** p) { if (mCurrent) { mCurrent = mCurrent->mNext; return Current(p); } else { mCurrent = mStart; return Current(p); } }