From: Vadim Zeitlin Date: Thu, 26 Nov 1998 14:08:16 +0000 (+0000) Subject: wxList::Insert() bug fixed X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/ff528365c8fdff9af65d3121d9f0954bf216b82f wxList::Insert() bug fixed git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@1061 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/src/common/list.cpp b/src/common/list.cpp index f7b1ab0543..2ee4089692 100644 --- a/src/common/list.cpp +++ b/src/common/list.cpp @@ -49,6 +49,27 @@ // implementation // ============================================================================= +// ----------------------------------------------------------------------------- +// wxListKey +// ----------------------------------------------------------------------------- + +bool wxListKey::operator==(wxListKeyValue value) const +{ + switch ( m_keyType ) + { + default: + wxFAIL_MSG("bad key type."); + // let compiler optimize the line above away in release build + // by not putting return here... + + case wxKEY_STRING: + return strcmp(m_key.string, value.string) == 0; + + case wxKEY_INTEGER: + return m_key.integer == value.integer; + } +} + // ----------------------------------------------------------------------------- // wxNodeBase // ----------------------------------------------------------------------------- @@ -206,16 +227,26 @@ wxNodeBase *wxListBase::Insert(wxNodeBase *position, void *object) wxCHECK_MSG( m_keyType == wxKEY_NONE, (wxNodeBase *)NULL, "need a key for the object to insert" ); - wxNodeBase *prev = (wxNodeBase *)NULL; + wxCHECK_MSG( !position || position->m_list == this, (wxNodeBase *)NULL, + "can't insert before a node from another list" ); + + // previous and next node for the node being inserted + wxNodeBase *prev, *next; if ( position ) + { prev = position->GetPrevious(); - //else - // inserting in the beginning of the list + next = position; + } + else + { + // inserting in the beginning of the list + prev = (wxNodeBase *)NULL; + next = m_nodeFirst; + } - wxNodeBase *node = CreateNode(prev, position, object); + wxNodeBase *node = CreateNode(prev, next, object); if ( !m_nodeFirst ) { - m_nodeFirst = node; m_nodeLast = node; } @@ -440,23 +471,6 @@ void wxListBase::Sort(const wxSortCompareFunction compfunc) delete[] objArray; } -bool wxListKey::operator==(wxListKeyValue value) const - { - switch ( m_keyType ) - { - default: - wxFAIL_MSG("bad key type."); - // let compiler optimize the line above away in release build - // by not putting return here... - - case wxKEY_STRING: - return strcmp(m_key.string, value.string) == 0; - - case wxKEY_INTEGER: - return m_key.integer == value.integer; - } - } - // ----------------------------------------------------------------------------- // wxList (a.k.a. wxObjectList) // -----------------------------------------------------------------------------