diff --git a/docs/latex/wx/array.tex b/docs/latex/wx/array.tex index 8d4fd6f665..9142a69eb9 100644 --- a/docs/latex/wx/array.tex +++ b/docs/latex/wx/array.tex @@ -200,6 +200,7 @@ does exactly the same as \helpref{Item()}{wxarrayitem} method. \helpref{WX\_CLEAR\_ARRAY}{wxcleararray}\\ \helpref{Empty}{wxarrayempty}\\ \helpref{Clear}{wxarrayclear}\\ +\helpref{RemoveAt}{wxarrayremoveat}\\ \helpref{Remove}{wxarrayremove} \membersection{Searching and sorting} @@ -412,7 +413,6 @@ it exists only for compatibility. \func{T *}{Detach}{\param{size\_t }{index}} Removes the element from the array, but, unlike, - \helpref{Remove()}{wxarrayremove} doesn't delete it. The function returns the pointer to the removed element. @@ -493,12 +493,13 @@ the array classes. \membersection{wxArray::Remove}\label{wxarrayremove} -\func{\void}{Remove}{\param{size\_t }{index}} - \func{\void}{Remove}{\param{T }{item}} -Removes the element from the array either by index or by value. When an element -is removed from wxObjArray it is deleted by the array - use +Removes the element from the array either by value: the first item of the +array equal to {\it item} is removed, an assert failure will result from an +attempt to remove an item which doesn't exist in the array. + +When an element is removed from wxObjArray it is deleted by the array - use \helpref{Detach()}{wxobjarraydetach} if you don't want this to happen. On the other hand, when an object is removed from a wxArray nothing happens - you should delete the it manually if required: @@ -512,6 +513,25 @@ array.Remove(n) See also \helpref{WX\_CLEAR\_ARRAY}{wxcleararray} macro which deletes all elements of a wxArray (supposed to contain pointers). +\membersection{wxArray::RemoveAt}\label{wxarrayremoveat} + +\func{\void}{RemoveAt}{\param{size\_t }{index}} + +Removes the element from the array either by index. When an element +is removed from wxObjArray it is deleted by the array - use +\helpref{Detach()}{wxobjarraydetach} if you don't want this to happen. On the +other hand, when an object is removed from a wxArray nothing happens - you +should delete the it manually if required: + +\begin{verbatim} +T *item = array[n]; +delete item; +array.RemoveAt(n) +\end{verbatim} + +See also \helpref{WX\_CLEAR\_ARRAY}{wxcleararray} macro which deletes all +elements of a wxArray (supposed to contain pointers). + \membersection{wxArray::Shrink}\label{wxarrayshrink} \func{void}{Shrink}{\void} diff --git a/include/wx/arrimpl.cpp b/include/wx/arrimpl.cpp index c2888057dd..585893ccc7 100644 --- a/include/wx/arrimpl.cpp +++ b/include/wx/arrimpl.cpp @@ -21,7 +21,7 @@ *****************************************************************************/ // needed to resolve the conflict between global T and macro parameter T -#define _WX_ERROR_REMOVE2(x) wxT("bad index in " #x "::Remove()") +#define _WX_ERROR_REMOVE2(x) wxT("bad index in " #x "::RemoveAt()") // macro implements remaining (not inline) methods of template list // (it's private to this file) @@ -59,13 +59,13 @@ void name::Empty() \ wxBaseArray::Clear(); \ } \ \ -void name::Remove(size_t uiIndex) \ +void name::RemoveAt(size_t uiIndex) \ { \ wxCHECK_RET( uiIndex < Count(), _WX_ERROR_REMOVE2(name) ); \ \ delete (T*)wxBaseArray::Item(uiIndex); \ \ - wxBaseArray::Remove(uiIndex); \ + wxBaseArray::RemoveAt(uiIndex); \ } \ \ void name::Add(const T& item) \ diff --git a/include/wx/dynarray.h b/include/wx/dynarray.h index a3c4017ada..cafb60d33a 100644 --- a/include/wx/dynarray.h +++ b/include/wx/dynarray.h @@ -132,7 +132,7 @@ protected: /// remove first item matching this value void Remove(long lItem); /// remove item by index - void Remove(size_t uiIndex); + void RemoveAt(size_t uiIndex); //@} /// sort array elements using given compare function @@ -198,7 +198,8 @@ public: \ void Insert(T Item, size_t uiIndex) \ { wxBaseArray::Insert((long)Item, uiIndex) ; } \ \ - void Remove(size_t uiIndex) { wxBaseArray::Remove(uiIndex); } \ + void Remove(size_t uiIndex) { RemoveAt(uiIndex); } \ + void RemoveAt(size_t uiIndex) { wxBaseArray::RemoveAt(uiIndex); } \ void Remove(T Item) \ { int iIndex = Index(Item); \ wxCHECK2_MSG( iIndex != wxNOT_FOUND, return, \ @@ -260,7 +261,8 @@ public: \ void Add(T Item) \ { wxBaseArray::Add((long)Item, (CMPFUNC)m_fnCompare); } \ \ - void Remove(size_t uiIndex) { wxBaseArray::Remove(uiIndex); } \ + void Remove(size_t uiIndex) { RemoveAt(uiIndex); } \ + void RemoveAt(size_t uiIndex) { wxBaseArray::RemoveAt(uiIndex); } \ void Remove(T Item) \ { int iIndex = Index(Item); \ wxCHECK2_MSG( iIndex != wxNOT_FOUND, return, \ @@ -307,7 +309,8 @@ public: \ T* Detach(size_t uiIndex) \ { T* p = (T*)wxBaseArray::Item(uiIndex); \ wxBaseArray::Remove(uiIndex); return p; } \ - void Remove(size_t uiIndex); \ + void Remove(size_t uiIndex) { RemoveAt(uiIndex); } \ + void RemoveAt(size_t uiIndex); \ \ void Sort(CMPFUNC##T fCmp) { wxBaseArray::Sort((CMPFUNC)fCmp); } \ \ diff --git a/src/common/dynarray.cpp b/src/common/dynarray.cpp index 04d89832e1..ed85392df3 100644 --- a/src/common/dynarray.cpp +++ b/src/common/dynarray.cpp @@ -261,9 +261,9 @@ void wxBaseArray::Insert(long lItem, size_t nIndex) } // removes item from array (by index) -void wxBaseArray::Remove(size_t nIndex) +void wxBaseArray::RemoveAt(size_t nIndex) { - wxCHECK_RET( nIndex <= m_nCount, wxT("bad index in wxArray::Remove") ); + wxCHECK_RET( nIndex <= m_nCount, wxT("bad index in wxArray::RemoveAt") ); memmove(&m_pItems[nIndex], &m_pItems[nIndex + 1], (m_nCount - nIndex - 1)*sizeof(long));