#include <wx/arrstr.h>
wxSortedArrayString is an efficient container for storing wxString objects which always keeps the string in alphabetical order.
wxSortedArrayString uses binary search in its wxArrayString::Index() function (instead of linear search for wxArrayString::Index()) which makes it much more efficient if you add strings to the array rarely (because, of course, you have to pay for Index() efficiency by having Add() be slower) but search for them often. Several methods should not be used with sorted array (basically, all those which break the order of items) which is mentioned in their description.
Public Member Functions | |
wxSortedArrayString (const wxArrayString &array) | |
Conversion constructor. | |
size_t | Add (const wxString &str, size_t copies=1) |
Appends the given number of copies of the new item str to the array and returns the index of the first new item in the array. | |
int | Index (const wxString &sz, bool bCase=true, bool bFromEnd=false) const |
Search the element in the array, starting from the beginning if bFromEnd is false or from end otherwise. | |
void | Insert (const wxString &str, size_t nIndex, size_t copies=1) |
void | Sort (bool reverseOrder=false) |
void | Sort (CompareFunction compareFunction) |
![]() | |
wxArrayString () | |
Default constructor. | |
wxArrayString (const wxArrayString &array) | |
Copy constructor. | |
wxArrayString (size_t sz, const wxString *arr) | |
Constructor from a wxString array. | |
~wxArrayString () | |
Destructor frees memory occupied by the array strings. | |
size_t | Add (const wxString &str, size_t copies=1) |
Appends the given number of copies of the new item str to the array and returns the index of the first new item in the array. | |
void | Alloc (size_t nCount) |
Preallocates enough memory to store nCount items. | |
void | Clear () |
Clears the array contents and frees memory. | |
void | Empty () |
Empties the array: after a call to this function GetCount() will return 0. | |
size_t | GetCount () const |
Returns the number of items in the array. | |
int | Index (const wxString &sz, bool bCase=true, bool bFromEnd=false) const |
Search the element in the array, starting from the beginning if bFromEnd is false or from end otherwise. | |
void | Insert (wxString lItem, size_t nIndex, size_t copies=1) |
Insert the given number of copies of the new element in the array before the position nIndex. | |
bool | IsEmpty () const |
Returns true if the array is empty, false otherwise. | |
void | Remove (const wxString &sz) |
Removes the first item matching this value. | |
void | RemoveAt (size_t nIndex, size_t count=1) |
Removes count items starting at position nIndex from the array. | |
void | Shrink () |
Releases the extra memory allocated by the array. | |
void | Sort (bool reverseOrder=false) |
Sorts the array in alphabetical order or in reverse alphabetical order if reverseOrder is true. | |
void | Sort (CompareFunction compareFunction) |
Sorts the array using the specified compareFunction for item comparison. | |
bool | operator!= (const wxArrayString &array) const |
Compares 2 arrays respecting the case. | |
wxArrayString & | operator= (const wxArrayString &) |
Assignment operator. | |
bool | operator== (const wxArrayString &array) const |
Compares 2 arrays respecting the case. | |
wxString & | operator[] (size_t nIndex) const |
Return the array element at position nIndex. | |
wxArrayString (size_t sz, const char **arr) | |
Constructor from a C string array. | |
wxArrayString (size_t sz, const wchar_t **arr) | |
Constructor from a C string array. | |
wxString & | Item (size_t nIndex) |
Return the array element at position nIndex. | |
const wxString & | Item (size_t nIndex) const |
Return the array element at position nIndex. | |
wxString & | Last () |
Returns the last element of the array. | |
const wxString & | Last () const |
Returns the last element of the array. | |
Additional Inherited Members | |
![]() | |
typedef int(* | CompareFunction )(const wxString &first, const wxString &second) |
The function type used with wxArrayString::Sort function. | |
wxSortedArrayString::wxSortedArrayString | ( | const wxArrayString & | array | ) |
Conversion constructor.
Constructs a sorted array with the same contents as the (possibly unsorted) "array" argument.
size_t wxSortedArrayString::Add | ( | const wxString & | str, |
size_t | copies = 1 |
||
) |
Appends the given number of copies of the new item str to the array and returns the index of the first new item in the array.
int wxSortedArrayString::Index | ( | const wxString & | sz, |
bool | bCase = true , |
||
bool | bFromEnd = false |
||
) | const |
Search the element in the array, starting from the beginning if bFromEnd is false or from end otherwise.
If bCase, comparison is case sensitive (default), otherwise the case is ignored.This function uses linear search for wxArrayString. Returns index of the first item matched or wxNOT_FOUND
if there is no match.
This function uses binary search for wxSortedArrayString, but it ignores the bCase and bFromEnd parameters.
void wxSortedArrayString::Insert | ( | const wxString & | str, |
size_t | nIndex, | ||
size_t | copies = 1 |
||
) |
void wxSortedArrayString::Sort | ( | bool | reverseOrder = false | ) |
void wxSortedArrayString::Sort | ( | CompareFunction | compareFunction | ) |