1999-02-28 08:58:05 -05:00
|
|
|
\section{\class{wxArrayString}}\label{wxarraystring}
|
|
|
|
|
|
|
|
wxArrayString is an efficient container for storing
|
|
|
|
\helpref{wxString}{wxstring} objects. It has the same features as all
|
|
|
|
\helpref{wxArray}{wxarray} classes, i.e. it dynamically expands when new items
|
1999-02-28 15:59:08 -05:00
|
|
|
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
|
1999-10-22 05:24:15 -04:00
|
|
|
doesn't take more space than a C array {\it wxString[]} type (wxArrayString
|
|
|
|
uses its knowledge of internals of wxString class to achieve this).
|
1999-02-28 08:58:05 -05:00
|
|
|
|
|
|
|
This class is used in the same way as other dynamic \helpref{arrays}{wxarray},
|
|
|
|
except that no {\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
|
2006-11-26 15:20:52 -05:00
|
|
|
the original string may be safely deleted (e.g. if it was a {\it wxChar *}
|
1999-02-28 08:58:05 -05:00
|
|
|
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 \helpref{Item}{wxarraystringitem},
|
|
|
|
\helpref{Last}{wxarraystringlast} or
|
|
|
|
\helpref{operator[]}{wxarraystringoperatorindex} are not constant, so the
|
|
|
|
array elements may be modified in place like this
|
|
|
|
|
|
|
|
\begin{verbatim}
|
|
|
|
array.Last().MakeUpper();
|
|
|
|
\end{verbatim}
|
|
|
|
|
2002-06-07 16:15:28 -04:00
|
|
|
There is also a variant of wxArrayString called wxSortedArrayString which has
|
1999-10-22 05:24:15 -04:00
|
|
|
exactly the same methods as wxArrayString, but which always keeps the string
|
|
|
|
in it in (alphabetical) order. wxSortedArrayString uses binary search in its
|
2002-06-07 16:15:28 -04:00
|
|
|
\helpref{Index}{wxarraystringindex} function (instead of linear search for
|
1999-10-22 05:24:15 -04:00
|
|
|
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
|
2002-06-07 16:15:28 -04:00
|
|
|
not be used with sorted array (basically, all which break the order of items)
|
1999-10-22 05:24:15 -04:00
|
|
|
which is mentioned in their description.
|
|
|
|
|
|
|
|
Final word: none of the methods of wxArrayString is virtual including its
|
|
|
|
destructor, so this class should not be used as a base class.
|
1999-02-28 08:58:05 -05:00
|
|
|
|
1999-02-28 15:59:08 -05:00
|
|
|
\wxheading{Derived from}
|
1999-02-28 08:58:05 -05:00
|
|
|
|
|
|
|
Although this is not true strictly speaking, this class may be considered as a
|
|
|
|
specialization of \helpref{wxArray}{wxarray} class for the wxString member
|
|
|
|
data: it is not implemented like this, but it does have all of the wxArray
|
|
|
|
functions.
|
|
|
|
|
|
|
|
\wxheading{Include files}
|
|
|
|
|
Added --use-stl to cnfigure, wxUSE_STL to setup0.h
Moved wx/datetime.inl contents to wx/datetime.h and removed
inline redefinition hack.
Implemented STL-like interface on top of wxList/wxArray, when wxUSE_STL=0.
Implemented wxList-like and wxArray interfaces on top of std::list and
std::vector, when wxUSE_STL=1.
Added arrstr.h, moved wxArrayString declaration there; string.h
#includes arrstr.h only if WXWIN_COMPATIBILITY_2_4 is enabled.
Added WX_CLEAR_HASH_MAP, WX_CLEAR_HASH_TABLE, WX_CLEAR_LIST macros,
to clear a wxHashMap, wxHashTable, wxList containing pointers: deletes
pointers and makes container zero-sized.
When wxUSE_STL=1, wxStringList works like a std::list<wxString>.
Made wxBase compile when wxUSE_STL=1.
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@21768 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
2003-07-08 15:52:35 -04:00
|
|
|
<wx/arrstr.h>
|
1999-02-28 08:58:05 -05:00
|
|
|
|
2007-07-28 08:21:03 -04:00
|
|
|
\wxheading{Library}
|
|
|
|
|
|
|
|
\helpref{wxBase}{librarieslist}
|
|
|
|
|
1999-02-28 08:58:05 -05:00
|
|
|
\wxheading{See also}
|
|
|
|
|
1999-02-28 15:59:08 -05:00
|
|
|
\helpref{wxArray}{wxarray}, \helpref{wxString}{wxstring}, \helpref{wxString overview}{wxstringoverview}
|
1999-02-28 08:58:05 -05:00
|
|
|
|
|
|
|
\latexignore{\rtfignore{\wxheading{Members}}}
|
|
|
|
|
|
|
|
\membersection{wxArrayString::wxArrayString}\label{wxarraystringctor}
|
|
|
|
|
|
|
|
\func{}{wxArrayString}{\void}
|
|
|
|
|
2005-03-26 09:18:56 -05:00
|
|
|
Default constructor.
|
1999-02-28 08:58:05 -05:00
|
|
|
|
2005-03-26 09:18:56 -05:00
|
|
|
\func{}{wxArrayString}{\param{const wxArrayString\&}{ array}}
|
1999-02-28 08:58:05 -05:00
|
|
|
|
2005-03-26 09:18:56 -05:00
|
|
|
Copy constructor. Note that when an array is assigned to a sorted array, its contents is
|
1999-10-22 05:24:15 -04:00
|
|
|
automatically sorted during construction.
|
|
|
|
|
2007-06-28 14:56:00 -04:00
|
|
|
\func{}{wxArrayString}{\param{size\_t}{ sz}, \param{const char**}{ arr}}
|
|
|
|
|
|
|
|
\func{}{wxArrayString}{\param{size\_t}{ sz}, \param{const wchar\_t**}{ arr}}
|
2005-03-26 09:18:56 -05:00
|
|
|
|
|
|
|
Constructor from a C string array. Pass a size {\it sz} and array {\it arr}.
|
|
|
|
|
|
|
|
\func{}{wxArrayString}{\param{size\_t}{ sz}, \param{const wxString*}{ arr}}
|
|
|
|
|
|
|
|
Constructor from a wxString array. Pass a size {\it sz} and array {\it arr}.
|
|
|
|
|
1999-02-28 08:58:05 -05:00
|
|
|
\membersection{wxArrayString::\destruct{wxArrayString}}\label{wxarraystringdtor}
|
|
|
|
|
|
|
|
\func{}{\destruct{wxArrayString}}{}
|
|
|
|
|
|
|
|
Destructor frees memory occupied by the array strings. For the performance
|
|
|
|
reasons it is not virtual, so this class should not be derived from.
|
|
|
|
|
|
|
|
\membersection{wxArrayString::operator=}\label{wxarraystringoperatorassign}
|
|
|
|
|
|
|
|
\func{wxArrayString \&}{operator $=$}{\param{const wxArrayString\&}{ array}}
|
|
|
|
|
|
|
|
Assignment operator.
|
|
|
|
|
2000-07-15 15:51:35 -04:00
|
|
|
\membersection{wxArrayString::operator==}\label{wxarraystringoperatorequal}
|
|
|
|
|
|
|
|
\constfunc{bool}{operator $==$}{\param{const wxArrayString\&}{ array}}
|
|
|
|
|
2003-01-17 19:16:34 -05:00
|
|
|
Compares 2 arrays respecting the case. Returns true only if the arrays have
|
2000-07-15 15:51:35 -04:00
|
|
|
the same number of elements and the same strings in the same order.
|
|
|
|
|
|
|
|
\membersection{wxArrayString::operator!=}\label{wxarraystringoperatornotequal}
|
|
|
|
|
|
|
|
\constfunc{bool}{operator $!=$}{\param{const wxArrayString\&}{ array}}
|
|
|
|
|
2003-01-17 19:16:34 -05:00
|
|
|
Compares 2 arrays respecting the case. Returns true if the arrays have
|
2000-07-15 15:51:35 -04:00
|
|
|
different number of elements or if the elements don't match pairwise.
|
|
|
|
|
1999-02-28 08:58:05 -05:00
|
|
|
\membersection{wxArrayString::operator[]}\label{wxarraystringoperatorindex}
|
|
|
|
|
1999-10-22 05:24:15 -04:00
|
|
|
\func{wxString\&}{operator[]}{\param{size\_t }{nIndex}}
|
1999-02-28 08:58:05 -05:00
|
|
|
|
|
|
|
Return the array element at position {\it 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 \helpref{Item}{wxarraystringitem} method.
|
|
|
|
|
|
|
|
\membersection{wxArrayString::Add}\label{wxarraystringadd}
|
|
|
|
|
2002-05-04 11:26:24 -04:00
|
|
|
\func{size\_t}{Add}{\param{const wxString\& }{str}, \param{size\_t}{ copies = $1$}}
|
1999-02-28 08:58:05 -05:00
|
|
|
|
2002-05-04 11:26:24 -04:00
|
|
|
Appends the given number of {\it copies} of the new item {\it str} to the
|
|
|
|
array and returns the index of the first new item in the array.
|
1999-02-28 08:58:05 -05:00
|
|
|
|
1999-10-22 05:24:15 -04:00
|
|
|
{\bf Warning:} For sorted arrays, the index of the inserted item will not be,
|
|
|
|
in general, equal to \helpref{GetCount()}{wxarraystringgetcount} - 1 because
|
|
|
|
the item is inserted at the correct position to keep the array sorted and not
|
|
|
|
appended.
|
|
|
|
|
1999-02-28 08:58:05 -05:00
|
|
|
See also: \helpref{Insert}{wxarraystringinsert}
|
|
|
|
|
|
|
|
\membersection{wxArrayString::Alloc}\label{wxarraystringalloc}
|
|
|
|
|
|
|
|
\func{void}{Alloc}{\param{size\_t }{nCount}}
|
|
|
|
|
|
|
|
Preallocates enough memory to store {\it nCount} items. This function may be
|
|
|
|
used to improve array class performance before adding a known number of items
|
|
|
|
consecutively.
|
|
|
|
|
|
|
|
See also: \helpref{Dynamic array memory management}{wxarraymemorymanagement}
|
|
|
|
|
|
|
|
\membersection{wxArrayString::Clear}\label{wxarraystringclear}
|
|
|
|
|
|
|
|
\func{void}{Clear}{\void}
|
|
|
|
|
|
|
|
Clears the array contents and frees memory.
|
|
|
|
|
|
|
|
See also: \helpref{Empty}{wxarraystringempty}
|
|
|
|
|
|
|
|
\membersection{wxArrayString::Empty}\label{wxarraystringempty}
|
|
|
|
|
|
|
|
\func{void}{Empty}{\void}
|
|
|
|
|
|
|
|
Empties the array: after a call to this function
|
|
|
|
\helpref{GetCount}{wxarraystringgetcount} 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 \helpref{Clear}{wxarraystringclear} to empty the array and free
|
|
|
|
memory.
|
|
|
|
|
|
|
|
\membersection{wxArrayString::GetCount}\label{wxarraystringgetcount}
|
|
|
|
|
|
|
|
\constfunc{size\_t}{GetCount}{\void}
|
|
|
|
|
|
|
|
Returns the number of items in the array.
|
|
|
|
|
|
|
|
\membersection{wxArrayString::Index}\label{wxarraystringindex}
|
|
|
|
|
2007-06-28 14:56:00 -04:00
|
|
|
\func{int}{Index}{\param{const wxString\& }{ sz}, \param{bool}{ bCase = true}, \param{bool}{ bFromEnd = false}}
|
1999-02-28 08:58:05 -05:00
|
|
|
|
|
|
|
Search the element in the array, starting from the beginning if
|
2003-01-17 19:16:34 -05:00
|
|
|
{\it bFromEnd} is false or from end otherwise. If {\it bCase}, comparison is
|
1999-02-28 08:58:05 -05:00
|
|
|
case sensitive (default), otherwise the case is ignored.
|
|
|
|
|
1999-10-22 05:24:15 -04:00
|
|
|
This function uses linear search for wxArrayString and binary search for
|
|
|
|
wxSortedArrayString, but it ignores the {\it bCase} and {\it bFromEnd}
|
|
|
|
parameters in the latter case.
|
|
|
|
|
2004-10-20 07:12:56 -04:00
|
|
|
Returns index of the first item matched or {\tt wxNOT\_FOUND} if there is no match.
|
1999-02-28 08:58:05 -05:00
|
|
|
|
|
|
|
\membersection{wxArrayString::Insert}\label{wxarraystringinsert}
|
|
|
|
|
2002-05-04 11:26:24 -04:00
|
|
|
\func{void}{Insert}{\param{const wxString\& }{str}, \param{size\_t}{ nIndex}, \param{size\_t }{copies = $1$}}
|
1999-02-28 08:58:05 -05:00
|
|
|
|
2002-05-04 11:26:24 -04:00
|
|
|
Insert the given number of {\it copies} of the new element in the array before the position {\it nIndex}. Thus, for
|
1999-02-28 08:58:05 -05:00
|
|
|
example, to insert the string in the beginning of the array you would write
|
|
|
|
|
|
|
|
\begin{verbatim}
|
|
|
|
Insert("foo", 0);
|
|
|
|
\end{verbatim}
|
|
|
|
|
2002-03-05 19:24:33 -05:00
|
|
|
If {\it nIndex} is equal to {\it GetCount()} this function behaves as
|
1999-02-28 08:58:05 -05:00
|
|
|
\helpref{Add}{wxarraystringadd}.
|
|
|
|
|
2000-03-14 19:21:49 -05:00
|
|
|
{\bf Warning:} this function should not be used with sorted arrays because it
|
1999-10-22 05:24:15 -04:00
|
|
|
could break the order of items and, for example, subsequent calls to
|
2000-03-14 19:21:49 -05:00
|
|
|
\helpref{Index()}{wxarraystringindex} would then not work!
|
1999-10-22 05:24:15 -04:00
|
|
|
|
1999-02-28 08:58:05 -05:00
|
|
|
\membersection{wxArrayString::IsEmpty}\label{wxarraystringisempty}
|
|
|
|
|
2005-02-20 12:06:25 -05:00
|
|
|
\func{bool}{IsEmpty}{}
|
1999-02-28 08:58:05 -05:00
|
|
|
|
2003-01-17 19:16:34 -05:00
|
|
|
Returns true if the array is empty, false otherwise. This function returns the
|
1999-02-28 08:58:05 -05:00
|
|
|
same result as {\it GetCount() == 0} but is probably easier to read.
|
|
|
|
|
|
|
|
\membersection{wxArrayString::Item}\label{wxarraystringitem}
|
|
|
|
|
|
|
|
\constfunc{wxString\&}{Item}{\param{size\_t }{nIndex}}
|
|
|
|
|
|
|
|
Return the array element at position {\it 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 also \helpref{operator[]}{wxarraystringoperatorindex} for the operator
|
|
|
|
version.
|
|
|
|
|
|
|
|
\membersection{wxArrayString::Last}\label{wxarraystringlast}
|
|
|
|
|
2005-02-20 12:06:25 -05:00
|
|
|
\func{wxString&}{Last}{}
|
1999-02-28 08:58:05 -05:00
|
|
|
|
|
|
|
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.
|
|
|
|
|
2000-07-15 15:51:35 -04:00
|
|
|
\membersection{wxArrayString::Remove}\label{wxarraystringremove}
|
1999-02-28 08:58:05 -05:00
|
|
|
|
2007-06-28 14:56:00 -04:00
|
|
|
\func{void}{Remove}{\param{const wxString\&}{ sz}}
|
1999-02-28 08:58:05 -05:00
|
|
|
|
|
|
|
Removes the first item matching this value. An assert failure is provoked by
|
|
|
|
an attempt to remove an element which does not exist in debug build.
|
|
|
|
|
2000-07-15 15:51:35 -04:00
|
|
|
See also: \helpref{Index}{wxarraystringindex}
|
1999-02-28 08:58:05 -05:00
|
|
|
|
2003-07-03 18:01:56 -04:00
|
|
|
\membersection{wxArrayString::RemoveAt}\label{wxarraystringremoveat}
|
|
|
|
|
|
|
|
\func{void}{RemoveAt}{\param{size\_t }{nIndex}, \param{size\_t }{count = $1$}}
|
1999-02-28 08:58:05 -05:00
|
|
|
|
2002-05-04 11:26:24 -04:00
|
|
|
Removes {\it count} items starting at position {\it nIndex} from the array.
|
1999-02-28 08:58:05 -05:00
|
|
|
|
|
|
|
\membersection{wxArrayString::Shrink}\label{wxarraystringshrink}
|
|
|
|
|
|
|
|
\func{void}{Shrink}{\void}
|
|
|
|
|
|
|
|
Releases the extra memory allocated by the array. This function is useful to
|
|
|
|
minimize the array memory consumption.
|
|
|
|
|
|
|
|
See also: \helpref{Alloc}{wxarraystringalloc}, \helpref{Dynamic array memory management}{wxarraymemorymanagement}
|
|
|
|
|
2000-07-15 15:51:35 -04:00
|
|
|
\membersection{wxArrayString::Sort}\label{wxarraystringsort}
|
1999-02-28 08:58:05 -05:00
|
|
|
|
2003-01-17 19:16:34 -05:00
|
|
|
\func{void}{Sort}{\param{bool}{ reverseOrder = false}}
|
1999-02-28 08:58:05 -05:00
|
|
|
|
2000-03-14 19:21:49 -05:00
|
|
|
Sorts the array in alphabetical order or in reverse alphabetical order if
|
2003-04-28 06:37:08 -04:00
|
|
|
{\it reverseOrder} is true. The sort is case-sensitive.
|
1999-02-28 08:58:05 -05:00
|
|
|
|
1999-10-22 05:24:15 -04:00
|
|
|
{\bf Warning:} this function should not be used with sorted array because it
|
|
|
|
could break the order of items and, for example, subsequent calls to
|
2000-03-14 19:21:49 -05:00
|
|
|
\helpref{Index()}{wxarraystringindex} would then not work!
|
1999-10-22 05:24:15 -04:00
|
|
|
|
1999-02-28 08:58:05 -05:00
|
|
|
\func{void}{Sort}{\param{CompareFunction }{compareFunction}}
|
|
|
|
|
|
|
|
Sorts the array using the specified {\it compareFunction} for item comparison.
|
|
|
|
{\it CompareFunction} is defined as a function taking two {\it const
|
2000-03-14 19:21:49 -05:00
|
|
|
wxString\&} parameters and returning an {\it int} value less than, equal to or
|
1999-02-28 08:58:05 -05:00
|
|
|
greater than 0 if the first string is less than, equal to or greater than the
|
|
|
|
second one.
|
|
|
|
|
1999-02-28 15:59:08 -05:00
|
|
|
\wxheading{Example}
|
1999-02-28 08:58:05 -05:00
|
|
|
|
1999-02-28 15:59:08 -05:00
|
|
|
The following example sorts strings by their length.
|
1999-02-28 08:58:05 -05:00
|
|
|
|
1999-02-28 15:59:08 -05:00
|
|
|
\begin{verbatim}
|
1999-02-28 08:58:05 -05:00
|
|
|
static int CompareStringLen(const wxString& first, const wxString& second)
|
|
|
|
{
|
|
|
|
return first.length() - second.length();
|
|
|
|
}
|
|
|
|
|
|
|
|
...
|
|
|
|
|
|
|
|
wxArrayString array;
|
|
|
|
|
|
|
|
array.Add("one");
|
|
|
|
array.Add("two");
|
|
|
|
array.Add("three");
|
|
|
|
array.Add("four");
|
|
|
|
|
|
|
|
array.Sort(CompareStringLen);
|
|
|
|
\end{verbatim}
|
|
|
|
|
1999-10-22 05:24:15 -04:00
|
|
|
{\bf Warning:} this function should not be used with sorted array because it
|
|
|
|
could break the order of items and, for example, subsequent calls to
|
2000-03-14 19:21:49 -05:00
|
|
|
\helpref{Index()}{wxarraystringindex} would then not work!
|
1999-10-22 05:24:15 -04:00
|
|
|
|