diff --git a/LEGO1/mxlist.h b/LEGO1/mxlist.h index 9e9eae53..3097dd8d 100644 --- a/LEGO1/mxlist.h +++ b/LEGO1/mxlist.h @@ -75,44 +75,9 @@ class MxListCursor : public MxCore m_match = NULL; } - MxBool Find(T *p_obj) { - for (m_match = m_list->m_first; - m_match && m_list->Compare(m_match->m_obj, p_obj); - m_match = m_match->m_next); - - return m_match != NULL; - } - - void Detach() { - MxListEntry *m_prev = m_match->m_prev; - MxListEntry *m_next = m_match->m_next; - - if (m_prev) - m_prev->m_next = m_next; - else - m_list->m_first = m_next; - - if (m_next) - m_next->m_prev = m_prev; - else - m_list->m_last = m_prev; - - delete m_match; - m_list->m_count--; - m_match = NULL; - } - - MxBool Next(T*& p_obj) { - if (!m_match) - m_match = m_list->m_first; - else - m_match = m_match->m_next; - - if (m_match) - p_obj = m_match->m_obj; - - return m_match != NULL; - } + MxBool Find(T *p_obj); + void Detach(); + MxBool Next(T*& p_obj); private: MxList *m_list; MxListEntry *m_match; @@ -170,4 +135,49 @@ inline void MxList::Append(T *p_newobj) this->m_count++; } +template +inline MxBool MxListCursor::Find(T *p_obj) +{ + for (m_match = m_list->m_first; + m_match && m_list->Compare(m_match->m_obj, p_obj); + m_match = m_match->m_next); + + return m_match != NULL; +} + +template +inline void MxListCursor::Detach() +{ + MxListEntry *m_prev = m_match->m_prev; + MxListEntry *m_next = m_match->m_next; + + if (m_prev) + m_prev->m_next = m_next; + else + m_list->m_first = m_next; + + if (m_next) + m_next->m_prev = m_prev; + else + m_list->m_last = m_prev; + + delete m_match; + m_list->m_count--; + m_match = NULL; +} + +template +inline MxBool MxListCursor::Next(T*& p_obj) +{ + if (!m_match) + m_match = m_list->m_first; + else + m_match = m_match->m_next; + + if (m_match) + p_obj = m_match->m_obj; + + return m_match != NULL; +} + #endif // MXLIST_H \ No newline at end of file