]> git.saurik.com Git - wxWidgets.git/blame_incremental - docs/doxygen/overviews/container.h
Fix broken and missing DataView interface items for Phoenix
[wxWidgets.git] / docs / doxygen / overviews / container.h
... / ...
CommitLineData
1/////////////////////////////////////////////////////////////////////////////
2// Name: container.h
3// Purpose: topic overview
4// Author: wxWidgets team
5// RCS-ID: $Id$
6// Licence: wxWindows licence
7/////////////////////////////////////////////////////////////////////////////
8
9/**
10
11@page overview_container Container Classes
12
13@tableofcontents
14
15For historical reasons, wxWidgets uses custom container classes internally.
16This was unfortunately unavoidable during a long time when the standard library
17wasn't widely available and can't be easily changed even now that it is for
18compatibility reasons. If you are building your own version of the library and
19don't care about compatibility nor slight (less than 5%) size penalty imposed
20by the use of STL classes, you may choose to use the "STL" build of wxWidgets
21in which these custom classes are replaced with their standard counterparts and
22only read the section @ref overview_container_std explaining how to do it.
23
24Otherwise you will need to know about the custom wxWidgets container classes
25such as wxList<T> and wxArray<T> if only to use wxWidgets functions that work
26with them, e.g. wxWindow::GetChildren(), and you should find the information
27about using these classes below useful.
28
29Notice that we recommend that you use standard classes directly in your own
30code instead of the container classes provided by wxWidgets in any case as the
31standard classes are easier to use and may also be safer because of extra
32run-time checks they may perform as well as more efficient.
33
34Finally notice that recent versions of wxWidgets also provide standard-like
35classes such as wxVector<T>, wxStack<T> or wxDList which can be used exactly
36like the std::vector<T>, std::stack<T> and std::list<T*>, respectively, and
37actually are just typedefs for the corresponding types if wxWidgets is compiled
38in STL mode. These classes could be useful if you wish to avoid the use of the
39standard library in your code for some reason.
40
41To summarize, you should use the standard container classes such as
42std::vector<T> and std::list<T> if possible and wxVector<T> or wxDList<T> if
43it isn't and only use legacy wxWidgets containers such as wxArray<T> and
44wxList<T> when you must, i.e. when you use a wxWidgets function taking or
45returning a container of such type.
46
47@see @ref group_class_containers
48
49
50
51@section overview_container_legacy Legacy Classes
52
53The list classes in wxWidgets are doubly-linked lists which may either own the
54objects they contain (meaning that the list deletes the object when it is
55removed from the list or the list itself is destroyed) or just store the
56pointers depending on whether or not you called wxList<T>::DeleteContents()
57method.
58
59Dynamic arrays resemble C arrays but with two important differences: they
60provide run-time range checking in debug builds and they automatically expand
61the allocated memory when there is no more space for new items. They come in
62two sorts: the "plain" arrays which store either built-in types such as "char",
63"int" or "bool" or the pointers to arbitrary objects, or "object arrays" which
64own the object pointers to which they store.
65
66For the same portability reasons, the container classes implementation in
67wxWidgets don't use templates, but are rather based on C preprocessor i.e. are
68implemented using the macros: WX_DECLARE_LIST() and WX_DEFINE_LIST() for the
69linked lists and WX_DECLARE_ARRAY(), WX_DECLARE_OBJARRAY() and
70WX_DEFINE_OBJARRAY() for the dynamic arrays.
71
72The "DECLARE" macro declares a new container class containing the elements of
73given type and is needed for all three types of container classes: lists,
74arrays and objarrays. The "DEFINE" classes must be inserted in your program in
75a place where the @e full declaration of container element class is in scope
76(i.e. not just forward declaration), otherwise destructors of the container
77elements will not be called!
78
79As array classes never delete the items they contain anyhow, there is no
80WX_DEFINE_ARRAY() macro for them.
81
82Examples of usage of these macros may be found in wxList<T> and wxArray<T>
83documentation.
84
85Finally, wxWidgets predefines several commonly used container classes. wxList
86is defined for compatibility with previous versions as a list containing
87wxObjects and wxStringList as a list of C-style strings (char *), both of these
88classes are deprecated and should not be used in new programs. The following
89array classes are defined: wxArrayInt, wxArrayLong, wxArrayPtrVoid and
90wxArrayString. The first three store elements of corresponding types, but
91wxArrayString is somewhat special: it is an optimized version of wxArray which
92uses its knowledge about wxString reference counting schema.
93
94
95
96@section overview_container_std STL Build
97
98To build wxWidgets with the standard containers you need to set
99wxUSE_STD_CONTAINERS option to 1 in @c wx/msw/setup.h for wxMSW builds or
100specify @c --enable-std_containers option to configure (which is also
101implicitly enabled by @c --enable-stl option) in Unix builds.
102
103The standard container build is mostly, but not quite, compatible with the
104default one. Here are the most important differences:
105 - wxList::compatibility_iterator must be used instead of wxList::Node* when
106 iterating over the list contents. The compatibility_iterator class has the
107 same semantics as a Node pointer but it is an object and not a pointer, so
108 you need to write
109 @code
110 for ( wxWindowList::compatibility_iterator it = list.GetFirst();
111 it;
112 it = it->GetNext() )
113 ...
114 @endcode
115 instead of the old
116 @code
117 for ( wxWindowList::Node *n = list.GetFirst(); n; n = n->GetNext() )
118 ...
119 @endcode
120 - wxSortedArrayString and wxArrayString are separate classes now and the
121 former doesn't derive from the latter. If you need to convert a sorted array
122 to a normal one, you must copy all the elements. Alternatively, you may
123 avoid the use of wxSortedArrayString by using a normal array and calling its
124 Sort() method when needed.
125 - WX_DEFINE_ARRAY_INT(bool) cannot be used because of the differences in
126 std::vector<bool> specialization compared with the generic std::vector<>
127 class. Please either use std::vector<bool> directly or use an integer array
128 instead.
129
130*/