]> git.saurik.com Git - wxWidgets.git/blobdiff - docs/latex/wx/array.tex
Added wxUSE_SPINCTRL
[wxWidgets.git] / docs / latex / wx / array.tex
index 2840322d0c1e15ed1a6d832f58a2b2096e05fdf3..9142a69eb9126abe63aafd8f97a48d7540bcc570 100644 (file)
@@ -39,7 +39,14 @@ deleted when the element is removed from the array. It should be noted that
 all of wxArray's functions are inline, so it costs strictly nothing to define as
 many array types as you want (either in terms of the executable size or the
 speed) as long as at least one of them is defined and this is always the case
-because wxArrays are used by wxWindows internally.
+because wxArrays are used by wxWindows internally. This class has one serious
+limitation: it can only be used for storing integral types (bool, char, short,
+int, long and their unsigned variants) or pointers (of any kind). An attempt
+to use with objects of sizeof() greater than sizeof(long) will provoke a
+runtime assertion failure, however declaring a wxArray of floats will not (on
+the machines where sizeof(float) <= sizeof(long)), yet it will {\bf not} work,
+please use wxObjArray for storing floats and doubles (NB: a more efficient
+wxArrayDouble class is scheduled for the next release of wxWindows).
 
 wxSortedArray is a wxArray variant which should be used when searching in the
 array is a frequently used operation. It requires you to define an additional
@@ -51,9 +58,8 @@ slower: it is $O(log(N))$ instead of constant time (neglecting time spent in
 memory allocation routine). However, in a usual situation elements are added to
 an array much less often than searched inside it, so wxSortedArray may lead to
 huge performance improvements compared to wxArray. Finally, it should be
-noticed that, as wxArray, wxSortedArray can not be used to store anything of
-sizeof() larger than max(sizeof(long), sizeof(void *)) - an assertion failure
-will be raised from the constructor otherwise.
+noticed that, as wxArray, wxSortedArray can be only used for storing integral
+types or pointers.
 
 wxObjArray class treats its elements like "objects". It may delete them when
 they are removed from the array (invoking the correct destructor) and copies
@@ -89,7 +95,9 @@ class MyDirectory
 ...
 
 // now that we have MyDirectory declaration in scope we may finish the
-// definition of ArrayOfDirectories
+// definition of ArrayOfDirectories -- note that this expands into some C++
+// code and so should only be compiled once (i.e., don't put this in the
+// header, but into a source file or you will get linkin errors)
 #include <wx/arrimpl.cpp> // this is a magic incantation which must be done!
 WX_DEFINE_OBJARRAY(ArrayOfDirectories);
 
@@ -192,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}
@@ -231,7 +240,7 @@ This macro defines a new sorted array class named {\it name} and containing
 the elements of type {\it T}. Example:
 
 \begin{verbatim}
-WX_DEFINE_SORTED_ARRAY(int, wxArrayInt);
+WX_DEFINE_SORTED_ARRAY(int, wxSortedArrayInt);
 
 class MyClass;
 WX_DEFINE_SORTED_ARRAY(MyClass *, wxArrayOfMyClass);
@@ -245,7 +254,7 @@ int CompareInts(int n1, int n2)
     return n1 - n2;
 }
 
-wxArrayInt sorted(CompareInts);
+wxSortedArrayInt sorted(CompareInts);
 
 int CompareMyClassObjects(MyClass *item1, MyClass *item2)
 {
@@ -404,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.
 
@@ -485,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:
@@ -504,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}