![]() ![]() ![]() ![]() container classes overviewwxwidgets uses itself several container classes including doubly-linked lists and dynamic arrays (i.e. arrays which expand automatically when they become full). for both historical and portability reasons wxwidgets does not use stl which provides the standard implementation of many container classes in c++. first of all, wxwidgets has existed since well before stl was written, and 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 will allow to base future versions of wxwidgets on stl - but this is not yet the case. wxwidgets container classes don't pretend to be as powerful or full as stl ones, but they are quite useful and may be compiled with absolutely any c++ compiler. they're used internally by wxwidgets, but may, of course, be used in your programs as well if you wish. the list classes in wxwidgets are doubly-linked lists which may either own the 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 pointers depending on whether you called or not wxlist::deletecontents method. dynamic arrays resemble c arrays but with two important differences: they provide run-time range checking in debug builds and they automatically expand 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. for the same portability reasons, the container classes implementation in wxwidgets does not use templates, but is rather based on c preprocessor i.e. is done with the macros: wx_declare_list and wx_define_list for the linked lists and wx_declare_array, wx_declare_objarray and wx_define_objarray for the dynamic arrays. the "declare" macro declares a 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 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. examples of usage of these macros may be found in wxlist and wxarray documentation. finally, wxwidgets predefines several commonly used container classes. wxlist 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 wxstring reference counting schema.
|