From 7cede536484c91bc5b732022b74f7661b13873cc Mon Sep 17 00:00:00 2001 From: disinvite Date: Sun, 11 Aug 2024 15:55:13 -0400 Subject: [PATCH] MxList DeleteAll and Empty functions --- LEGO1/omni/include/mxlist.h | 45 ++++++++++--------- .../omni/src/common/mxcompositepresenter.cpp | 2 +- 2 files changed, 25 insertions(+), 22 deletions(-) diff --git a/LEGO1/omni/include/mxlist.h b/LEGO1/omni/include/mxlist.h index 985c48d2..b020eeb3 100644 --- a/LEGO1/omni/include/mxlist.h +++ b/LEGO1/omni/include/mxlist.h @@ -45,17 +45,14 @@ class MxListEntry { template class MxList : protected MxCollection { public: - MxList() - { - m_last = NULL; - m_first = NULL; - } + MxList() { m_first = m_last = NULL; } ~MxList() override; void Append(T p_obj) { InsertEntry(p_obj, this->m_last, NULL); } void Prepend(T p_obj) { InsertEntry(p_obj, NULL, this->m_first); } - void DeleteAll(MxBool p_destroy = TRUE); + void DeleteAll(); + void Empty(); MxU32 GetCount() { return this->m_count; } friend class MxListCursor; @@ -136,27 +133,33 @@ MxList::~MxList() DeleteAll(); } +// Delete entries and values template -inline void MxList::DeleteAll(MxBool p_destroy) +inline void MxList::DeleteAll() { - for (MxListEntry* t = m_first;;) { - if (!t) { - break; - } - - MxListEntry* next = t->GetNext(); - - if (p_destroy) { - this->m_customDestructor(t->GetValue()); - } - + MxListEntry* next; + for (MxListEntry* t = m_first; t; t = next) { + next = t->GetNext(); + this->m_customDestructor(t->GetValue()); delete t; - t = next; } this->m_count = 0; - m_last = NULL; - m_first = NULL; + m_first = m_last = NULL; +} + +// Delete entries only +template +inline void MxList::Empty() +{ + MxListEntry* next; + for (MxListEntry* t = m_first; t; t = next) { + next = t->GetNext(); + delete t; + } + + this->m_count = 0; + m_first = m_last = NULL; } template diff --git a/LEGO1/omni/src/common/mxcompositepresenter.cpp b/LEGO1/omni/src/common/mxcompositepresenter.cpp index 7beb86ca..124d6b0a 100644 --- a/LEGO1/omni/src/common/mxcompositepresenter.cpp +++ b/LEGO1/omni/src/common/mxcompositepresenter.cpp @@ -86,7 +86,7 @@ void MxCompositePresenter::EndAction() return; } - ((MxDSMultiAction*) m_action)->GetActionList()->DeleteAll(FALSE); + ((MxDSMultiAction*) m_action)->GetActionList()->Empty(); while (!m_list.empty()) { MxPresenter* presenter = m_list.front();