// Licence: wxWindows license
/////////////////////////////////////////////////////////////////////////////
+/**
+ @todo
+ the following functions are not documented; do they need to be?
+ WXDLLIMPEXP_BASE int wxCMPFUNC_CONV wxStringSortAscending(wxString*, wxString*);
+ WXDLLIMPEXP_BASE int wxCMPFUNC_CONV wxStringSortDescending(wxString*, wxString*);
+*/
+
/**
@class wxArrayString
@wxheader{arrstr.h}
(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
- @e WX_DEFINE_ARRAY declaration is needed for it.
+ ::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 @e wxChar *
pointer the memory it was using can be freed immediately after this).
array.Last().MakeUpper();
@endcode
- There is also a variant of wxArrayString called wxSortedArrayString which has
- exactly the same methods as wxArrayString, but which always keeps the string
- in it 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 which break the order of items) which is
- mentioned in their description.
-
@note none of the methods of wxArrayString is virtual including its
destructor, so this class should not be used as a base class.
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.
+ @todo what about stl? how does it integrate?
+
@library{wxbase}
@category{containers}
wxArrayString();
/**
- Copy constructor. Note that when an array is assigned to a sorted array,
- its contents is automatically sorted during construction.
+ Copy constructor.
*/
wxArrayString(const wxArrayString& array);
//@{
/**
- Constructor from a C string array. Pass a size sz and array arr.
+ Constructor from a C string array. Pass a size @a sz and an array @a arr.
**/
wxArrayString(size_t sz, const char** arr);
wxArrayString(size_t sz, const wchar_t** arr);
//@}
/**
- Constructor from a wxString array. Pass a size @a sz and array @e arr.
+ Constructor from a wxString array. Pass a size @a sz and array @a arr.
*/
wxArrayString(size_t sz, const wxString* arr);
Appends the given number of @a copies of the new item @a str to the
array and returns the index of the first new item in the array.
- @warning
- For sorted arrays, the index of the inserted item will not be, in general,
- equal to GetCount() - 1 because the item is inserted at the correct position
- to keep the array sorted and not appended.
-
@see Insert()
*/
size_t Add(const wxString& str, size_t copies = 1);
/**
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
+ 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.
*/
/**
Search the element in the array, starting from the beginning if @a bFromEnd
- is @false or from end otherwise. If @e bCase, comparison is case sensitive
+ is @false or from end otherwise. If @a bCase, comparison is case sensitive
(default), otherwise the case is ignored.
- This function uses linear search for wxArrayString and binary search for
- wxSortedArrayString, but it ignores the @a bCase and @a bFromEnd parameters
- in the latter case.
+ This function uses linear search for wxArrayString.
Returns index of the first item matched or @c wxNOT_FOUND if there is no match.
*/
- int Index(const wxString& sz, bool bCase = true,
- bool bFromEnd = false);
+ int Index(const wxString& sz, bool bCase = true, bool bFromEnd = false) const;
/**
Insert the given number of @a copies of the new element in the array before the
- position @e nIndex. Thus, for example, to insert the string in the beginning of
+ position @a nIndex. Thus, for example, to insert the string in the beginning of
the array you would write:
@code
Insert("foo", 0);
@endcode
-
- If @a nIndex is equal to @e GetCount() this function behaves as Add().
- @warning this function should not be used with sorted arrays because it
- could break the order of items and, for example, subsequent calls
- to Index() would then not work!
+ If @a nIndex is equal to GetCount() this function behaves as Add().
*/
void Insert(const wxString& str, size_t nIndex,
size_t copies = 1);
/**
Returns @true if the array is empty, @false otherwise. This function returns the
- same result as @e GetCount() == 0 but is probably easier to read.
+ same result as GetCount() == 0 but is probably easier to read.
*/
- bool IsEmpty();
+ bool IsEmpty() const;
/**
- Return the array element at position @e nIndex. An assert failure will
+ Return the array element at position @a 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.
@see operator[] for the operator version.
*/
- wxString Item(size_t nIndex) const;
+ wxString& Item(size_t nIndex) const;
/**
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.
*/
- wxString Last();
+ wxString& Last() const;
/**
Removes the first item matching this value. An assert failure is provoked by
/**
Sorts the array in alphabetical order or in reverse alphabetical order if
@a reverseOrder is @true. The sort is case-sensitive.
-
- @warning this function should not be used with sorted array because it could
- break the order of items and, for example, subsequent calls to Index()
- would then not work!
*/
-
void Sort(bool reverseOrder = false);
/**
Sorts the array using the specified @a compareFunction for item comparison.
- @e CompareFunction is defined as a function taking two @e const wxString
- parameters and returning an @e int value less than, equal to or greater
+ @a CompareFunction is defined as a function taking two @e const wxString
+ parameters and returning an @e 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.
{
return first.length() - second.length();
}
-
+
...
-
+
wxArrayString array;
-
+
array.Add("one");
array.Add("two");
array.Add("three");
array.Add("four");
-
+
array.Sort(CompareStringLen);
@endcode
-
- @warning this function should not be used with sorted array because
- it could break the order of items and, for example, subsequent
- calls to Index() would then not work!
*/
void Sort(CompareFunction compareFunction);
/**
Assignment operator.
*/
- wxArrayString operator =(const wxArrayString& array);
+ wxArrayString& operator=(const wxArrayString&);
/**
Compares 2 arrays respecting the case. Returns @true only if the arrays have
bool operator ==(const wxArrayString& array) const;
/**
- Return the array element at position @e nIndex. An assert failure will
+ Return the array element at position @a 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.
This is the operator version of the Item() method.
*/
- wxString operator[](size_t nIndex);
+ wxString& operator[](size_t nIndex) const;
};
+/**
+ @class wxSortedArrayString
+ @wxheader{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.
+
+ @todo what about STL? who does it integrates?
+
+ @library{wxbase}
+ @category{containers}
+
+ @see wxArray, wxString, @ref overview_string
+*/
+class wxSortedArrayString : public wxArrayString
+{
+public:
+
+ /**
+ Copy constructor. Note that when an array is assigned to a sorted array,
+ its contents is automatically sorted during construction.
+ */
+ wxArrayString(const wxArrayString& array);
+
+ /**
+ @copydoc wxArrayString::Add()
+
+ @warning
+ For sorted arrays, the index of the inserted item will not be, in general,
+ equal to GetCount() - 1 because the item is inserted at the correct position
+ to keep the array sorted and not appended.
+ */
+ size_t Add(const wxString& str, size_t copies = 1);
+
+
+ /**
+ @copydoc wxArrayString::Index()
+
+ This function uses binary search for wxSortedArrayString, but it ignores
+ the @a bCase and @a bFromEnd parameters.
+ */
+ int Index(const wxString& sz, bool bCase = true,
+ bool bFromEnd = false);
+
+ /**
+ @warning this function should not be used with sorted arrays because it
+ could break the order of items and, for example, subsequent calls
+ to Index() would then not work!
+ */
+ void Insert(const wxString& str, size_t nIndex,
+ size_t copies = 1);
+
+ //@{
+ /**
+ @warning this function should not be used with sorted array because it could
+ break the order of items and, for example, subsequent calls to Index()
+ would then not work! Also, sorting a wxSortedArrayString doesn't make
+ sense because its elements are always already sorted.
+ */
+ void Sort(bool reverseOrder = false);
+ void Sort(CompareFunction compareFunction);
+ //@}
+};
+
// ============================================================================
// Global functions/macros
separators.
@see wxJoin()
+
+ @header{wx/arrstr.h}
*/
wxArrayString wxSplit(const wxString& str, const wxChar sep,
const wxChar escape = '\\');
@a sep and returns the result as a wxString.
If the @a escape character is non-@NULL, then it's used as prefix for each
- occurrence of @e sep in the strings contained in @a arr before joining them
- which is necessary in order to be able to recover the original array contents
- from the string later using wxSplit().
+ occurrence of @a sep in the strings contained in @a arr before joining them
+ which is necessary in order to be able to recover the original array
+ contents from the string later using wxSplit().
@see wxSplit()
+
+ @header{wx/arrstr.h}
*/
wxString wxJoin(const wxArrayString& arr, const wxChar sep,
const wxChar escape = '\\');
//@}
+