diff options
Diffstat (limited to '')
-rw-r--r-- | src/T2DLL/CLink.cpp | 90 |
1 files changed, 90 insertions, 0 deletions
diff --git a/src/T2DLL/CLink.cpp b/src/T2DLL/CLink.cpp new file mode 100644 index 0000000..88f63bc --- /dev/null +++ b/src/T2DLL/CLink.cpp @@ -0,0 +1,90 @@ +#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); + } +} |