- wxBaseArray class which works with untyped data and can not be used directly.
- The standard macros WX_DEFINE_ARRAY(), WX_DEFINE_SORTED_ARRAY() and
- WX_DEFINE_OBJARRAY() are used to define a new class deriving from it. The
- classes declared will be called in this documentation wxArray, wxSortedArray and
- wxObjArray but you should keep in mind that no classes with such names actually
- exist, each time you use one of WX_DEFINE_XXXARRAY macro you define a class
- with a new name. In fact, these names are "template" names and each usage of one
- of the macros mentioned above creates a template specialization for the given
- element type.
-
- wxArray is suitable for storing integer types and pointers which it does not
- treat as objects in any way, i.e. the element pointed to by the pointer is not
- deleted when the element is removed from the array. It should be noted that
- all of wxArray's functions are inline, so it costs strictly nothing to define as
- many array types as you want (either in terms of the executable size or the
- speed) as long as at least one of them is defined and this is always the case
- because wxArrays are used by wxWidgets internally. This class has one serious
- limitation: it can only be used for storing integral types (bool, char, short,
- int, long and their unsigned variants) or pointers (of any kind). An attempt
- to use with objects of sizeof() greater than sizeof(long) will provoke a
- runtime assertion failure, however declaring a wxArray of floats will not (on
- the machines where sizeof(float) = sizeof(long)), yet it will @b not work,
- please use wxObjArray for storing floats and doubles.
-
- wxSortedArray is a wxArray variant which should be used when searching in the
- array is a frequently used operation. It requires you to define an additional
- function for comparing two elements of the array element type and always stores
- its items in the sorted order (according to this function). Thus, it is
- wxArray::Index function execution time is O(log(N)) instead of
- O(N) for the usual arrays but the wxArray::Add method is
- slower: it is O(log(N)) instead of constant time (neglecting time spent in
- memory allocation routine). However, in a usual situation elements are added to
- an array much less often than searched inside it, so wxSortedArray may lead to
- huge performance improvements compared to wxArray. Finally, it should be
- noticed that, as wxArray, wxSortedArray can be only used for storing integral
- types or pointers.
-
- wxObjArray class treats its elements like "objects". It may delete them when
- they are removed from the array (invoking the correct destructor) and copies
- them using the objects copy constructor. In order to implement this behaviour
- the definition of the wxObjArray arrays is split in two parts: first, you should
- declare the new wxObjArray class using WX_DECLARE_OBJARRAY() macro and then
- you must include the file defining the implementation of template type:
- wx/arrimpl.cpp and define the array class with WX_DEFINE_OBJARRAY() macro
- from a point where the full (as opposed to 'forward') declaration of the array
- elements class is in scope. As it probably sounds very complicated here is an
- example:
+ wxBaseArray class which works with untyped data and can not be used
+ directly. The standard macros WX_DEFINE_ARRAY(), WX_DEFINE_SORTED_ARRAY()
+ and WX_DEFINE_OBJARRAY() are used to define a new class deriving from it.
+ The classes declared will be called in this documentation wxArray,
+ wxSortedArray and wxObjArray but you should keep in mind that no classes
+ with such names actually exist, each time you use one of the
+ WX_DEFINE_XXXARRAY() macros, you define a class with a new name. In fact,
+ these names are "template" names and each usage of one of the macros
+ mentioned above creates a template specialization for the given element
+ type.
+
+ wxArray is suitable for storing integer types and pointers which it does
+ not treat as objects in any way, i.e. the element pointed to by the pointer
+ is not deleted when the element is removed from the array. It should be
+ noted that all of wxArray's functions are inline, so it costs strictly
+ nothing to define as many array types as you want (either in terms of the
+ executable size or the speed) as long as at least one of them is defined
+ and this is always the case because wxArrays are used by wxWidgets
+ internally. This class has one serious limitation: it can only be used for
+ storing integral types (bool, char, short, int, long and their unsigned
+ variants) or pointers (of any kind). An attempt to use with objects of
+ @c sizeof() greater than @c sizeof(long) will provoke a runtime assertion
+ failure, however declaring a wxArray of floats will not (on the machines
+ where @c "sizeof(float) <= sizeof(long)"), yet it will @b not work, please
+ use wxObjArray for storing floats and doubles.
+
+ wxSortedArray is a wxArray variant which should be used when searching in
+ the array is a frequently used operation. It requires you to define an
+ additional function for comparing two elements of the array element type
+ and always stores its items in the sorted order (according to this
+ function). Thus, its Index() function execution time is @c "O(log(N))"
+ instead of @c "O(N)" for the usual arrays but the Add() method is slower:
+ it is @c "O(log(N))" instead of constant time (neglecting time spent in
+ memory allocation routine). However, in a usual situation elements are
+ added to an array much less often than searched inside it, so wxSortedArray
+ may lead to huge performance improvements compared to wxArray. Finally, it
+ should be noticed that, as wxArray, wxSortedArray can be only used for
+ storing integral types or pointers.
+
+ wxObjArray class treats its elements like "objects". It may delete them
+ when they are removed from the array (invoking the correct destructor) and
+ copies them using the objects copy constructor. In order to implement this
+ behaviour the definition of the wxObjArray arrays is split in two parts:
+ first, you should declare the new wxObjArray class using the
+ WX_DECLARE_OBJARRAY() macro and then you must include the file defining the
+ implementation of template type: @<wx/arrimpl.cpp@> and define the array
+ class with the WX_DEFINE_OBJARRAY() macro from a point where the full (as
+ opposed to 'forward') declaration of the array elements class is in scope.
+ As it probably sounds very complicated here is an example: