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