]> git.saurik.com Git - wxWidgets.git/blame - docs/latex/wx/list.tex
Patches-1851591 ] dataview sample is crashing (under MSW)
[wxWidgets.git] / docs / latex / wx / list.tex
CommitLineData
1ac74d83
WS
1%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2%% Name: list.tex
3%% Purpose: wxList
4%% Author: wxWidgets Team
5%% Modified by:
6%% Created:
7%% RCS-ID: $Id$
8%% Copyright: (c) wxWidgets Team
9%% License: wxWindows license
10%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
11
83e51c48
RR
12\section{\class{wxList<T>}}\label{wxlist}
13
14The wxList<T> class provides linked list functionality. It has been written
15to be type safe and to provide the full API of the STL std::list container and
16should be used like it. The exception is that wxList<T> actually stores
17pointers and therefore its iterators return pointers and not references
cb367500
RR
18to the actual objets in the list (see example below) and {\it value\_type}
19is defined as {\it T*}.
20
21
22Unfortunately, the
83e51c48
RR
23new wxList<T> class requires that you declare and define each wxList<T>
24class in your program. This is done with {\it WX\_DECLARE\_LIST} and
25{\it WX\_DEFINE\_LIST} macros (see example). We hope that we'll be able
26to provide a proper template class providing both the STL std::list
27and the old wxList API in the future.
28
29Please refer to the STL std::list documentation for further
cb367500
RR
30information on how to use the class. Below we documented both
31the supported STL and the legacy API that originated from the
32old wxList class and which can still be used alternatively for
33the the same class.
83e51c48 34
7e57f04a 35Note that if you compile wxWidgets in STL mode (wxUSE\_STL defined as 1)
83e51c48
RR
36then wxList<T> will actually derive from std::list and just add a legacy
37compatibility layer for the old wxList class.
38
6e6110ee
VZ
39\wxheading{Example}
40
6e6110ee
VZ
41\begin{verbatim}
42 // this part might be in a header or source (.cpp) file
43 class MyListElement
44 {
45 ... // whatever
46 };
47
83e51c48 48 // this macro declares and partly implements MyList class
f776e250 49 WX_DECLARE_LIST(MyListElement, MyList);
6e6110ee
VZ
50
51 ...
52
2edb0bde 53 // the only requirement for the rest is to be AFTER the full declaration of
6e6110ee
VZ
54 // MyListElement (for WX_DECLARE_LIST forward declaration is enough), but
55 // usually it will be found in the source file and not in the header
56
57 #include <wx/listimpl.cpp>
f776e250 58 WX_DEFINE_LIST(MyList);
6e6110ee 59
83e51c48 60
6e6110ee
VZ
61 MyList list;
62 MyListElement element;
1ac74d83 63 list.Append(&element); // ok
bb250157 64 list.Append(17); // error: incorrect type
6e6110ee 65
83e51c48
RR
66 // let's iterate over the list in STL syntax
67 MyList::iterator iter;
68 for (iter = list.begin(); iter != list.end(); ++iter)
69 {
70 MyListElement *current = *iter;
71
72 ...process the current element...
73 }
74
75 // the same with the legacy API from the old wxList class
76 MyList::compatibility_iterator node = list.GetFirst();
77 while (node)
6e6110ee
VZ
78 {
79 MyListElement *current = node->GetData();
80
81 ...process the current element...
83e51c48
RR
82
83 node = node->GetNext();
6e6110ee 84 }
83e51c48 85
6e6110ee 86\end{verbatim}
6e6110ee
VZ
87
88For compatibility with previous versions wxList and wxStringList classes are
89still defined, but their usage is deprecated and they will disappear in the
703f03c3 90future versions completely. The use of the latter is especially discouraged as
1ac74d83 91it is not only unsafe but is also much less efficient than
35d367d8 92\helpref{wxArrayString}{wxarraystring} class.
a660d684 93
954b8ae6
JS
94\wxheading{Include files}
95
96<wx/list.h>
97
a7af285d
VZ
98\wxheading{Library}
99
100\helpref{wxBase}{librarieslist}
101
a660d684
KB
102\wxheading{See also}
103
44f2a3d1
RR
104\helpref{wxArray<T>}{wxarray},
105\helpref{wxVector<T>}{wxvector}
a660d684
KB
106
107\latexignore{\rtfignore{\wxheading{Members}}}
108
83e51c48 109\membersection{wxList<T>::wxList<T>}\label{wxlistctor}
2bbd97f4 110
83e51c48 111\func{}{wxList<T>}{\void}
a660d684 112
7e57f04a 113\func{}{wxList<T>}{\param{size\_t}{ count}, \param{T *}{elements[]}}
a660d684 114
83e51c48 115Constructors.
a660d684 116
83e51c48 117\membersection{wxList<T>::\destruct{wxList<T>}}\label{wxlistdtor}
a660d684 118
83e51c48 119\func{}{\destruct{wxList<T>}}{\void}
a660d684 120
83e51c48
RR
121Destroys the list, but does not delete the objects stored in the list
122unless you called DeleteContents({\tt true} ).
a660d684 123
83e51c48 124\membersection{wxList<T>::Append}\label{wxlistappend}
a660d684 125
e7ec3618 126\func{wxList<T>::compatibility\_iterator }{Append}{\param{T *}{object}}
a660d684 127
83e51c48 128Appends the pointer to \rtfsp{\it object} to the list.
2bbd97f4 129
de414223 130\membersection{wxList<T>::Clear}\label{wxlistclear1}
a660d684
KB
131
132\func{void}{Clear}{\void}
133
83e51c48
RR
134Clears the list, but does not delete the objects stored in the list
135unless you called DeleteContents({\tt true} ).
a660d684 136
83e51c48 137\membersection{wxList<T>::DeleteContents}\label{wxlistdeletecontents}
a660d684
KB
138
139\func{void}{DeleteContents}{\param{bool}{ destroy}}
140
83e51c48
RR
141If {\it destroy} is {\tt true}, instructs the list to call {\it delete}
142on objects stored in the list whenever they are removed.
143The default is {\tt false}.
a660d684 144
83e51c48 145\membersection{wxList<T>::DeleteNode}\label{wxlistdeletenode}
a660d684 146
e7ec3618 147\func{bool}{DeleteNode}{\param{const compatibility\_iterator &}{iter}}
a660d684 148
83e51c48
RR
149Deletes the given element refered to by {\tt iter} from the list,
150returning {\tt true} if successful.
a660d684 151
83e51c48 152\membersection{wxList<T>::DeleteObject}\label{wxlistdeleteobject}
a660d684 153
2b5f62a0 154\func{bool}{DeleteObject}{\param{T *}{object}}
a660d684 155
83e51c48
RR
156Finds the given {\it object} and removes it from the list, returning
157{\tt true} if successful. The application must delete the actual object
158separately.
e0ad14ca 159
83e51c48 160\membersection{wxList<T>::Erase}\label{wxlisterase}
a660d684 161
e7ec3618 162\func{void}{Erase}{\param{const compatibility\_iterator &}{iter}}
a660d684 163
83e51c48 164Removes element refered to be {\tt iter}.
2b5f62a0 165
83e51c48 166\membersection{wxList<T>::Find}\label{wxlistfind}
2bbd97f4 167
e7ec3618 168\constfunc{wxList<T>::compatibility\_iterator}{Find}{\param{T *}{ object}}
2b5f62a0 169
83e51c48 170Returns the iterator refering to {\it object} or NULL if none found.
a660d684 171
83e51c48 172\membersection{wxList<T>::GetCount}\label{wxlistgetcount}
d8996187
VZ
173
174\constfunc{size\_t}{GetCount}{\void}
175
176Returns the number of elements in the list.
177
83e51c48 178\membersection{wxList<T>::GetFirst}\label{wxlistgetfirst}
a660d684 179
e7ec3618 180\constfunc{wxList<T>::compatibility\_iterator}{GetFirst}{\void}
a660d684 181
83e51c48 182Returns the first iterator in the list (NULL if the list is empty).
a660d684 183
83e51c48 184\membersection{wxList<T>::GetLast}\label{wxlistgetlast}
d8996187 185
e7ec3618 186\constfunc{wxList<T>::compatibility\_iterator}{GetLast}{\void}
d8996187 187
83e51c48 188Returns the last iterator in the list (NULL if the list is empty).
d8996187 189
83e51c48 190\membersection{wxList<T>::IndexOf}\label{wxlistindexof}
77c5eefb 191
83e51c48 192\constfunc{int}{IndexOf}{\param{T*}{ obj }}
77c5eefb 193
83e51c48
RR
194Returns the index of {\it obj} within the list or {\tt wxNOT\_FOUND} if
195{\it obj} is not found in the list.
77c5eefb 196
de414223 197\membersection{wxList<T>::Insert}\label{wxlistinsert1}
a660d684 198
e7ec3618 199\func{wxList<T>::compatibility\_iterator}{Insert}{\param{T *}{object}}
a660d684 200
83e51c48 201Insert object at the front of list.
a660d684 202
e7ec3618 203\func{wxList<T>::compatibility\_iterator}{Insert}{\param{size\_t }{position}, \param{T *}{object}}
a660d684 204
d8996187
VZ
205Insert object before {\it position}, i.e. the index of the new item in the
206list will be equal to {\it position}. {\it position} should be less than or
207equal to \helpref{GetCount}{wxlistgetcount}; if it is equal to it, this is the
208same as calling \helpref{Append}{wxlistappend}.
a660d684 209
e7ec3618 210\func{wxList<T>::compatibility\_iterator}{Insert}{\param{compatibility\_iterator}{iter}, \param{T *}{object}}
a660d684 211
83e51c48 212Inserts the object before the object refered to be {\it iter}.
a660d684 213
83e51c48 214\membersection{wxList<T>::IsEmpty}\label{wxlistisempty}
b79a8705
VZ
215
216\constfunc{bool}{IsEmpty}{\void}
217
cc81d32f 218Returns {\tt true} if the list is empty, {\tt false} otherwise.
b79a8705 219
0b0625e9 220% Use different label name to avoid clashing with wxListItem label
83e51c48 221\membersection{wxList<T>::Item}\label{wxlistitemfunc}
a660d684 222
e7ec3618 223\constfunc{wxList<T>::compatibility\_iterator}{Item}{\param{size\_t }{index}}
d8996187 224
83e51c48
RR
225Returns the iterator refering to the object at the given
226{\tt index} in the list.
a660d684 227
83e51c48 228\membersection{wxList<T>::Member}\label{wxlistmember}
a660d684 229
e7ec3618 230\constfunc{wxList<T>::compatibility\_iterator}{Member}{\param{T *}{ object}}
a660d684 231
d8996187
VZ
232{\bf NB:} This function is deprecated, use \helpref{Find}{wxlistfind} instead.
233
83e51c48 234\membersection{wxList<T>::Nth}\label{wxlistnth}
a660d684 235
e7ec3618 236\constfunc{wxList<T>::compatibility\_iterator}{Nth}{\param{int }{n}}
a660d684 237
0b0625e9 238{\bf NB:} This function is deprecated, use \helpref{Item}{wxlistitemfunc} instead.
d8996187 239
a660d684
KB
240Returns the {\it nth} node in the list, indexing from zero (NULL if the list is empty
241or the nth node could not be found).
242
83e51c48 243\membersection{wxList<T>::Number}\label{wxlistnumber}
a660d684 244
83e51c48 245\constfunc{int}{Number}{\void}
a660d684 246
d8996187
VZ
247{\bf NB:} This function is deprecated, use \helpref{GetCount}{wxlistgetcount} instead.
248
a660d684
KB
249Returns the number of elements in the list.
250
83e51c48 251\membersection{wxList<T>::Sort}\label{wxlistsort}
a660d684
KB
252
253\func{void}{Sort}{\param{wxSortCompareFunction}{ compfunc}}
254
255\begin{verbatim}
256 // Type of compare function for list sort operation (as in 'qsort')
257 typedef int (*wxSortCompareFunction)(const void *elem1, const void *elem2);
258\end{verbatim}
259
83e51c48
RR
260Allows the sorting of arbitrary lists by giving a function to compare
261two list elements. We use the system {\bf qsort} function for the actual
262sorting process.
a660d684 263
cb367500
RR
264
265
266\membersection{wxList<T>::assign}\label{wxlistassign}
267
268\func{void}{assign}{\param{const\_iterator }{first}, \param{const const\_iterator\& }{last}}
269
270
271\func{void}{assign}{\param{size\_type }{n}, \param{const\_reference }{v = value\_type()}}
272
273
274\membersection{wxList<T>::back}\label{wxlistback}
275
276\func{reference}{back}{\void}
277
278\constfunc{const\_reference}{back}{\void}
279
280Returns the last item of the list.
281
282\membersection{wxList<T>::begin}\label{wxlistbegin}
283
284\func{iterator}{begin}{\void}
285
286\constfunc{const\_iterator}{begin}{\void}
287
288Returns a (const) iterator pointing to the beginning of the list.
289
290\membersection{wxList<T>::clear}\label{wxlistclear}
291
292\func{void}{clear}{\void}
293
294Removes all items from the list.
295
296\membersection{wxList<T>::empty}\label{wxlistempty}
297
298\constfunc{bool}{empty}{\void}
299
300Returns {\it true} if the list is empty.
301
302\membersection{wxList<T>::end}\label{wxlistend}
303
304\func{iterator}{end}{\void}
305
306\constfunc{const\_iterator}{end}{\void}
307
308Returns a (const) iterator pointing at the end of the list.
309
310\membersection{wxList<T>::erase}\label{wxlisterase2}
311
312\func{iterator}{erase}{\param{const iterator\& }{it}}
313
314Erases the item pointed to by {\it it}.
315
316\func{iterator}{erase}{\param{const iterator\& }{first}, \param{const iterator\& }{last}}
317
318Erases the items from {\it first} to {\it last}.
319
320\membersection{wxList<T>::front}\label{wxlistfront}
321
322\func{reference}{front}{\void}
323
324\constfunc{const\_reference}{front}{\void}
325
326Returns the first item in the list.
327
328\membersection{wxList<T>::insert}\label{wxlistinsert}
329
330\func{iterator}{insert}{\param{const iterator\& }{it}, \param{const\_reference }{v = value\_type()}}
331
332\func{void}{insert}{\param{const iterator\& }{it}, \param{size\_type }{n}, \param{const\_reference }{v = value\_type()}}
333
334\func{void}{insert}{\param{const iterator\& }{it}, \param{const\_iterator }{first}, \param{const const\_iterator\& }{last}}
335
336Inserts an item (or several) at the given position.
337
d8fcdf97 338\membersection{wxList<T>::max\_size}\label{wxlistmaxsize}
cb367500
RR
339
340\constfunc{size\_type}{max\_size}{\void}
341
342Returns the largest possible size of the list.
343
d8fcdf97 344\membersection{wxList<T>::pop\_back}\label{wxlistpopback}
cb367500
RR
345
346\func{void}{pop\_back}{\void}
347
348Removes the last item from the list.
349
d8fcdf97 350\membersection{wxList<T>::pop\_front}\label{wxlistpopfront}
cb367500
RR
351
352\func{void}{pop\_front}{\void}
353
354Removes the first item from the list.
355
d8fcdf97 356\membersection{wxList<T>::push\_back}\label{wxlistpushback}
cb367500
RR
357
358\func{void}{push\_back}{\param{const\_reference }{v = value\_type()}}
359
360Adds an item to end of the list.
361
d8fcdf97 362\membersection{wxList<T>::push\_front}\label{wxlistpushfront}
cb367500
RR
363
364\func{void}{push\_front}{\param{const\_reference }{v = value\_type()}}
365
366Adds an item to the front of the list.
367
368\membersection{wxList<T>::rbegin}\label{wxlistrbegin}
369
370\func{reverse\_iterator}{rbegin}{\void}
371
372\constfunc{const\_reverse\_iterator}{rbegin}{\void}
373
374Returns a (const) reverse iterator pointing to the beginning of the
375reversed list.
376
377\membersection{wxList<T>::remove}\label{wxlistremove}
378
379\func{void}{remove}{\param{const\_reference }{v}}
380
381Removes an item from the list.
382
383\membersection{wxList<T>::rend}\label{wxlistrend}
384
385\func{reverse\_iterator}{rend}{\void}
386
387\constfunc{const\_reverse\_iterator}{rend}{\void}
388
389Returns a (const) reverse iterator pointing to the end of the
390reversed list.
391
392\membersection{wxList<T>::resize}\label{wxlistresize}
393
394\func{void}{resize}{\param{size\_type }{n}, \param{value\_type }{v = value\_type()}}
395
396Resizes the list. If the the list is enlarges items with
397the value {\it v} are appended to the list.
398
399\membersection{wxList<T>::reverse}\label{wxlistreverse}
400
401\func{void}{reverse}{\void}
402
403Reverses the list.
404
405\membersection{wxList<T>::size}\label{wxlistsize}
406
407\constfunc{size\_type}{size}{\void}
408
409Returns the size of the list.
410
411\membersection{wxList<T>::splice}\label{wxlistsplice}
412
413\func{void}{splice}{\param{const iterator\& }{it}, \param{wxList<T>\& }{l}}
414
415\func{void}{splice}{\param{const iterator\& }{it}, \param{wxList<T>\& }{l}, \param{const iterator\& }{first}}
416
417\func{void}{splice}{\param{const iterator\& }{it}, \param{wxList<T>\& }{l}, \param{const iterator\& }{first}, \param{const iterator\& }{last}}
418
419Moves part of the list into another list, starting from {\it first} and
420ending at {\it last} if specified.