]> git.saurik.com Git - wxWidgets.git/blob - docs/latex/wx/variant.tex
a6cd0b1a1cf9ddc8bf08d9412e1e5dde9acc6b1a
[wxWidgets.git] / docs / latex / wx / variant.tex
1 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2 %% Name: variant.tex
3 %% Purpose: wxVariant docs
4 %% Author: wxWidgets Team
5 %% Modified by:
6 %% Created: 01/30/2005
7 %% RCS-ID: $Id$
8 %% Copyright: (c) wxWidgets Team
9 %% License: wxWindows license
10 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
11
12 \section{\class{wxVariant}}\label{wxvariant}
13
14 The {\bf wxVariant} class represents a container for any type.
15 A variant's value can be changed at run time, possibly to a different type of value.
16
17 As standard, wxVariant can store values of type bool, char, double, long, string,
18 string list, time, date, void pointer, list of strings, and list of variants.
19 However, an application can extend wxVariant's capabilities by deriving from the
20 class \helpref{wxVariantData}{wxvariantdata} and using the wxVariantData form of
21 the wxVariant constructor or assignment operator to assign this data to a variant.
22 Actual values for user-defined types will need to be accessed via the wxVariantData
23 object, unlike the case for basic data types where convenience functions such as
24 \helpref{GetLong}{wxvariantgetlong} can be used.
25
26 Pointers to any \helpref{wxObject}{helpref} derived class can also easily be stored
27 in a wxVariant. wxVariant will then use wxWidgets' built-in RTTI system to set the
28 type name (returned by \helpref{GetType}{wxvariantgettype}) and to perform
29 type-safety checks at runtime.
30
31 This class is useful for reducing the programming for certain tasks, such as an editor
32 for different data types, or a remote procedure call protocol.
33
34 An optional name member is associated with a wxVariant. This might be used, for example, in CORBA
35 or OLE automation classes, where named parameters are required.
36
37 Note that as of wxWidgets 2.7.1, wxVariant is reference counted.
38
39 \wxheading{Derived from}
40
41 \helpref{wxObject}{wxobject}
42
43 \wxheading{Include files}
44
45 <wx/variant.h>
46
47 \wxheading{See also}
48
49 \helpref{wxVariantData}{wxvariantdata}
50
51 \latexignore{\rtfignore{\wxheading{Members}}}
52
53 \membersection{wxVariant::wxVariant}\label{wxvariantctor}
54
55 \func{}{wxVariant}{\void}
56
57 Default constructor.
58
59 \func{}{wxVariant}{\param{const wxVariant\& }{variant}}
60
61 Copy constructor.
62
63 \func{}{wxVariant}{\param{const char*}{ value}, \param{const wxString\& }{name = ``"}}
64
65 \func{}{wxVariant}{\param{const wxString\&}{ value}, \param{const wxString\& }{name = ``"}}
66
67 Construction from a string value.
68
69 \func{}{wxVariant}{\param{char}{ value}, \param{const wxString\& }{name = ``"}}
70
71 Construction from a character value.
72
73 \func{}{wxVariant}{\param{long}{ value}, \param{const wxString\& }{name = ``"}}
74
75 Construction from an integer value. You may need to cast to (long) to
76 avoid confusion with other constructors (such as the bool constructor).
77
78 \func{}{wxVariant}{\param{bool}{ value}, \param{const wxString\& }{name = ``"}}
79
80 Construction from a boolean value.
81
82 \func{}{wxVariant}{\param{double}{ value}, \param{const wxString\& }{name = ``"}}
83
84 Construction from a double-precision floating point value.
85
86 \func{}{wxVariant}{\param{const wxList\&}{ value}, \param{const wxString\& }{name = ``"}}
87
88 Construction from a list of wxVariant objects. This constructor
89 copies {\it value}, the application is still responsible for
90 deleting {\it value} and its contents.
91
92 \func{}{wxVariant}{\param{void*}{ value}, \param{const wxString\& }{name = ``"}}
93
94 Construction from a void pointer.
95
96 \func{}{wxVariant}{\param{wxObject*}{ value}, \param{const wxString\& }{name = ``"}}
97
98 Construction from a wxObject pointer.
99
100 \func{}{wxVariant}{\param{wxVariantData*}{ data}, \param{const wxString\& }{name = ``"}}
101
102 Construction from user-defined data. The variant holds onto the {\it data} pointer.
103
104 \func{}{wxVariant}{\param{wxDateTime\&}{ val}, \param{const wxString\& }{name = ``"}}
105
106 Construction from a \helpref{wxDateTime}{wxdatetime}.
107
108 \func{}{wxVariant}{\param{wxArrayString\&}{ val}, \param{const wxString\& }{name = ``"}}
109
110 Construction from an array of strings. This constructor copies {\it value} and its contents.
111
112 \func{}{wxVariant}{\param{DATE\_STRUCT*}{ val}, \param{const wxString\& }{name = ``"}}
113
114 Construction from a odbc date value. Represented internally by a \helpref{wxDateTime}{wxdatetime} value.
115
116 \func{}{wxVariant}{\param{TIME\_STRUCT*}{ val}, \param{const wxString\& }{name = ``"}}
117
118 Construction from a odbc time value. Represented internally by a \helpref{wxDateTime}{wxdatetime} value.
119
120 \func{}{wxVariant}{\param{TIMESTAMP\_STRUCT*}{ val}, \param{const wxString\& }{name = ``"}}
121
122 Construction from a odbc timestamp value. Represented internally by a \helpref{wxDateTime}{wxdatetime} value.
123
124 \membersection{wxVariant::\destruct{wxVariant}}\label{wxvariantdtor}
125
126 \func{}{\destruct{wxVariant}}{\void}
127
128 Destructor.
129
130 Note that destructor is protected, so wxVariantData cannot usually
131 be deleted. Instead, \helpref{DecRef}{wxvariantdatadecref} should be called.
132
133
134 \membersection{wxVariant::Append}\label{wxvariantappend}
135
136 \func{void}{Append}{\param{const wxVariant\&}{ value}}
137
138 Appends a value to the list.
139
140 \membersection{wxVariant::Clear}\label{wxvariantclear}
141
142 \func{void}{Clear}{\void}
143
144 Makes the variant null by deleting the internal data and
145 set the name to {\it wxEmptyString}.
146
147 \membersection{wxVariant::ClearList}\label{wxvariantclearlist}
148
149 \func{void}{ClearList}{\void}
150
151 Deletes the contents of the list.
152
153
154 \membersection{wxVariant::Convert}\label{wxvariantconvert}
155
156 \constfunc{bool}{Convert}{\param{long*}{ value}}
157
158 \constfunc{bool}{Convert}{\param{bool*}{ value}}
159
160 \constfunc{bool}{Convert}{\param{double*}{ value}}
161
162 \constfunc{bool}{Convert}{\param{wxString*}{ value}}
163
164 \constfunc{bool}{Convert}{\param{char*}{ value}}
165
166 \constfunc{bool}{Convert}{\param{wxDateTime*}{ value}}
167
168 Retrieves and converts the value of this variant to the type that {\it value} is.
169
170
171 \membersection{wxVariant::GetCount}\label{wxvariantgetcount}
172
173 \constfunc{size\_t}{GetCount}{\void}
174
175 Returns the number of elements in the list.
176
177 \membersection{wxVariant::Delete}\label{wxvariantdelete}
178
179 \func{bool}{Delete}{\param{size\_t }{item}}
180
181 Deletes the zero-based {\it item} from the list.
182
183 \membersection{wxVariant::GetArrayString}\label{wxvariantgetarraystring}
184
185 \constfunc{wxArrayString}{GetArrayString}{\void}
186
187 Returns the string array value.
188
189 \membersection{wxVariant::GetBool}\label{wxvariantgetbool}
190
191 \constfunc{bool}{GetBool}{\void}
192
193 Returns the boolean value.
194
195 \membersection{wxVariant::GetChar}\label{wxvariantgetchar}
196
197 \constfunc{char}{GetChar}{\void}
198
199 Returns the character value.
200
201 \membersection{wxVariant::GetData}\label{wxvariantgetdata}
202
203 \constfunc{wxVariantData*}{GetData}{\void}
204
205 Returns a pointer to the internal variant data. To take ownership
206 of this data, you must call its \helpref{IncRef}{wxvariantdataincref}
207 method. When you stop using it, \helpref{DecRef}{wxvariantdatadecref}
208 must be likewise called.
209
210 \membersection{wxVariant::GetDateTime}\label{wxvariantgetdatetime}
211
212 \constfunc{wxDateTime}{GetDateTime}{\void}
213
214 Returns the date value.
215
216 \membersection{wxVariant::GetDouble}\label{wxvariantgetdouble}
217
218 \constfunc{double}{GetDouble}{\void}
219
220 Returns the floating point value.
221
222 \membersection{wxVariant::GetLong}\label{wxvariantgetlong}
223
224 \constfunc{long}{GetLong}{\void}
225
226 Returns the integer value.
227
228 \membersection{wxVariant::GetName}\label{wxvariantgetname}
229
230 \constfunc{const wxString\&}{GetName}{\void}
231
232 Returns a constant reference to the variant name.
233
234 \membersection{wxVariant::GetString}\label{wxvariantgetstring}
235
236 \constfunc{wxString}{GetString}{\void}
237
238 Gets the string value.
239
240 \membersection{wxVariant::GetType}\label{wxvariantgettype}
241
242 \constfunc{wxString}{GetType}{\void}
243
244 Returns the value type as a string. The built-in types are: bool, char, date, double, list, long, string, stringlist, time, void*.
245
246 If the variant is null, the value type returned is the string ``null" (not the empty string).
247
248 \membersection{wxVariant::GetVoidPtr}\label{wxvariantgetvoidptr}
249
250 \constfunc{void*}{GetVoidPtr}{\void}
251
252 Gets the void pointer value.
253
254 \membersection{wxVariant::GetWxObjectPtr}\label{wxvariantgetwxobjectptr}
255
256 \constfunc{wxObject*}{GetWxObjectPtr}{\void}
257
258 Gets the wxObject pointer value.
259
260 \membersection{wxVariant::Insert}\label{wxvariantinsert}
261
262 \func{void}{Insert}{\param{const wxVariant\&}{ value}}
263
264 Inserts a value at the front of the list.
265
266 \membersection{wxVariant::IsNull}\label{wxvariantisnull}
267
268 \constfunc{bool}{IsNull}{\void}
269
270 Returns true if there is no data associated with this variant, false if there is data.
271
272 \membersection{wxVariant::IsType}\label{wxvariantistype}
273
274 \constfunc{bool}{IsType}{\param{const wxString\&}{ type}}
275
276 Returns true if {\it type} matches the type of the variant, false otherwise.
277
278 \membersection{wxVariant::IsValueKindOf}\label{wxvariantisvaluekindof}
279
280 \constfunc{bool}{IsValueKindOf}{\param{const wxClassInfo* type}{ type}}
281
282 Returns true if the data is derived from the class described by {\it type}, false otherwise.
283
284 \membersection{wxVariant::MakeNull}\label{wxvariantmakenull}
285
286 \func{void}{MakeNull}{\void}
287
288 Makes the variant null by deleting the internal data.
289
290 \membersection{wxVariant::MakeString}\label{wxvariantmakestring}
291
292 \constfunc{wxString}{MakeString}{\void}
293
294 Makes a string representation of the variant value (for any type).
295
296 \membersection{wxVariant::Member}\label{wxvariantmember}
297
298 \constfunc{bool}{Member}{\param{const wxVariant\&}{ value}}
299
300 Returns true if {\it value} matches an element in the list.
301
302 \membersection{wxVariant::NullList}\label{wxvariantnulllist}
303
304 \func{void}{NullList}{\void}
305
306 Makes an empty list. This differs from a null variant which has no data; a null list
307 is of type list, but the number of elements in the list is zero.
308
309 \membersection{wxVariant::SetData}\label{wxvariantsetdata}
310
311 \func{void}{SetData}{\param{wxVariantData*}{ data}}
312
313 Sets the internal variant data, deleting the existing data if there is any.
314
315 \membersection{wxVariant::operator $=$}\label{wxvariantassignment}
316
317 \func{void}{operator $=$}{\param{const wxVariant\& }{value}}
318
319 \func{void}{operator $=$}{\param{wxVariantData* }{value}}
320
321 \func{void}{operator $=$}{\param{const wxString\& }{value}}
322
323 \func{void}{operator $=$}{\param{const char* }{value}}
324
325 \func{void}{operator $=$}{\param{char }{value}}
326
327 \func{void}{operator $=$}{\param{const long }{value}}
328
329 \func{void}{operator $=$}{\param{const bool }{value}}
330
331 \func{void}{operator $=$}{\param{const double }{value}}
332
333 \func{void}{operator $=$}{\param{void* }{value}}
334
335 \func{void}{operator $=$}{\param{wxObject* }{value}}
336
337 \func{void}{operator $=$}{\param{const wxList\& }{value}}
338
339 \func{void}{operator $=$}{\param{const wxDateTime\& }{value}}
340
341 \func{void}{operator $=$}{\param{const wxArrayString\& }{value}}
342
343 \func{void}{operator $=$}{\param{const DATE\_STRUCT* }{value}}
344
345 \func{void}{operator $=$}{\param{const TIME\_STRUCT* }{value}}
346
347 \func{void}{operator $=$}{\param{const TIMESTAMP\_STRUCT* }{value}}
348
349 Assignment operators.
350
351 \membersection{wxVariant::operator $==$}\label{wxvarianteq}
352
353 \constfunc{bool}{operator $==$}{\param{const wxVariant\& }{value}}
354
355 \constfunc{bool}{operator $==$}{\param{const wxString\& }{value}}
356
357 \constfunc{bool}{operator $==$}{\param{const char* }{value}}
358
359 \constfunc{bool}{operator $==$}{\param{char }{value}}
360
361 \constfunc{bool}{operator $==$}{\param{const long }{value}}
362
363 \constfunc{bool}{operator $==$}{\param{const bool }{value}}
364
365 \constfunc{bool}{operator $==$}{\param{const double }{value}}
366
367 \constfunc{bool}{operator $==$}{\param{void* }{value}}
368
369 \constfunc{bool}{operator $==$}{\param{wxObject* }{value}}
370
371 \constfunc{bool}{operator $==$}{\param{const wxList\& }{value}}
372
373 \constfunc{bool}{operator $==$}{\param{const wxArrayString\& }{value}}
374
375 \constfunc{bool}{operator $==$}{\param{const wxDateTime\& }{value}}
376
377 Equality test operators.
378
379 \membersection{wxVariant::operator $!=$}\label{wxvariantneq}
380
381 \constfunc{bool}{operator $!=$}{\param{const wxVariant\& }{value}}
382
383 \constfunc{bool}{operator $!=$}{\param{const wxString\& }{value}}
384
385 \constfunc{bool}{operator $!=$}{\param{const char* }{value}}
386
387 \constfunc{bool}{operator $!=$}{\param{char }{value}}
388
389 \constfunc{bool}{operator $!=$}{\param{const long }{value}}
390
391 \constfunc{bool}{operator $!=$}{\param{const bool }{value}}
392
393 \constfunc{bool}{operator $!=$}{\param{const double }{value}}
394
395 \constfunc{bool}{operator $!=$}{\param{void* }{value}}
396
397 \constfunc{bool}{operator $!=$}{\param{wxObject* }{value}}
398
399 \constfunc{bool}{operator $!=$}{\param{const wxList\& }{value}}
400
401 \constfunc{bool}{operator $!=$}{\param{const wxArrayString\& }{value}}
402
403 \constfunc{bool}{operator $!=$}{\param{const wxDateTime\& }{value}}
404
405 Inequality test operators.
406
407 \membersection{wxVariant::operator $[]$}\label{wxvariantarray}
408
409 \constfunc{wxVariant}{operator $[]$}{\param{size\_t }{idx}}
410
411 Returns the value at {\it idx} (zero-based).
412
413 \func{wxVariant\&}{operator $[]$}{\param{size\_t }{idx}}
414
415 Returns a reference to the value at {\it idx} (zero-based). This can be used
416 to change the value at this index.
417
418 \membersection{wxVariant::operator char}\label{wxvariantchar}
419
420 \constfunc{char}{operator char}{\void}
421
422 Operator for implicit conversion to a char, using \helpref{wxVariant::GetChar}{wxvariantgetchar}.
423
424 \membersection{wxVariant::operator double}\label{wxvariantdouble}
425
426 \constfunc{double}{operator double}{\void}
427
428 Operator for implicit conversion to a double, using \helpref{wxVariant::GetDouble}{wxvariantgetdouble}.
429
430 \constfunc{long}{operator long}{\void}
431
432 Operator for implicit conversion to a long, using \helpref{wxVariant::GetLong}{wxvariantgetlong}.
433
434 \membersection{wxVariant::operator wxString}\label{wxvariantwxstring}
435
436 \constfunc{wxString}{operator wxString}{\void}
437
438 Operator for implicit conversion to a string, using \helpref{wxVariant::MakeString}{wxvariantmakestring}.
439
440 \membersection{wxVariant::operator void*}\label{wxvariantvoid}
441
442 \constfunc{void*}{operator void*}{\void}
443
444 Operator for implicit conversion to a pointer to a void, using \helpref{wxVariant::GetVoidPtr}{wxvariantgetvoidptr}.
445
446 \membersection{wxVariant::operator wxDateTime}\label{wxvariantdatetime}
447
448 \constfunc{void*}{operator wxDateTime}{\void}
449
450 Operator for implicit conversion to a pointer to a \helpref{wxDateTime}{wxdatetime}, using \helpref{wxVariant::GetDateTime}{wxvariantgetdatetime}.
451
452 \section{\class{wxVariantData}}\label{wxvariantdata}
453
454 The {\bf wxVariantData} is used to implement a new type for wxVariant. Derive from wxVariantData,
455 and override the pure virtual functions.
456
457 wxVariantData is reference counted, but you don't normally have to care about this, as
458 wxVariant manages the count automatically. However, incase your application needs to take
459 ownership of wxVariantData, be aware that the object is created with reference count of 1,
460 and passing it to wxVariant will not increase this. In other words, \helpref{IncRef}{wxvariantdataincref}
461 needs to be called only if you both take ownership of wxVariantData and pass it to a wxVariant.
462 Also note that the destructor is protected, so you can never explicitly delete a wxVariantData
463 instance. Instead, \helpref{DecRef}{wxvariantdatadecref} will delete the object automatically
464 when the reference count reaches zero.
465
466 \wxheading{Derived from}
467
468 \helpref{wxObject}{wxobject}
469
470 \wxheading{Include files}
471
472 <wx/variant.h>
473
474 \wxheading{See also}
475
476 \helpref{wxVariant}{wxvariant}
477
478 \latexignore{\rtfignore{\wxheading{Members}}}
479
480 \membersection{wxVariantData::wxVariantData}\label{wxvariantdatactor}
481
482 \func{}{wxVariantData}{\void}
483
484 Default constructor.
485
486 \membersection{wxVariantData::DecRef}\label{wxvariantdatadecref}
487
488 \func{void}{DecRef}{\void}
489
490 Decreases reference count. If the count reaches zero, the object is
491 automatically deleted.
492
493 Note that destructor of wxVariantData is protected, so delete
494 cannot be used as normal. Instead, DecRef should be called.
495
496 \membersection{wxVariantData::Eq}\label{wxvariantdataeq}
497
498 \constfunc{bool}{Eq}{\param{wxVariantData\&}{ data}}
499
500 Returns true if this object is equal to {\it data}.
501
502 \membersection{wxVariantData::GetType}\label{wxvariantdatagettype}
503
504 \constfunc{wxString}{GetType}{\void}
505
506 Returns the string type of the data.
507
508 \membersection{wxVariantData::GetValueClassInfo}\label{wxvariantdatagetvalueclassinfo}
509
510 \constfunc{wxClassInfo*}{GetValueClassInfo}{\void}
511
512 If the data is a wxObject returns a pointer to the objects wxClassInfo structure, if
513 the data isn't a wxObject the method returns NULL.
514
515 \membersection{wxVariantData::IncRef}\label{wxvariantdataincref}
516
517 \func{void}{IncRef}{\void}
518
519 Increases reference count. Note that initially wxVariantData has reference count of 1.
520
521 \membersection{wxVariantData::Read}\label{wxvariantdataread}
522
523 \func{bool}{Read}{\param{ostream\&}{ stream}}
524
525 \func{bool}{Read}{\param{wxString\&}{ string}}
526
527 Reads the data from {\it stream} or {\it string}.
528
529 \membersection{wxVariantData::Write}\label{wxvariantdatawrite}
530
531 \constfunc{bool}{Write}{\param{ostream\&}{ stream}}
532
533 \constfunc{bool}{Write}{\param{wxString\&}{ string}}
534
535 Writes the data to {\it stream} or {\it string}.
536
537
538 \membersection{wxGetVariantCast}\label{wxgetvariantcast}
539
540 \func{classname *}{wxGetVariantCast}{wxVariant\&, classname}
541
542 This macro returns the data stored in {\it variant} cast to the type {\it classname *} if
543 the data is of this type (the check is done during the run-time) or
544 {\tt NULL} otherwise.
545
546
547 \wxheading{See also}
548
549 \helpref{RTTI overview}{runtimeclassoverview}\\
550 \helpref{wxDynamicCast}{wxdynamiccast}