git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@51520
c3d73ce0-8a6f-49c7-b76d-
6d57e0e08775
but is not that complicated and allows the code to be compiled with any, however
dumb, C++ compiler in the world.
but is not that complicated and allows the code to be compiled with any, however
dumb, C++ compiler in the world.
+Remember to #include <wx/arrimpl.cpp> just before each WX\_DEFINE\_OBJARRAY
+ocurrence in your code, even if you have several in the same file.
+
Things are much simpler for wxArray and wxSortedArray however: it is enough
just to write
Things are much simpler for wxArray and wxSortedArray however: it is enough
just to write
\membersection{Adding items}\label{arrayadding}
\helpref{Add}{wxarrayadd}\\
\membersection{Adding items}\label{arrayadding}
\helpref{Add}{wxarrayadd}\\
+\helpref{AddAt}{wxarrayaddat}\\
\helpref{Insert}{wxarrayinsert}\\
\helpref{SetCount}{wxarraysetcount}\\
\helpref{WX\_APPEND\_ARRAY}{wxappendarray}\\
\helpref{Insert}{wxarrayinsert}\\
\helpref{SetCount}{wxarraysetcount}\\
\helpref{WX\_APPEND\_ARRAY}{wxappendarray}\\
\membersection{Searching and sorting}\label{arraysearchingandsorting}
\helpref{Index}{wxarrayindex}\\
\membersection{Searching and sorting}\label{arraysearchingandsorting}
\helpref{Index}{wxarrayindex}\\
+\helpref{IndexForInsert}{wxarrayindexforinsert}\\
\helpref{Sort}{wxarraysort}
%%%%% MEMBERS HERE %%%%%
\helpref{Sort}{wxarraysort}
%%%%% MEMBERS HERE %%%%%
-wxSortedArrayInt sorted(CompareInts);
+MySortedArrayInt sorted(CompareInts);
int CompareMyClassObjects(MyClass *item1, MyClass *item2)
{
int CompareMyClassObjects(MyClass *item1, MyClass *item2)
{
return Stricmp(item1->GetAddress(), item2->GetAddress());
}
return Stricmp(item1->GetAddress(), item2->GetAddress());
}
-wxArrayOfMyClass another(CompareMyClassObjects);
+ArrayOfMyClass another(CompareMyClassObjects);
\end{verbatim}
\membersection{WX\_DECLARE\_OBJARRAY}\label{wxdeclareobjarray}
\end{verbatim}
\membersection{WX\_DECLARE\_OBJARRAY}\label{wxdeclareobjarray}
\func{void}{Add}{\param{T }{item}, \param{size\_t}{ copies = $1$}}
\func{void}{Add}{\param{T }{item}, \param{size\_t}{ copies = $1$}}
+\func{size\_t}{Add}{\param{T }{item}}
+
\func{void}{Add}{\param{T *}{item}}
\func{void}{Add}{\param{T \&}{item}, \param{size\_t}{ copies = $1$}}
\func{void}{Add}{\param{T *}{item}}
\func{void}{Add}{\param{T \&}{item}, \param{size\_t}{ copies = $1$}}
Appends the given number of {\it copies} of the {\it item} to the array
consisting of the elements of type {\it T}.
Appends the given number of {\it copies} of the {\it item} to the array
consisting of the elements of type {\it T}.
-The first version is used with wxArray and wxSortedArray. The second and the
-third are used with wxObjArray. There is an important difference between
+The first version is used with wxArray. The second is used with wxSortedArray,
+returning the index where {\it item} is stored. The third and the
+fourth ones are used with wxObjArray. There is an important difference between
them: if you give a pointer to the array, it will take ownership of it, i.e.
will delete it when the item is deleted from the array. If you give a reference
to the array, however, the array will make a copy of the item and will not take
them: if you give a pointer to the array, it will take ownership of it, i.e.
will delete it when the item is deleted from the array. If you give a reference
to the array, however, the array will make a copy of the item and will not take
{\it copies} parameter and modify the elements in place later if you plan to
append a lot of items.
{\it copies} parameter and modify the elements in place later if you plan to
append a lot of items.
+\membersection{wxSortedArray::AddAt}\label{wxarrayaddat}
+
+\func{void}{AddAt}{\param{T }{item}, \param{size\_t}{ index}}
+
+Inserts the given {\it item} into the array in the specified {\it index}
+ position.
+
+Be aware that you will set out the order of the array if you give a wrong
+ position.
+
+This function is useful in conjunction with
+\helpref{IndexForInsert}{wxarrayindexforinsert} for a common operation
+of "insert only if not found".
+
\membersection{wxArray::Alloc}\label{wxarrayalloc}
\func{void}{Alloc}{\param{size\_t }{count}}
\membersection{wxArray::Alloc}\label{wxarrayalloc}
\func{void}{Alloc}{\param{size\_t }{count}}
previously added to the array, but fail even if another, identical, element is
in the array.
previously added to the array, but fail even if another, identical, element is
in the array.
+\membersection{wxSortedArray::IndexForInsert}\label{wxarrayindexforinsert}
+
+\constfunc{size\_t}{IndexForInsert}{\param{T }{item}}
+
+Search for a place to insert {\it item} into the sorted array (binary search).
+The index returned is just before the first existing item that is greater or equal
+(according to the compare function) to the given {\it item}.
+
+You have to do extra work to know if the {\it item} already exists in array.
+
+This function is useful in conjunction with
+\helpref{AddAt}{wxarrayaddat} for a common operation
+of "insert only if not found".
+
\membersection{wxArray::Insert}\label{wxarrayinsert}
\func{void}{Insert}{\param{T }{item}, \param{size\_t }{n}, \param{size\_t }{copies = $1$}}
\membersection{wxArray::Insert}\label{wxarrayinsert}
\func{void}{Insert}{\param{T }{item}, \param{size\_t }{n}, \param{size\_t }{copies = $1$}}
the existing item {\it n} - thus, {\it Insert(something, 0u)} will insert an
item in such way that it will become the first array element.
the existing item {\it n} - thus, {\it Insert(something, 0u)} will insert an
item in such way that it will become the first array element.
+wxSortedArray doesn't have this function because inserting in wrong place
+would break its sorted condition.
+
Please see \helpref{Add()}{wxarrayadd} for explanation of the differences
between the overloaded versions of this function.
Please see \helpref{Add()}{wxarrayadd} for explanation of the differences
between the overloaded versions of this function.