]> git.saurik.com Git - wxWidgets.git/commitdiff
RemoveAt() added to array classes
authorVadim Zeitlin <vadim@wxwidgets.org>
Tue, 16 Nov 1999 13:28:23 +0000 (13:28 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Tue, 16 Nov 1999 13:28:23 +0000 (13:28 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@4589 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

docs/latex/wx/array.tex
include/wx/arrimpl.cpp
include/wx/dynarray.h
src/common/dynarray.cpp

index 8d4fd6f665c9c2bcc3bddcd9203ae38dd6dd8352..9142a69eb9126abe63aafd8f97a48d7540bcc570 100644 (file)
@@ -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}
index c2888057ddc74a7ac39f639b0a7aeb8ea42cb6a3..585893ccc75b283fdd2bd80c72621fdb23e5f32f 100644 (file)
@@ -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)                                                 \
index a3c4017ada52beba2b7d6caa86a49fa6394d8beb..cafb60d33ac4d9f8b62400cdbd5a3f70289d6e99 100644 (file)
@@ -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); }  \
                                                                     \
index 04d89832e16d5f579b422ce281a3df14913abb02..ed85392df3004ae66ad244ff6a98dc5da39978c5 100644 (file)
@@ -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));