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

@@ -144,6 +144,13 @@ Returns the node whose stored key matches {\it key}. Use on a keyed list only.
Returns the first node in the list (NULL if the list is empty).
\membersection{wxList::IndexOf}
\func{int}{IndexOf}{\param{wxObject*}{ obj }}
Returns the index of {\it obj} within the list or NOT\_FOUND if {\it obj}
is not found in the list.
\membersection{wxList::Insert}
\func{wxNode *}{Insert}{\param{wxObject *}{object}}

View File

@@ -38,4 +38,10 @@ Retrieves the previous node (NULL if at start of list).
Sets the data associated with the node (usually the pointer will have been
set when the node was created).
\membersection{wxNode::IndexOf}
\func{int}{IndexOf}{\void}
Returns the zero-based index of this node within the list. The return value
will be NOT\_FOUND if the node has not been added to a list yet.

View File

@@ -163,6 +163,9 @@ protected:
void *GetData() const { return m_data; }
void SetData(void *data) { m_data = data; }
// get 0-based index of this node within the list or NOT_FOUND
int IndexOf() const;
virtual void DeleteData() { }
private:
@@ -257,6 +260,9 @@ protected:
// by key
wxNodeBase *Find(const wxListKey& key) const;
// get 0-based index of object or NOT_FOUND
int IndexOf( void *object ) const;
// this function allows the sorting of arbitrary lists by giving
// a function to compare two list elements. The list is sorted in place.
void Sort(const wxSortCompareFunction compfunc);
@@ -377,6 +383,9 @@ private:
virtual nodetype *Find(const wxListKey& key) const \
{ return (nodetype *)wxListBase::Find(key); } \
\
int IndexOf( T *object ) const \
{ return wxListBase::IndexOf(object); } \
\
void Sort(wxSortFuncFor_##name func) \
{ wxListBase::Sort((wxSortCompareFunction)func); } \
\

View File

@@ -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