X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/4050e98de9c43a9fa60dffb35202d89d749ba081..92c0fc34c104c8d7c12d6a3b78ea232690fc23f4:/interface/wx/dynarray.h diff --git a/interface/wx/dynarray.h b/interface/wx/dynarray.h index 54e1f22f73..9fba5c14f9 100644 --- a/interface/wx/dynarray.h +++ b/interface/wx/dynarray.h @@ -2,8 +2,7 @@ // Name: dynarray.h // Purpose: interface of wxArray // Author: wxWidgets team -// RCS-ID: $Id$ -// Licence: wxWindows license +// Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// /** @@ -32,7 +31,7 @@ functions are inline, so they do not take @e any space at all. wxWidgets has three different kinds of array. All of them derive from - wxBaseArray class which works with untyped data and can not be used + wxBaseArray class which works with untyped data and cannot 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, @@ -124,7 +123,7 @@ however dumb, C++ compiler in the world. Remember to include @ just before each - WX_DEFINE_OBJARRAY() ocurrence in your code, even if you have several in + WX_DEFINE_OBJARRAY() occurrence in your code, even if you have several in the same file. Things are much simpler for wxArray and wxSortedArray however: it is enough @@ -197,11 +196,24 @@ - WX_DEFINE_SORTED_USER_EXPORTED_ARRAY_INT() + @section array_predef Predefined array types + + wxWidgets defines the following dynamic array types: + - ::wxArrayShort + - ::wxArrayInt + - ::wxArrayDouble + - ::wxArrayLong + - ::wxArrayPtrVoid + + To use them you don't need any macro; you just need to include @c dynarray.h. + + @library{wxbase} @category{containers} @see @ref overview_container, wxList, wxVector */ +template class wxArray { public: @@ -224,10 +236,12 @@ public: Default constructor. */ wxArray(); + /** Default constructor initializes an empty array object. */ wxObjArray(); + /** There is no default constructor for wxSortedArray classes - you must initialize it with a function to use for item comparison. It is a @@ -239,32 +253,36 @@ public: wxSortedArray(int (*)(T first, T second)compareFunction); /** - Performs a shallow array copy (i.e. doesn't copy the objects pointed to + Performs a shallow array copy (i.e.\ doesn't copy the objects pointed to even if the source array contains the items of pointer type). */ wxArray(const wxArray& array); + /** - Performs a shallow array copy (i.e. doesn't copy the objects pointed to + Performs a shallow array copy (i.e.\ doesn't copy the objects pointed to even if the source array contains the items of pointer type). */ wxSortedArray(const wxSortedArray& array); + /** - Performs a deep copy (i.e. the array element are copied too). + Performs a deep copy (i.e.\ the array element are copied too). */ wxObjArray(const wxObjArray& array); /** - Performs a shallow array copy (i.e. doesn't copy the objects pointed to + Performs a shallow array copy (i.e.\ doesn't copy the objects pointed to even if the source array contains the items of pointer type). */ wxArray& operator=(const wxArray& array); + /** - Performs a shallow array copy (i.e. doesn't copy the objects pointed to + Performs a shallow array copy (i.e.\ doesn't copy the objects pointed to even if the source array contains the items of pointer type). */ wxSortedArray& operator=(const wxSortedArray& array); + /** - Performs a deep copy (i.e. the array element are copied too). + Performs a deep copy (i.e.\ the array element are copied too). */ wxObjArray& operator=(const wxObjArray& array); @@ -273,11 +291,13 @@ public: may use the WX_CLEAR_ARRAY() macro for this. */ ~wxArray(); + /** This destructor does not delete all the items owned by the array, you may use the WX_CLEAR_ARRAY() macro for this. */ ~wxSortedArray(); + /** This destructor deletes all the items owned by the array. */ @@ -355,7 +375,7 @@ public: T& Item(size_t index) const; /** - Returns the last element in the array, i.e. is the same as calling + Returns the last element in the array, i.e.\ is the same as calling "Item(GetCount() - 1)". An assert failure is raised in the debug mode if the array is empty. @@ -384,6 +404,7 @@ public: a lot of items. */ void Add(T item, size_t copies = 1); + /** Appends the @a item to the array consisting of the elements of type @c T. @@ -392,6 +413,7 @@ public: @a item is stored. */ size_t Add(T item); + /** Appends the @a item to the array consisting of the elements of type @c T. @@ -407,6 +429,7 @@ public: a lot of items. */ void Add(T* item); + /** Appends the given number of @a copies of the @a item to the array consisting of the elements of type @c T. @@ -445,6 +468,7 @@ public: overloaded versions of this function. */ void Insert(T item, size_t n, size_t copies = 1); + /** Insert the @a item into the array before the existing item @a n - thus, @e Insert(something, 0u) will insert an item in such way that it will @@ -457,6 +481,7 @@ public: overloaded versions of this function. */ void Insert(T* item, size_t n); + /** Insert the given number of @a copies of the @a item into the array before the existing item @a n - thus, @e Insert(something, 0u) will @@ -520,14 +545,20 @@ public: @code T *item = array[n]; + array.Remove(item); delete item; - array.Remove(n); @endcode See also WX_CLEAR_ARRAY() macro which deletes all elements of a wxArray (supposed to contain pointers). + + Notice that for sorted arrays this method uses binary search to find + the item so it doesn't necessarily remove the first matching item, but + the first one found by the binary search. + + @see RemoveAt() */ - Remove(T item); + void Remove(T item); /** Removes @a count elements starting at @a index from the array. When an @@ -545,7 +576,7 @@ public: See also WX_CLEAR_ARRAY() macro which deletes all elements of a wxArray (supposed to contain pointers). */ - RemoveAt(size_t index, size_t count = 1); + void RemoveAt(size_t index, size_t count = 1); //@} @@ -570,15 +601,16 @@ public: another, identical, element is in the array. */ int Index(T& item, bool searchFromEnd = false) const; + /** This version of Index() is for wxSortedArray only. - Searches the element in the array, starting from either beginning or - the end depending on the value of @a searchFromEnd parameter. + Searches for the element in the array, using binary search. + @c wxNOT_FOUND is returned if the element is not found, otherwise the index of the element is returned. */ - const int Index(T& item) const; + int Index(T& item) const; /** Search for a place to insert @a item into the sorted array (binary @@ -619,17 +651,17 @@ public: /** - This macro may be used to append all elements of the @a other array to the - @a array. The two arrays must be of the same type. + This macro may be used to append all elements of the @a wxArray_arrayToBeAppended + array to the @a wxArray_arrayToModify. The two arrays must be of the same type. */ -#define WX_APPEND_ARRAY(wxArray& array, wxArray& other) +#define WX_APPEND_ARRAY(wxArray_arrayToModify, wxArray_arrayToBeAppended) /** This macro may be used to delete all elements of the array before emptying - it. It can not be used with wxObjArrays - but they will delete their + it. It cannot be used with wxObjArrays - but they will delete their elements anyway when you call Empty(). */ -#define WX_CLEAR_ARRAY(wxArray& array) +#define WX_CLEAR_ARRAY(wxArray_arrayToBeCleared) //@{ /** @@ -764,8 +796,18 @@ public: //@} /** - This macro may be used to prepend all elements of the @a other array to the - @a array. The two arrays must be of the same type. + This macro may be used to prepend all elements of the @a wxArray_arrayToBePrepended + array to the @a wxArray_arrayToModify. The two arrays must be of the same type. */ -#define WX_PREPEND_ARRAY(wxArray& array, wxArray& other) +#define WX_PREPEND_ARRAY(wxArray_arrayToModify, wxArray_arrayToBePrepended) +//@{ +/** + Predefined specialization of wxArray for standard types. +*/ +typedef wxArray wxArrayInt; +typedef wxArray wxArrayLong; +typedef wxArray wxArrayShort; +typedef wxArray wxArrayDouble; +typedef wxArray wxArrayPtrVoid; +//@}