]> git.saurik.com Git - wxWidgets.git/blame_incremental - docs/latex/wx/tcontain.tex
toplevel code transferred to wxTopLevelWindow
[wxWidgets.git] / docs / latex / wx / tcontain.tex
... / ...
CommitLineData
1\section{Container classes overview}\label{wxcontaineroverview}
2
3Classes: \helpref{wxList}{wxlist}, \helpref{wxArray}{wxarray}
4
5wxWindows uses itself several container classes including doubly-linked lists
6and dynamic arrays (i.e. arrays which expand automatically when they become
7full). For both historical and portability reasons wxWindows does not
8use STL which provides the standard implementation of many container classes in
9C++. First of all, wxWindows has existed since well before STL was written, and
10secondly we don't believe that today compilers can deal really well with all of
11STL classes (this is especially true for some less common platforms). Of
12course, the compilers are evolving quite rapidly and hopefully their progress
13will allow to base future versions of wxWindows on STL - but this is not yet
14the case.
15
16wxWindows container classes don't pretend to be as powerful or full as STL
17ones, but they are quite useful and may be compiled with absolutely any C++
18compiler. They're used internally by wxWindows, but may, of course, be used in
19your programs as well if you wish.
20
21The list classes in wxWindows are doubly-linked lists which may either own the
22objects they contain (meaning that the list deletes the object when it is
23removed from the list or the list itself is destroyed) or just store the
24pointers depending on whether you called or not
25\helpref{wxList::DeleteContents}{wxlistdeletecontents} method.
26
27Dynamic arrays resemble C arrays but with two important differences: they
28provide run-time range checking in debug builds and they expand automatically
29the allocated memory when there is no more space for new items. They come in
30two sorts: the "plain" arrays which store either built-in types such as "char",
31"int" or "bool" or the pointers to arbitrary objects, or "object arrays" which
32own the object pointers to which they store.
33
34For the same portability reasons, the container classes implementation in wxWindows
35does not use templates, but is rather based on C preprocessor i.e. is done with
36the macros: {\it WX\_DECLARE\_LIST} and {\it WX\_DEFINE\_LIST} for the linked
37lists and {\it WX\_DECLARE\_ARRAY}, {\it WX\_DECLARE\_OBJARRAY} and {\it WX\_DEFINE\_OBJARRAY} for
38the dynamic arrays. The "DECLARE" macro declares a
39new container class containing the elements of given type and is needed for all
40three types of container classes: lists, arrays and objarrays. The "DEFINE"
41classes must be inserted in your program in a place where the {\bf full
42declaration of container element class is in scope} (i.e. not just forward
43declaration), otherwise destructors of the container elements will not be
44called! As array classes never delete the items they contain anyhow, there is
45no WX\_DEFINE\_ARRAY macro for them.
46
47Examples of usage of these macros may be found in \helpref{wxList}{wxlist} and
48\helpref{wxArray}{wxarray} documentation.
49
50Finally, wxWindows predefines several commonly used container classes. wxList
51is defined for compatibility with previous versions as a list containing
52wxObjects and wxStringList as a list of C-style strings (char *), both of these
53classes are deprecated and should not be used in new programs. The following
54array classes are defined: wxArrayInt, wxArrayLong, wxArrayPtrVoid and
55wxArrayString. The first three store elements of corresponding types, but
56wxArrayString is somewhat special: it is an optimized version of wxArray which
57uses its knowledge about \helpref{wxString}{wxstring} reference counting
58schema.
59