]> git.saurik.com Git - wxWidgets.git/blame - docs/latex/wx/variant.tex
fixed typo
[wxWidgets.git] / docs / latex / wx / variant.tex
CommitLineData
a974387a
JS
1\section{\class{wxVariant}}\label{wxvariant}
2
3The {\bf wxVariant} class represents a container for any type.
4A variant's value can be changed at run time, possibly to a different type of value.
5
6As standard, wxVariant can store values of type bool, char, double, long, string,
7string list, time, date, void pointer, list of strings, and list of variants. However, an application can extend
8wxVariant's capabilities by deriving from the class \helpref{wxVariantData}{wxvariantdata} and
9using the wxVariantData form of the wxVariant constructor or assignment operator
10to assign this data to a variant. Actual values for user-defined types will need to be accessed
11via the wxVariantData object, unlike the case for basic data types where convenience
12functions such as GetLong can be used.
13
14This class is useful for reducing the programming for certain tasks, such as an editor
15for different data types, or a remote procedure call protocol.
16
17An optional name member is associated with a wxVariant. This might be used, for example, in CORBA
18or OLE automation classes, where named parameters are required.
19
20wxVariant is similar to wxExpr and also to wxPropertyValue. However, wxExpr is efficiency-optimized for
21a restricted range of data types, whereas wxVariant is less efficient but more extensible.
22wxPropertyValue may be replaced by wxVariant eventually.
23
24\wxheading{Derived from}
25
26\helpref{wxObject}{wxobject}
27
954b8ae6
JS
28\wxheading{Include files}
29
30<wx/variant.h>
31
a974387a
JS
32\wxheading{See also}
33
34\helpref{wxVariantData}{wxvariantdata}
35
36\latexignore{\rtfignore{\wxheading{Members}}}
37
38\membersection{wxVariant::wxVariant}\label{wxvariantctor}
39
40\func{}{wxVariant}{\void}
41
42Default constructor.
43
44\func{}{wxVariant}{\param{const wxVariant\& }{variant}}
45
46Copy constructor.
47
f6bcfd97
BP
48\func{}{wxVariant}{\param{const char*}{ value}, \param{const wxString\& }{name = ``"}}
49
a974387a
JS
50\func{}{wxVariant}{\param{const wxString\&}{ value}, \param{const wxString\& }{name = ``"}}
51
52Construction from a string value.
53
54\func{}{wxVariant}{\param{char}{ value}, \param{const wxString\& }{name = ``"}}
55
56Construction from a character value.
57
58\func{}{wxVariant}{\param{long}{ value}, \param{const wxString\& }{name = ``"}}
59
60Construction from an integer value. You may need to cast to (long) to
61avoid confusion with other constructors (such as the bool constructor).
62
63\func{}{wxVariant}{\param{bool}{ value}, \param{const wxString\& }{name = ``"}}
64
65Construction from a boolean value.
66
67\func{}{wxVariant}{\param{double}{ value}, \param{const wxString\& }{name = ``"}}
68
69Construction from a double-precision floating point value.
70
71\func{}{wxVariant}{\param{const wxList\&}{ value}, \param{const wxString\& }{name = ``"}}
72
73Construction from a list of wxVariant objects. This constructor
74copies {\it value}, the application is still responsible for
75deleting {\it value} and its contents.
76
77\func{}{wxVariant}{\param{const wxStringList\&}{ value}, \param{const wxString\& }{name = ``"}}
78
79Construction from a list of strings. This constructor
80copies {\it value}, the application is still responsible for
81deleting {\it value} and its contents.
82
83%Note: this constructor is currently disabled because it causes a C++ ambiguity.
84
a974387a
JS
85\func{}{wxVariant}{\param{void*}{ value}, \param{const wxString\& }{name = ``"}}
86
87Construction from a void pointer.
88
89\func{}{wxVariant}{\param{wxVariantData*}{ data}, \param{const wxString\& }{name = ``"}}
90
91Construction from user-defined data. The variant holds on to the {\it data} pointer.
92
93\membersection{wxVariant::\destruct{wxVariant}}\label{wxvariantdtor}
94
95\func{}{\destruct{wxVariant}}{\void}
96
97Destructor.
98
99\membersection{wxVariant::Append}\label{wxvariantappend}
100
101\func{void}{Append}{\param{const wxVariant\&}{ value}}
102
103Appends a value to the list.
104
105\membersection{wxVariant::ClearList}\label{wxvariantclearlist}
106
107\func{void}{ClearList}{\void}
108
109Deletes the contents of the list.
110
111\membersection{wxVariant::GetCount}\label{wxvariantgetcount}
112
113\constfunc{int}{GetCount}{\void}
114
115Returns the number of elements in the list.
116
117\membersection{wxVariant::Delete}\label{wxvariantdelete}
118
119\func{bool}{Delete}{\param{int }{item}}
120
121Deletes the zero-based {\it item} from the list.
122
123\membersection{wxVariant::GetBool}\label{wxvariantgetbool}
124
125\constfunc{bool}{GetBool}{\void}
126
127Returns the boolean value.
128
129\membersection{wxVariant::GetChar}\label{wxvariantgetchar}
130
131\constfunc{char}{GetChar}{\void}
132
133Returns the character value.
134
135\membersection{wxVariant::GetData}\label{wxvariantgetdata}
136
137\constfunc{wxVariantData*}{GetData}{\void}
138
139Returns a pointer to the internal variant data.
140
a974387a
JS
141\membersection{wxVariant::GetDouble}\label{wxvariantgetdouble}
142
143\constfunc{double}{GetDouble}{\void}
144
145Returns the floating point value.
146
147\membersection{wxVariant::GetLong}\label{wxvariantgetlong}
148
149\constfunc{long}{GetLong}{\void}
150
151Returns the integer value.
152
153\membersection{wxVariant::GetName}\label{wxvariantgetname}
154
155\constfunc{const wxString\&}{GetName}{\void}
156
157Returns a constant reference to the variant name.
158
159\membersection{wxVariant::GetString}\label{wxvariantgetstring}
160
161\constfunc{wxString}{GetString}{\void}
162
163Gets the string value.
164
a974387a
JS
165\membersection{wxVariant::GetType}\label{wxvariantgettype}
166
167\constfunc{wxString}{GetType}{\void}
168
169Returns the value type as a string. The built-in types are: bool, char, date, double, list, long, string, stringlist, time, void*.
170
171If the variant is null, the value type returned is the string ``null" (not the empty string).
172
173\membersection{wxVariant::GetVoidPtr}\label{wxvariantgetvoidptr}
174
175\constfunc{void*}{GetVoidPtr}{\void}
176
177Gets the void pointer value.
178
179\membersection{wxVariant::Insert}\label{wxvariantinsert}
180
181\func{void}{Insert}{\param{const wxVariant\&}{ value}}
182
183Inserts a value at the front of the list.
184
185\membersection{wxVariant::IsNull}\label{wxvariantisnull}
186
187\constfunc{bool}{IsNull}{\void}
188
cc81d32f 189Returns true if there is no data associated with this variant, false if there is data.
a974387a
JS
190
191\membersection{wxVariant::IsType}\label{wxvariantistype}
192
193\constfunc{bool}{IsType}{\param{const wxString\&}{ type}}
194
cc81d32f 195Returns true if {\it type} matches the type of the variant, false otherwise.
a974387a
JS
196
197\membersection{wxVariant::MakeNull}\label{wxvariantmakenull}
198
199\func{void}{MakeNull}{\void}
200
201Makes the variant null by deleting the internal data.
202
203\membersection{wxVariant::MakeString}\label{wxvariantmakestring}
204
205\constfunc{wxString}{MakeString}{\void}
206
207Makes a string representation of the variant value (for any type).
208
209\membersection{wxVariant::Member}\label{wxvariantmember}
210
211\constfunc{bool}{Member}{\param{const wxVariant\&}{ value}}
212
cc81d32f 213Returns true if {\it value} matches an element in the list.
a974387a
JS
214
215\membersection{wxVariant::NullList}\label{wxvariantnulllist}
216
217\func{void}{NullList}{\void}
218
219Makes an empty list. This differs from a null variant which has no data; a null list
220is of type list, but the number of elements in the list is zero.
221
222\membersection{wxVariant::SetData}\label{wxvariantsetdata}
223
224\func{void}{SetData}{\param{wxVariantData*}{ data}}
225
226Sets the internal variant data, deleting the existing data if there is any.
227
228\membersection{wxVariant::operator $=$}\label{wxvariantassignment}
229
230\func{void}{operator $=$}{\param{const wxVariant\& }{value}}
231
232\func{void}{operator $=$}{\param{wxVariantData* }{value}}
233
234\func{void}{operator $=$}{\param{const wxString\& }{value}}
235
236\func{void}{operator $=$}{\param{const char* }{value}}
237
238\func{void}{operator $=$}{\param{char }{value}}
239
240\func{void}{operator $=$}{\param{const long }{value}}
241
242\func{void}{operator $=$}{\param{const bool }{value}}
243
244\func{void}{operator $=$}{\param{const double }{value}}
245
a974387a
JS
246\func{void}{operator $=$}{\param{void* }{value}}
247
248\func{void}{operator $=$}{\param{const wxList\& }{value}}
249
250\func{void}{operator $=$}{\param{const wxStringList\& }{value}}
251
252Assignment operators.
253
254\membersection{wxVariant::operator $==$}\label{wxvarianteq}
255
256\func{bool}{operator $==$}{\param{const wxVariant\& }{value}}
257
258\func{bool}{operator $==$}{\param{const wxString\& }{value}}
259
260\func{bool}{operator $==$}{\param{const char* }{value}}
261
262\func{bool}{operator $==$}{\param{char }{value}}
263
264\func{bool}{operator $==$}{\param{const long }{value}}
265
266\func{bool}{operator $==$}{\param{const bool }{value}}
267
268\func{bool}{operator $==$}{\param{const double }{value}}
269
a974387a
JS
270\func{bool}{operator $==$}{\param{void* }{value}}
271
272\func{bool}{operator $==$}{\param{const wxList\& }{value}}
273
274\func{bool}{operator $==$}{\param{const wxStringList\& }{value}}
275
276Equality test operators.
277
278\membersection{wxVariant::operator $!=$}\label{wxvariantneq}
279
280\func{bool}{operator $!=$}{\param{const wxVariant\& }{value}}
281
282\func{bool}{operator $!=$}{\param{const wxString\& }{value}}
283
284\func{bool}{operator $!=$}{\param{const char* }{value}}
285
286\func{bool}{operator $!=$}{\param{char }{value}}
287
288\func{bool}{operator $!=$}{\param{const long }{value}}
289
290\func{bool}{operator $!=$}{\param{const bool }{value}}
291
292\func{bool}{operator $!=$}{\param{const double }{value}}
293
a974387a
JS
294\func{bool}{operator $!=$}{\param{void* }{value}}
295
296\func{bool}{operator $!=$}{\param{const wxList\& }{value}}
297
298\func{bool}{operator $!=$}{\param{const wxStringList\& }{value}}
299
300Inequality test operators.
301
302\membersection{wxVariant::operator $[]$}\label{wxvariantarray}
303
304\constfunc{wxVariant}{operator $[]$}{\param{size\_t }{idx}}
305
306Returns the value at {\it idx} (zero-based).
307
308\func{wxVariant\&}{operator $[]$}{\param{size\_t }{idx}}
309
310Returns a reference to the value at {\it idx} (zero-based). This can be used
311to change the value at this index.
312
313\membersection{wxVariant::operator char}\label{wxvariantchar}
314
315\constfunc{char}{operator char}{\void}
316
317Operator for implicit conversion to a char, using \helpref{wxVariant::GetChar}{wxvariantgetchar}.
318
319\membersection{wxVariant::operator double}\label{wxvariantdouble}
320
321\constfunc{double}{operator double}{\void}
322
323Operator for implicit conversion to a double, using \helpref{wxVariant::GetDouble}{wxvariantgetdouble}.
324
325\constfunc{long}{operator long}{\void}
326
327Operator for implicit conversion to a long, using \helpref{wxVariant::GetLong}{wxvariantgetlong}.
328
a974387a
JS
329\membersection{wxVariant::operator wxString}\label{wxvariantwxstring}
330
331\constfunc{wxString}{operator wxString}{\void}
332
333Operator for implicit conversion to a string, using \helpref{wxVariant::MakeString}{wxvariantmakestring}.
334
a974387a
JS
335\membersection{wxVariant::operator void*}\label{wxvariantvoid}
336
337\constfunc{void*}{operator void*}{\void}
338
339Operator for implicit conversion to a pointer to a void, using \helpref{wxVariant::GetVoidPtr}{wxvariantgetvoidptr}.
340
341\section{\class{wxVariantData}}\label{wxvariantdata}
342
343The {\bf wxVariantData} is used to implement a new type for wxVariant. Derive from wxVariantData,
344and override the pure virtual functions.
345
346\wxheading{Derived from}
347
348\helpref{wxObject}{wxobject}
349
954b8ae6
JS
350\wxheading{Include files}
351
352<wx/variant.h>
353
a974387a
JS
354\wxheading{See also}
355
356\helpref{wxVariant}{wxvariant}
357
358\latexignore{\rtfignore{\wxheading{Members}}}
359
360\membersection{wxVariantData::wxVariantData}\label{wxvariantdatactor}
361
362\func{}{wxVariantData}{\void}
363
364Default constructor.
365
366\membersection{wxVariantData::Copy}\label{wxvariantdatacopy}
367
368\func{void}{Copy}{\param{wxVariantData\&}{ data}}
369
370Copy the data from `this' object to {\it data}.
371
372\membersection{wxVariantData::Eq}\label{wxvariantdataeq}
373
374\constfunc{bool}{Eq}{\param{wxVariantData\&}{ data}}
375
cc81d32f 376Returns true if this object is equal to {\it data}.
a974387a
JS
377
378\membersection{wxVariantData::GetType}\label{wxvariantdatagettype}
379
380\constfunc{wxString}{GetType}{\void}
381
382Returns the string type of the data.
383
384\membersection{wxVariantData::Read}\label{wxvariantdataread}
385
386\func{bool}{Read}{\param{ostream\&}{ stream}}
387
388\func{bool}{Read}{\param{wxString\&}{ string}}
389
390Reads the data from {\it stream} or {\it string}.
391
392\membersection{wxVariantData::Write}\label{wxvariantdatawrite}
393
394\constfunc{bool}{Write}{\param{ostream\&}{ stream}}
395
396\constfunc{bool}{Write}{\param{wxString\&}{ string}}
397
398Writes the data to {\it stream} or {\it string}.
399
400
401