1999-01-02 18:02:30 -05:00
|
|
|
\section{Container classes overview}\label{wxcontaineroverview}
|
|
|
|
|
|
|
|
Classes: \helpref{wxList}{wxlist}, \helpref{wxArray}{wxarray}
|
|
|
|
|
2004-05-04 04:27:20 -04:00
|
|
|
wxWidgets uses itself several container classes including doubly-linked lists
|
1999-01-02 18:02:30 -05:00
|
|
|
and dynamic arrays (i.e. arrays which expand automatically when they become
|
2004-05-04 04:27:20 -04:00
|
|
|
full). For both historical and portability reasons wxWidgets does not
|
1999-01-02 18:02:30 -05:00
|
|
|
use STL which provides the standard implementation of many container classes in
|
2004-05-04 04:27:20 -04:00
|
|
|
C++. First of all, wxWidgets has existed since well before STL was written, and
|
1999-01-02 18:02:30 -05:00
|
|
|
secondly we don't believe that today compilers can deal really well with all of
|
|
|
|
STL classes (this is especially true for some less common platforms). Of
|
|
|
|
course, the compilers are evolving quite rapidly and hopefully their progress
|
2004-05-04 04:27:20 -04:00
|
|
|
will allow to base future versions of wxWidgets on STL - but this is not yet
|
1999-01-02 18:02:30 -05:00
|
|
|
the case.
|
|
|
|
|
2004-05-04 04:27:20 -04:00
|
|
|
wxWidgets container classes don't pretend to be as powerful or full as STL
|
1999-01-02 18:02:30 -05:00
|
|
|
ones, but they are quite useful and may be compiled with absolutely any C++
|
2004-05-04 04:27:20 -04:00
|
|
|
compiler. They're used internally by wxWidgets, but may, of course, be used in
|
1999-01-02 18:02:30 -05:00
|
|
|
your programs as well if you wish.
|
|
|
|
|
2004-05-04 04:27:20 -04:00
|
|
|
The list classes in wxWidgets are doubly-linked lists which may either own the
|
1999-01-02 18:02:30 -05:00
|
|
|
objects they contain (meaning that the list deletes the object when it is
|
|
|
|
removed from the list or the list itself is destroyed) or just store the
|
1999-01-10 18:15:35 -05:00
|
|
|
pointers depending on whether you called or not
|
1999-01-02 18:02:30 -05:00
|
|
|
\helpref{wxList::DeleteContents}{wxlistdeletecontents} method.
|
|
|
|
|
1999-01-24 18:56:51 -05:00
|
|
|
Dynamic arrays resemble C arrays but with two important differences: they
|
2004-09-03 22:44:43 -04:00
|
|
|
provide run-time range checking in debug builds and they automatically expand
|
1999-01-02 18:02:30 -05:00
|
|
|
the allocated memory when there is no more space for new items. They come in
|
|
|
|
two sorts: the "plain" arrays which store either built-in types such as "char",
|
|
|
|
"int" or "bool" or the pointers to arbitrary objects, or "object arrays" which
|
|
|
|
own the object pointers to which they store.
|
|
|
|
|
2004-05-04 04:27:20 -04:00
|
|
|
For the same portability reasons, the container classes implementation in wxWidgets
|
1999-01-02 18:02:30 -05:00
|
|
|
does not use templates, but is rather based on C preprocessor i.e. is done with
|
|
|
|
the macros: {\it WX\_DECLARE\_LIST} and {\it WX\_DEFINE\_LIST} for the linked
|
1999-01-12 13:28:34 -05:00
|
|
|
lists and {\it WX\_DECLARE\_ARRAY}, {\it WX\_DECLARE\_OBJARRAY} and {\it WX\_DEFINE\_OBJARRAY} for
|
|
|
|
the dynamic arrays. The "DECLARE" macro declares a
|
1999-01-02 18:02:30 -05:00
|
|
|
new container class containing the elements of given type and is needed for all
|
|
|
|
three types of container classes: lists, arrays and objarrays. The "DEFINE"
|
|
|
|
classes must be inserted in your program in a place where the {\bf full
|
|
|
|
declaration of container element class is in scope} (i.e. not just forward
|
|
|
|
declaration), otherwise destructors of the container elements will not be
|
|
|
|
called! As array classes never delete the items they contain anyhow, there is
|
|
|
|
no WX\_DEFINE\_ARRAY macro for them.
|
|
|
|
|
1999-01-24 18:56:51 -05:00
|
|
|
Examples of usage of these macros may be found in \helpref{wxList}{wxlist} and
|
1999-01-02 18:02:30 -05:00
|
|
|
\helpref{wxArray}{wxarray} documentation.
|
|
|
|
|
2004-05-04 04:27:20 -04:00
|
|
|
Finally, wxWidgets predefines several commonly used container classes. wxList
|
1999-01-02 18:02:30 -05:00
|
|
|
is defined for compatibility with previous versions as a list containing
|
|
|
|
wxObjects and wxStringList as a list of C-style strings (char *), both of these
|
|
|
|
classes are deprecated and should not be used in new programs. The following
|
|
|
|
array classes are defined: wxArrayInt, wxArrayLong, wxArrayPtrVoid and
|
|
|
|
wxArrayString. The first three store elements of corresponding types, but
|
|
|
|
wxArrayString is somewhat special: it is an optimized version of wxArray which
|
|
|
|
uses its knowledge about \helpref{wxString}{wxstring} reference counting
|
|
|
|
schema.
|
|
|
|
|