added wxNode::IndexOf and wxList::IndexOf (patch by Frank McIngvale)

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@1096 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
1998-12-02 10:32:03 +00:00
parent 7b67869804
commit 77c5eefb1f
4 changed files with 59 additions and 11 deletions

View File

@@ -68,7 +68,7 @@ bool wxListKey::operator==(wxListKeyValue value) const
case wxKEY_INTEGER:
return m_key.integer == value.integer;
}
}
}
// -----------------------------------------------------------------------------
// wxNodeBase
@@ -82,28 +82,28 @@ wxNodeBase::wxNodeBase(wxListBase *list,
m_data = data;
m_previous = previous;
m_next = next;
switch ( key.GetKeyType() )
{
case wxKEY_NONE:
break;
case wxKEY_INTEGER:
m_key.integer = key.GetNumber();
break;
case wxKEY_STRING:
// to be free()d later
m_key.string = strdup(key.GetString());
break;
default:
wxFAIL_MSG("invalid key type");
}
if ( previous )
previous->m_next = this;
if ( next )
next->m_previous = this;
}
@@ -119,6 +119,25 @@ wxNodeBase::~wxNodeBase()
}
}
int wxNodeBase::IndexOf() const
{
wxCHECK_MSG( m_list, NOT_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
// reusable way of doing it. Can always be optimized at a later date (since
// IndexOf() resides in wxListBase as well) if efficiency is a problem.
int i;
wxNodeBase *prev = m_previous;
for( i = 0; prev; i++ )
{
prev = prev->m_previous;
}
return i;
}
// -----------------------------------------------------------------------------
// wxListBase
// -----------------------------------------------------------------------------
@@ -304,6 +323,13 @@ wxNodeBase *wxListBase::Find(void *object) const
return (wxNodeBase *)NULL;
}
int wxListBase::IndexOf(void *object) const
{
wxNodeBase *node = Find( object );
return node ? node->IndexOf() : NOT_FOUND;
}
void wxListBase::DoDeleteNode(wxNodeBase *node)
{
// free node's data
@@ -498,7 +524,7 @@ void wxStringList::DoCopy(const wxStringList& other)
size_t count = other.GetCount();
for ( size_t n = 0; n < count; n++ )
{
Add(other.Item(n)->GetData());
Add(other.Item(n)->GetData());
}
}