1 \section{\class{wxVariant
}}\label{wxvariant
}
3 The
{\bf wxVariant
} class represents a container for any type.
4 A variant's value can be changed at run time, possibly to a different type of value.
6 As standard, wxVariant can store values of type bool, char, double, long, string,
7 string list, time, date, void pointer, list of strings, and list of variants. However, an application can extend wxVariant's capabilities by deriving from the class
\helpref{wxVariantData
}{wxvariantdata
} and using the wxVariantData form of the wxVariant constructor or assignment operator to assign this data to a variant. Actual values for user-defined types will need to be accessed via the wxVariantData object, unlike the case for basic data types where convenience functions such as GetLong can be used.
9 This class is useful for reducing the programming for certain tasks, such as an editor
10 for different data types, or a remote procedure call protocol.
12 An optional name member is associated with a wxVariant. This might be used, for example, in CORBA
13 or OLE automation classes, where named parameters are required.
15 \wxheading{Derived from
}
17 \helpref{wxObject
}{wxobject
}
19 \wxheading{Include files
}
25 \helpref{wxVariantData
}{wxvariantdata
}
27 \latexignore{\rtfignore{\wxheading{Members
}}}
29 \membersection{wxVariant::wxVariant
}\label{wxvariantctor
}
31 \func{}{wxVariant
}{\void}
35 \func{}{wxVariant
}{\param{const wxVariant\&
}{variant
}}
39 \func{}{wxVariant
}{\param{const char*
}{ value
},
\param{const wxString\&
}{name = ``"
}}
41 \func{}{wxVariant
}{\param{const wxString\&
}{ value
},
\param{const wxString\&
}{name = ``"
}}
43 Construction from a string value.
45 \func{}{wxVariant
}{\param{char
}{ value
},
\param{const wxString\&
}{name = ``"
}}
47 Construction from a character value.
49 \func{}{wxVariant
}{\param{long
}{ value
},
\param{const wxString\&
}{name = ``"
}}
51 Construction from an integer value. You may need to cast to (long) to
52 avoid confusion with other constructors (such as the bool constructor).
54 \func{}{wxVariant
}{\param{bool
}{ value
},
\param{const wxString\&
}{name = ``"
}}
56 Construction from a boolean value.
58 \func{}{wxVariant
}{\param{double
}{ value
},
\param{const wxString\&
}{name = ``"
}}
60 Construction from a double-precision floating point value.
62 \func{}{wxVariant
}{\param{const wxList\&
}{ value
},
\param{const wxString\&
}{name = ``"
}}
64 Construction from a list of wxVariant objects. This constructor
65 copies
{\it value
}, the application is still responsible for
66 deleting
{\it value
} and its contents.
68 \func{}{wxVariant
}{\param{const wxStringList\&
}{ value
},
\param{const wxString\&
}{name = ``"
}}
70 Construction from a list of strings. This constructor
71 copies
{\it value
}, the application is still responsible for
72 deleting
{\it value
} and its contents.
74 \func{}{wxVariant
}{\param{void*
}{ value
},
\param{const wxString\&
}{name = ``"
}}
76 Construction from a void pointer.
78 \func{}{wxVariant
}{\param{wxObject*
}{ value
},
\param{const wxString\&
}{name = ``"
}}
80 Construction from a wxObject pointer.
82 \func{}{wxVariant
}{\param{wxVariantData*
}{ data
},
\param{const wxString\&
}{name = ``"
}}
84 Construction from user-defined data. The variant holds onto the
{\it data
} pointer.
86 \func{}{wxVariant
}{\param{wxDateTime\&
}{ val
},
\param{const wxString\&
}{name = ``"
}}
88 Construction from a
\helpref{wxDateTime
}{wxdatetime
}.
90 \func{}{wxVariant
}{\param{wxArrayString\&
}{ val
},
\param{const wxString\&
}{name = ``"
}}
92 Construction from an array of strings. This constructor copies
{\it value
} and its contents.
94 \func{}{wxVariant
}{\param{DATE
\_STRUCT*
}{ val
},
\param{const wxString\&
}{name = ``"
}}
96 Construction from a odbc date value. Represented internally by a
\helpref{wxDateTime
}{wxdatetime
} value.
98 \func{}{wxVariant
}{\param{TIME
\_STRUCT*
}{ val
},
\param{const wxString\&
}{name = ``"
}}
100 Construction from a odbc time value. Represented internally by a
\helpref{wxDateTime
}{wxdatetime
} value.
102 \func{}{wxVariant
}{\param{TIMESTAMP
\_STRUCT*
}{ val
},
\param{const wxString\&
}{name = ``"
}}
104 Construction from a odbc timestamp value. Represented internally by a
\helpref{wxDateTime
}{wxdatetime
} value.
106 \membersection{wxVariant::
\destruct{wxVariant
}}\label{wxvariantdtor
}
108 \func{}{\destruct{wxVariant
}}{\void}
113 \membersection{wxVariant::Append
}\label{wxvariantappend
}
115 \func{void
}{Append
}{\param{const wxVariant\&
}{ value
}}
117 Appends a value to the list.
119 \membersection{wxVariant::ClearList
}\label{wxvariantclearlist
}
121 \func{void
}{ClearList
}{\void}
123 Deletes the contents of the list.
126 \membersection{wxVariant::Convert
}\label{wxvariantconvert
}
128 \constfunc{bool
}{Convert
}{long* value
}
130 \constfunc{bool
}{Convert
}{bool* value
}
132 \constfunc{bool
}{Convert
}{double* value
}
134 \constfunc{bool
}{Convert
}{wxString* value
}
136 \constfunc{bool
}{Convert
}{char* value
}
138 \constfunc{bool
}{Convert
}{wxDateTime* value
}
140 Retrieves and converts the value of this variant to the type that
{\it value
} is.
143 \membersection{wxVariant::GetCount
}\label{wxvariantgetcount
}
145 \constfunc{int
}{GetCount
}{\void}
147 Returns the number of elements in the list.
149 \membersection{wxVariant::Delete
}\label{wxvariantdelete
}
151 \func{bool
}{Delete
}{\param{int
}{item
}}
153 Deletes the zero-based
{\it item
} from the list.
155 \membersection{wxVariant::GetArrayString
}\label{wxvariantgetarraystring
}
157 \constfunc{wxArrayString
}{GetArrayString
}{\void}
159 Returns the string array value.
161 \membersection{wxVariant::GetBool
}\label{wxvariantgetbool
}
163 \constfunc{bool
}{GetBool
}{\void}
165 Returns the boolean value.
167 \membersection{wxVariant::GetChar
}\label{wxvariantgetchar
}
169 \constfunc{char
}{GetChar
}{\void}
171 Returns the character value.
173 \membersection{wxVariant::GetData
}\label{wxvariantgetdata
}
175 \constfunc{wxVariantData*
}{GetData
}{\void}
177 Returns a pointer to the internal variant data.
179 \membersection{wxVariant::GetDateTime
}\label{wxvariantgetdatetime
}
181 \constfunc{wxDateTime
}{GetDateTime
}{\void}
183 Returns the date value.
185 \membersection{wxVariant::GetDouble
}\label{wxvariantgetdouble
}
187 \constfunc{double
}{GetDouble
}{\void}
189 Returns the floating point value.
191 \membersection{wxVariant::GetLong
}\label{wxvariantgetlong
}
193 \constfunc{long
}{GetLong
}{\void}
195 Returns the integer value.
197 \membersection{wxVariant::GetName
}\label{wxvariantgetname
}
199 \constfunc{const wxString\&
}{GetName
}{\void}
201 Returns a constant reference to the variant name.
203 \membersection{wxVariant::GetString
}\label{wxvariantgetstring
}
205 \constfunc{wxString
}{GetString
}{\void}
207 Gets the string value.
209 \membersection{wxVariant::GetType
}\label{wxvariantgettype
}
211 \constfunc{wxString
}{GetType
}{\void}
213 Returns the value type as a string. The built-in types are: bool, char, date, double, list, long, string, stringlist, time, void*.
215 If the variant is null, the value type returned is the string ``null" (not the empty string).
217 \membersection{wxVariant::GetVoidPtr
}\label{wxvariantgetvoidptr
}
219 \constfunc{void*
}{GetVoidPtr
}{\void}
221 Gets the void pointer value.
223 \membersection{wxVariant::GetWxObjectPtr
}\label{wxvariantgetwxobjectptr
}
225 \constfunc{void*
}{GetWxObjectPtr
}{\void}
227 Gets the wxObject pointer value.
229 \membersection{wxVariant::Insert
}\label{wxvariantinsert
}
231 \func{void
}{Insert
}{\param{const wxVariant\&
}{ value
}}
233 Inserts a value at the front of the list.
235 \membersection{wxVariant::IsNull
}\label{wxvariantisnull
}
237 \constfunc{bool
}{IsNull
}{\void}
239 Returns true if there is no data associated with this variant, false if there is data.
241 \membersection{wxVariant::IsType
}\label{wxvariantistype
}
243 \constfunc{bool
}{IsType
}{\param{const wxString\&
}{ type
}}
245 Returns true if
{\it type
} matches the type of the variant, false otherwise.
247 \membersection{wxVariant::IsValueKindOf
}\label{wxvariantisvaluekindof
}
249 \constfunc{bool
}{IsValueKindOf
}{\param{const wxClassInfo* type
}{ type
}}
251 Returns true if the data is derived from the class described by
{\it type
}, false otherwise.
253 \membersection{wxVariant::MakeNull
}\label{wxvariantmakenull
}
255 \func{void
}{MakeNull
}{\void}
257 Makes the variant null by deleting the internal data.
259 \membersection{wxVariant::MakeString
}\label{wxvariantmakestring
}
261 \constfunc{wxString
}{MakeString
}{\void}
263 Makes a string representation of the variant value (for any type).
265 \membersection{wxVariant::Member
}\label{wxvariantmember
}
267 \constfunc{bool
}{Member
}{\param{const wxVariant\&
}{ value
}}
269 Returns true if
{\it value
} matches an element in the list.
271 \membersection{wxVariant::NullList
}\label{wxvariantnulllist
}
273 \func{void
}{NullList
}{\void}
275 Makes an empty list. This differs from a null variant which has no data; a null list
276 is of type list, but the number of elements in the list is zero.
278 \membersection{wxVariant::SetData
}\label{wxvariantsetdata
}
280 \func{void
}{SetData
}{\param{wxVariantData*
}{ data
}}
282 Sets the internal variant data, deleting the existing data if there is any.
284 \membersection{wxVariant::operator $=$
}\label{wxvariantassignment
}
286 \func{void
}{operator $=$
}{\param{const wxVariant\&
}{value
}}
288 \func{void
}{operator $=$
}{\param{wxVariantData*
}{value
}}
290 \func{void
}{operator $=$
}{\param{const wxString\&
}{value
}}
292 \func{void
}{operator $=$
}{\param{const char*
}{value
}}
294 \func{void
}{operator $=$
}{\param{char
}{value
}}
296 \func{void
}{operator $=$
}{\param{const long
}{value
}}
298 \func{void
}{operator $=$
}{\param{const bool
}{value
}}
300 \func{void
}{operator $=$
}{\param{const double
}{value
}}
302 \func{void
}{operator $=$
}{\param{void*
}{value
}}
304 \func{void
}{operator $=$
}{\param{const wxList\&
}{value
}}
306 \func{void
}{operator $=$
}{\param{const wxStringList\&
}{value
}}
308 \func{void
}{operator $=$
}{\param{const wxDateTime\&
}{value
}}
310 \func{void
}{operator $=$
}{\param{const wxArrayString\&
}{value
}}
312 \func{void
}{operator $=$
}{\param{const DATE
\_STRUCT*
}{value
}}
314 \func{void
}{operator $=$
}{\param{const TIME
\_STRUCT*
}{value
}}
316 \func{void
}{operator $=$
}{\param{const TIMESTAMP
\_STRUCT*
}{value
}}
318 Assignment operators.
320 \membersection{wxVariant::operator $==$
}\label{wxvarianteq
}
322 \constfunc{bool
}{operator $==$
}{\param{const wxVariant\&
}{value
}}
324 \constfunc{bool
}{operator $==$
}{\param{const wxString\&
}{value
}}
326 \constfunc{bool
}{operator $==$
}{\param{const char*
}{value
}}
328 \constfunc{bool
}{operator $==$
}{\param{char
}{value
}}
330 \constfunc{bool
}{operator $==$
}{\param{const long
}{value
}}
332 \constfunc{bool
}{operator $==$
}{\param{const bool
}{value
}}
334 \constfunc{bool
}{operator $==$
}{\param{const double
}{value
}}
336 \constfunc{bool
}{operator $==$
}{\param{void*
}{value
}}
338 \constfunc{bool
}{operator $==$
}{\param{const wxList\&
}{value
}}
340 \constfunc{bool
}{operator $==$
}{\param{const wxStringList\&
}{value
}}
342 \constfunc{bool
}{operator $==$
}{\param{const wxArrayString\&
}{value
}}
344 \constfunc{bool
}{operator $==$
}{\param{const wxDateTime\&
}{value
}}
346 Equality test operators.
348 \membersection{wxVariant::operator $!=$
}\label{wxvariantneq
}
350 \constfunc{bool
}{operator $!=$
}{\param{const wxVariant\&
}{value
}}
352 \constfunc{bool
}{operator $!=$
}{\param{const wxString\&
}{value
}}
354 \constfunc{bool
}{operator $!=$
}{\param{const char*
}{value
}}
356 \constfunc{bool
}{operator $!=$
}{\param{char
}{value
}}
358 \constfunc{bool
}{operator $!=$
}{\param{const long
}{value
}}
360 \constfunc{bool
}{operator $!=$
}{\param{const bool
}{value
}}
362 \constfunc{bool
}{operator $!=$
}{\param{const double
}{value
}}
364 \constfunc{bool
}{operator $!=$
}{\param{void*
}{value
}}
366 \constfunc{bool
}{operator $!=$
}{\param{const wxList\&
}{value
}}
368 \constfunc{bool
}{operator $!=$
}{\param{const wxStringList\&
}{value
}}
370 \constfunc{bool
}{operator $!=$
}{\param{const wxArrayString\&
}{value
}}
372 \constfunc{bool
}{operator $!=$
}{\param{const wxDateTime\&
}{value
}}
374 Inequality test operators.
376 \membersection{wxVariant::operator $
[]$
}\label{wxvariantarray
}
378 \constfunc{wxVariant
}{operator $
[]$
}{\param{size
\_t }{idx
}}
380 Returns the value at
{\it idx
} (zero-based).
382 \func{wxVariant\&
}{operator $
[]$
}{\param{size
\_t }{idx
}}
384 Returns a reference to the value at
{\it idx
} (zero-based). This can be used
385 to change the value at this index.
387 \membersection{wxVariant::operator char
}\label{wxvariantchar
}
389 \constfunc{char
}{operator char
}{\void}
391 Operator for implicit conversion to a char, using
\helpref{wxVariant::GetChar
}{wxvariantgetchar
}.
393 \membersection{wxVariant::operator double
}\label{wxvariantdouble
}
395 \constfunc{double
}{operator double
}{\void}
397 Operator for implicit conversion to a double, using
\helpref{wxVariant::GetDouble
}{wxvariantgetdouble
}.
399 \constfunc{long
}{operator long
}{\void}
401 Operator for implicit conversion to a long, using
\helpref{wxVariant::GetLong
}{wxvariantgetlong
}.
403 \membersection{wxVariant::operator wxString
}\label{wxvariantwxstring
}
405 \constfunc{wxString
}{operator wxString
}{\void}
407 Operator for implicit conversion to a string, using
\helpref{wxVariant::MakeString
}{wxvariantmakestring
}.
409 \membersection{wxVariant::operator void*
}\label{wxvariantvoid
}
411 \constfunc{void*
}{operator void*
}{\void}
413 Operator for implicit conversion to a pointer to a void, using
\helpref{wxVariant::GetVoidPtr
}{wxvariantgetvoidptr
}.
415 \membersection{wxVariant::operator wxDateTime
}\label{wxvariantdatetime
}
417 \constfunc{void*
}{operator wxDateTime
}{\void}
419 Operator for implicit conversion to a pointer to a
\helpref{wxDateTime
}{wxdatetime
}, using
\helpref{wxVariant::GetDateTime
}{wxvariantgetdatetime
}.
421 \section{\class{wxVariantData
}}\label{wxvariantdata
}
423 The
{\bf wxVariantData
} is used to implement a new type for wxVariant. Derive from wxVariantData,
424 and override the pure virtual functions.
426 \wxheading{Derived from
}
428 \helpref{wxObject
}{wxobject
}
430 \wxheading{Include files
}
436 \helpref{wxVariant
}{wxvariant
}
438 \latexignore{\rtfignore{\wxheading{Members
}}}
440 \membersection{wxVariantData::wxVariantData
}\label{wxvariantdatactor
}
442 \func{}{wxVariantData
}{\void}
446 \membersection{wxVariantData::Copy
}\label{wxvariantdatacopy
}
448 \func{void
}{Copy
}{\param{wxVariantData\&
}{ data
}}
450 Copy the data from `this' object to
{\it data
}.
452 \membersection{wxVariantData::Eq
}\label{wxvariantdataeq
}
454 \constfunc{bool
}{Eq
}{\param{wxVariantData\&
}{ data
}}
456 Returns true if this object is equal to
{\it data
}.
458 \membersection{wxVariantData::GetType
}\label{wxvariantdatagettype
}
460 \constfunc{wxString
}{GetType
}{\void}
462 Returns the string type of the data.
464 \membersection{wxVariantData::GetValueClassInfo
}\label{wxvariantdatagetvalueclassinfo
}
466 \constfunc{wxClassInfo*
}{GetValueClassInfo
}{\void}
468 If the data is a wxObject returns a pointer to the objects wxClassInfo structure, if
469 the data isn't a wxObject the method returns NULL.
471 \membersection{wxVariantData::Read
}\label{wxvariantdataread
}
473 \func{bool
}{Read
}{\param{ostream\&
}{ stream
}}
475 \func{bool
}{Read
}{\param{wxString\&
}{ string
}}
477 Reads the data from
{\it stream
} or
{\it string
}.
479 \membersection{wxVariantData::Write
}\label{wxvariantdatawrite
}
481 \constfunc{bool
}{Write
}{\param{ostream\&
}{ stream
}}
483 \constfunc{bool
}{Write
}{\param{wxString\&
}{ string
}}
485 Writes the data to
{\it stream
} or
{\it string
}.
488 \membersection{wxGetVariantCast
}\label{wxgetvariantcast
}
490 \func{classname *
}{wxGetVariantCast
}{wxVariant\&, classname
}
492 This macro returns the data stored in
{\it variant
} cast to the type
{\it classname *
} if
493 the data is of this type (the check is done during the run-time) or
494 {\tt NULL
} otherwise.
499 \helpref{RTTI overview
}{runtimeclassoverview
}\\
500 \helpref{wxDynamicCast
}{wxdynamiccast
}