#include <wx/arrstr.h>
wxArrayString is an efficient container for storing wxString objects.
It has the same features as all wxArray classes, i.e. it dynamically expands when new items are added to it (so it is as easy to use as a linked list), but the access time to the elements is constant, instead of being linear in number of elements as in the case of linked lists. It is also very size efficient and doesn't take more space than a C array wxString[] type (wxArrayString uses its knowledge of internals of wxString class to achieve this).
This class is used in the same way as other dynamic arrays(), except that no WX_DEFINE_ARRAY declaration is needed for it. When a string is added or inserted in the array, a copy of the string is created, so the original string may be safely deleted (e.g. if it was a wxChar * pointer the memory it was using can be freed immediately after this). In general, there is no need to worry about string memory deallocation when using this class - it will always free the memory it uses itself.
The references returned by wxArrayString::Item, wxArrayString::Last or wxArrayString::operator[] are not constant, so the array elements may be modified in place like this:
Although this is not true strictly speaking, this class may be considered as a specialization of wxArray class for the wxString member data: it is not implemented like this, but it does have all of the wxArray functions.
It also has the full set of
std::vector<wxString> compatible methods, including nested
iterator and
const_iterator classes which should be used in the new code for forward compatibility with the future wxWidgets versions.
The function type used with wxArrayString::Sort().
This function uses the same conventions as the standard
qsort() comparison function, that is it should return a negative value if the first argument is less than the second one, a positive value if the first argument is greater than the second one and 0 if the arguments are equal.
Default constructor.
Copy constructor.
Constructor from a C string array.
Pass a size sz and an array arr.
Constructor from a C string array.
Pass a size sz and an array arr.
Destructor frees memory occupied by the array strings.
For performance reasons it is not virtual, so this class should not be derived from.
Preallocates enough memory to store nCount items.
This function may be used to improve array class performance before adding a known number of items consecutively.
Empties the array: after a call to this function GetCount() will return 0.
However, this function does not free the memory used by the array and so should be used when the array is going to be reused for storing other strings. Otherwise, you should use Clear() to empty the array and free memory.
Returns the number of items in the array.
Searches the array for str, starting from the beginning if bFromEnd is false or from the end otherwise.
If bCase, comparison is case sensitive (default), otherwise the case is ignored.
This function uses linear search for wxArrayString. Returns the index of the first item matched or
wxNOT_FOUND if there is no match.
Inserts the given number of copies of str in the array before the array element at the position nIndex.
Thus, for example, to insert the string in the beginning of the array you would write:
If nIndex is equal to GetCount() this function behaves as Add().
Returns true if the array is empty, false otherwise.
This function returns the same result as GetCount() == 0 but is probably easier to read.
Return the array element at position nIndex.
An assert failure will result from an attempt to access an element beyond the end of array in debug mode, but no check is done in release mode.
Return the array element at position nIndex.
An assert failure will result from an attempt to access an element beyond the end of array in debug mode, but no check is done in release mode.
Returns the last element of the array.
Attempt to access the last element of an empty array will result in assert failure in debug build, however no checks are done in release mode.
Returns the last element of the array.
Attempt to access the last element of an empty array will result in assert failure in debug build, however no checks are done in release mode.
Compares 2 arrays respecting the case.
Returns true if the arrays have different number of elements or if the elements don't match pairwise.
Assignment operator.
Compares 2 arrays respecting the case.
Returns true only if the arrays have the same number of elements and the same strings in the same order.
Removes count items starting at position nIndex from the array.
Sorts the array in alphabetical order or in reverse alphabetical order if reverseOrder is true.
The sort is case-sensitive.
Sorts the array using the specified compareFunction for item comparison.
CompareFunction is defined as a function taking two const wxString& parameters and returning an int value less than, equal to or greater than 0 if the first string is less than, equal to or greater than the second one.
Example: The following example sorts strings by their length.