File: arrstrng.tex

package info (click to toggle)
wxwidgets2.8 2.8.10.1-3
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 239,052 kB
  • ctags: 289,550
  • sloc: cpp: 1,838,857; xml: 396,717; python: 282,506; ansic: 126,171; makefile: 51,406; sh: 14,581; asm: 299; sql: 258; lex: 194; perl: 139; yacc: 128; pascal: 95; php: 39; lisp: 38; tcl: 24; haskell: 20; java: 18; cs: 18; erlang: 17; ruby: 16; ada: 9; ml: 9; csh: 9
file content (298 lines) | stat: -rw-r--r-- 11,326 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
\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
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 {\it 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 \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
the original string may be safely deleted (e.g. if it was a {\it 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 \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}

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 
\helpref{Index}{wxarraystringindex} 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.

Final word: none of the methods of wxArrayString is virtual including its
destructor, so this class should not be used as a base class.

\wxheading{Derived from}

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}

<wx/arrstr.h>

\wxheading{See also}

\helpref{wxArray}{wxarray}, \helpref{wxString}{wxstring}, \helpref{wxString overview}{wxstringoverview}

\latexignore{\rtfignore{\wxheading{Members}}}

\membersection{wxArrayString::wxArrayString}\label{wxarraystringctor}

\func{}{wxArrayString}{\void}

Default constructor.

\func{}{wxArrayString}{\param{const wxArrayString\&}{ array}}

Copy constructor. Note that when an array is assigned to a sorted array, its contents is
automatically sorted during construction.

\func{}{wxArrayString}{\param{size\_t}{ sz}, \param{const wxChar**}{ arr}}

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}.

\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.

\membersection{wxArrayString::operator==}\label{wxarraystringoperatorequal}

\constfunc{bool}{operator $==$}{\param{const wxArrayString\&}{ array}}

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.

\membersection{wxArrayString::operator!=}\label{wxarraystringoperatornotequal}

\constfunc{bool}{operator $!=$}{\param{const wxArrayString\&}{ array}}

Compares 2 arrays respecting the case. Returns true if the arrays have
different number of elements or if the elements don't match pairwise.

\membersection{wxArrayString::operator[]}\label{wxarraystringoperatorindex}

\func{wxString\&}{operator[]}{\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.

This is the operator version of \helpref{Item}{wxarraystringitem} method.

\membersection{wxArrayString::Add}\label{wxarraystringadd}

\func{size\_t}{Add}{\param{const wxString\& }{str}, \param{size\_t}{ copies = $1$}}

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.

{\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.

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::Count}\label{wxarraystringcount}

\constfunc{size\_t}{Count}{\void}

Returns the number of items in the array. This function is deprecated and is
for backwards compatibility only, please use 
\helpref{GetCount}{wxarraystringgetcount} instead.

\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}

\func{int}{Index}{\param{const wxChar *}{ sz}, \param{bool}{ bCase = true}, \param{bool}{ bFromEnd = false}}

Search the element in the array, starting from the beginning if
{\it bFromEnd} is false or from end otherwise. If {\it 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 {\it bCase} and {\it bFromEnd} 
parameters in the latter case.

Returns index of the first item matched or {\tt wxNOT\_FOUND} if there is no match.

\membersection{wxArrayString::Insert}\label{wxarraystringinsert}

\func{void}{Insert}{\param{const wxString\& }{str}, \param{size\_t}{ nIndex}, \param{size\_t }{copies = $1$}}

Insert the given number of {\it copies} of the new element in the array before the position {\it nIndex}. Thus, for
example, to insert the string in the beginning of the array you would write

\begin{verbatim}
Insert("foo", 0);
\end{verbatim}

If {\it nIndex} is equal to {\it GetCount()} this function behaves as 
\helpref{Add}{wxarraystringadd}.

{\bf Warning:} this function should not be used with sorted arrays because it
could break the order of items and, for example, subsequent calls to 
\helpref{Index()}{wxarraystringindex} would then not work!

\membersection{wxArrayString::IsEmpty}\label{wxarraystringisempty}

\func{bool}{IsEmpty}{}

Returns true if the array is empty, false otherwise. This function returns the
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}

\func{wxString&}{Last}{}

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.

\membersection{wxArrayString::Remove}\label{wxarraystringremove}

\func{void}{Remove}{\param{const wxChar *}{ sz}}

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.

See also: \helpref{Index}{wxarraystringindex}

\membersection{wxArrayString::RemoveAt}\label{wxarraystringremoveat}

\func{void}{RemoveAt}{\param{size\_t }{nIndex}, \param{size\_t }{count = $1$}}

Removes {\it count} items starting at position {\it nIndex} from the array.

\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}

\membersection{wxArrayString::Sort}\label{wxarraystringsort}

\func{void}{Sort}{\param{bool}{ reverseOrder = false}}

Sorts the array in alphabetical order or in reverse alphabetical order if 
{\it reverseOrder} is true. The sort is case-sensitive.

{\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 
\helpref{Index()}{wxarraystringindex} would then not work!

\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
wxString\&} parameters and returning an {\it 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.

\wxheading{Example}

The following example sorts strings by their length.

\begin{verbatim}
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}

{\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 
\helpref{Index()}{wxarraystringindex} would then not work!