X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/77c5eefb1f06a8956231d2cbe1526e4de526cac5..89c684ef8280e2d91096da2d96ba36e24a1fb917:/src/common/list.cpp?ds=sidebyside diff --git a/src/common/list.cpp b/src/common/list.cpp index 457a48aa14..85448991d2 100644 --- a/src/common/list.cpp +++ b/src/common/list.cpp @@ -37,14 +37,6 @@ #include "wx/utils.h" // for copystring() (beurk...) #endif -// Sun CC compatibility (interference with xview/pkg.h, apparently...) -#if defined(SUN_CC) && defined(__XVIEW__) - #undef va_start - #undef va_end - #undef va_arg - #undef va_list -#endif - // ============================================================================= // implementation // ============================================================================= @@ -53,6 +45,8 @@ // wxListKey // ----------------------------------------------------------------------------- +wxListKey wxDefaultListKey; + bool wxListKey::operator==(wxListKeyValue value) const { switch ( m_keyType ) @@ -115,13 +109,18 @@ wxNodeBase::~wxNodeBase() // compatibility with old code if ( m_list != NULL ) { + if ( m_list->m_keyType == wxKEY_STRING ) + { + free(m_key.string); + } + m_list->DetachNode(this); } } int wxNodeBase::IndexOf() const { - wxCHECK_MSG( m_list, NOT_FOUND, "node doesn't belong to a list in IndexOf"); + wxCHECK_MSG( m_list, wxNOT_FOUND, "node doesn't belong to a list in IndexOf"); // It would be more efficient to implement IndexOf() completely inside // wxListBase (only traverse the list once), but this is probably a more @@ -142,7 +141,7 @@ int wxNodeBase::IndexOf() const // wxListBase // ----------------------------------------------------------------------------- -void wxListBase::Init(wxKeyType keyType = wxKEY_NONE) +void wxListBase::Init(wxKeyType keyType) { m_nodeFirst = m_nodeLast = (wxNodeBase *) NULL; @@ -291,7 +290,7 @@ wxNodeBase *wxListBase::Item(size_t n) const wxFAIL_MSG( "invalid index in wxListBase::Item" ); - return NULL; + return (wxNodeBase *)NULL; } wxNodeBase *wxListBase::Find(const wxListKey& key) const @@ -327,7 +326,7 @@ int wxListBase::IndexOf(void *object) const { wxNodeBase *node = Find( object ); - return node ? node->IndexOf() : NOT_FOUND; + return node ? node->IndexOf() : wxNOT_FOUND; } void wxListBase::DoDeleteNode(wxNodeBase *node) @@ -343,6 +342,8 @@ void wxListBase::DoDeleteNode(wxNodeBase *node) node->DeleteData(); } + // so that the node knows that it's being deleted by the list + node->m_list = NULL; delete node; } @@ -394,7 +395,6 @@ bool wxListBase::DeleteObject(void *object) return FALSE; } - void wxListBase::Clear() { wxNodeBase *current = m_nodeFirst; @@ -517,6 +517,23 @@ void wxStringListNode::DeleteData() delete [] (char *)GetData(); } +bool wxStringList::Delete(const char *s) +{ + wxStringListNode *current; + + for ( current = GetFirst(); current; current = current->GetNext() ) + { + if ( strcmp(current->GetData(), s) == 0 ) + { + DeleteNode(current); + return TRUE; + } + } + + // not found + return FALSE; +} + void wxStringList::DoCopy(const wxStringList& other) { wxASSERT( GetCount() == 0 ); // this list must be empty before copying! @@ -601,19 +618,20 @@ void wxStringList::Sort() { size_t N = GetCount(); char **array = new char *[N]; + wxStringListNode *node; size_t i = 0; - for ( wxStringListNode *node = GetFirst(); node; node = node->GetNext() ) + for ( node = GetFirst(); node; node = node->GetNext() ) { array[i++] = node->GetData(); } qsort (array, N, sizeof (char *), wx_comparestrings); - Clear(); - for (i = 0; i < N; i++) - Append (array[i]); + i = 0; + for ( node = GetFirst(); node; node = node->GetNext() ) + node->SetData( array[i++] ); - delete[]array; + delete [] array; }