summaryrefslogtreecommitdiff
path: root/src/T2DLL/CLink.cpp
diff options
context:
space:
mode:
authorAsh Wolf <ninji@wuffs.org>2023-06-14 00:50:34 +0100
committerAsh Wolf <ninji@wuffs.org>2023-06-14 00:50:34 +0100
commit37e364b2c6cc7487a1c888d256a73e5337bb7189 (patch)
treeeaf6e857382eef16c2dd940eb4125536fbe068bd /src/T2DLL/CLink.cpp
downloadt2win-37e364b2c6cc7487a1c888d256a73e5337bb7189.tar.gz
t2win-37e364b2c6cc7487a1c888d256a73e5337bb7189.zip
initial commit
Diffstat (limited to '')
-rw-r--r--src/T2DLL/CLink.cpp90
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);
+ }
+}