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{void*
}{ value
},
\param{const wxString\&
}{name = ``"
}}
70 Construction from a void pointer.
72 \func{}{wxVariant
}{\param{wxObject*
}{ value
},
\param{const wxString\&
}{name = ``"
}}
74 Construction from a wxObject pointer.
76 \func{}{wxVariant
}{\param{wxVariantData*
}{ data
},
\param{const wxString\&
}{name = ``"
}}
78 Construction from user-defined data. The variant holds onto the
{\it data
} pointer.
80 \func{}{wxVariant
}{\param{wxDateTime\&
}{ val
},
\param{const wxString\&
}{name = ``"
}}
82 Construction from a
\helpref{wxDateTime
}{wxdatetime
}.
84 \func{}{wxVariant
}{\param{wxArrayString\&
}{ val
},
\param{const wxString\&
}{name = ``"
}}
86 Construction from an array of strings. This constructor copies
{\it value
} and its contents.
88 \func{}{wxVariant
}{\param{DATE
\_STRUCT*
}{ val
},
\param{const wxString\&
}{name = ``"
}}
90 Construction from a odbc date value. Represented internally by a
\helpref{wxDateTime
}{wxdatetime
} value.
92 \func{}{wxVariant
}{\param{TIME
\_STRUCT*
}{ val
},
\param{const wxString\&
}{name = ``"
}}
94 Construction from a odbc time value. Represented internally by a
\helpref{wxDateTime
}{wxdatetime
} value.
96 \func{}{wxVariant
}{\param{TIMESTAMP
\_STRUCT*
}{ val
},
\param{const wxString\&
}{name = ``"
}}
98 Construction from a odbc timestamp value. Represented internally by a
\helpref{wxDateTime
}{wxdatetime
} value.
100 \membersection{wxVariant::
\destruct{wxVariant
}}\label{wxvariantdtor
}
102 \func{}{\destruct{wxVariant
}}{\void}
107 \membersection{wxVariant::Append
}\label{wxvariantappend
}
109 \func{void
}{Append
}{\param{const wxVariant\&
}{ value
}}
111 Appends a value to the list.
113 \membersection{wxVariant::ClearList
}\label{wxvariantclearlist
}
115 \func{void
}{ClearList
}{\void}
117 Deletes the contents of the list.
120 \membersection{wxVariant::Convert
}\label{wxvariantconvert
}
122 \constfunc{bool
}{Convert
}{long* value
}
124 \constfunc{bool
}{Convert
}{bool* value
}
126 \constfunc{bool
}{Convert
}{double* value
}
128 \constfunc{bool
}{Convert
}{wxString* value
}
130 \constfunc{bool
}{Convert
}{char* value
}
132 \constfunc{bool
}{Convert
}{wxDateTime* value
}
134 Retrieves and converts the value of this variant to the type that
{\it value
} is.
137 \membersection{wxVariant::GetCount
}\label{wxvariantgetcount
}
139 \constfunc{int
}{GetCount
}{\void}
141 Returns the number of elements in the list.
143 \membersection{wxVariant::Delete
}\label{wxvariantdelete
}
145 \func{bool
}{Delete
}{\param{int
}{item
}}
147 Deletes the zero-based
{\it item
} from the list.
149 \membersection{wxVariant::GetArrayString
}\label{wxvariantgetarraystring
}
151 \constfunc{wxArrayString
}{GetArrayString
}{\void}
153 Returns the string array value.
155 \membersection{wxVariant::GetBool
}\label{wxvariantgetbool
}
157 \constfunc{bool
}{GetBool
}{\void}
159 Returns the boolean value.
161 \membersection{wxVariant::GetChar
}\label{wxvariantgetchar
}
163 \constfunc{char
}{GetChar
}{\void}
165 Returns the character value.
167 \membersection{wxVariant::GetData
}\label{wxvariantgetdata
}
169 \constfunc{wxVariantData*
}{GetData
}{\void}
171 Returns a pointer to the internal variant data.
173 \membersection{wxVariant::GetDateTime
}\label{wxvariantgetdatetime
}
175 \constfunc{wxDateTime
}{GetDateTime
}{\void}
177 Returns the date value.
179 \membersection{wxVariant::GetDouble
}\label{wxvariantgetdouble
}
181 \constfunc{double
}{GetDouble
}{\void}
183 Returns the floating point value.
185 \membersection{wxVariant::GetLong
}\label{wxvariantgetlong
}
187 \constfunc{long
}{GetLong
}{\void}
189 Returns the integer value.
191 \membersection{wxVariant::GetName
}\label{wxvariantgetname
}
193 \constfunc{const wxString\&
}{GetName
}{\void}
195 Returns a constant reference to the variant name.
197 \membersection{wxVariant::GetString
}\label{wxvariantgetstring
}
199 \constfunc{wxString
}{GetString
}{\void}
201 Gets the string value.
203 \membersection{wxVariant::GetType
}\label{wxvariantgettype
}
205 \constfunc{wxString
}{GetType
}{\void}
207 Returns the value type as a string. The built-in types are: bool, char, date, double, list, long, string, stringlist, time, void*.
209 If the variant is null, the value type returned is the string ``null" (not the empty string).
211 \membersection{wxVariant::GetVoidPtr
}\label{wxvariantgetvoidptr
}
213 \constfunc{void*
}{GetVoidPtr
}{\void}
215 Gets the void pointer value.
217 \membersection{wxVariant::GetWxObjectPtr
}\label{wxvariantgetwxobjectptr
}
219 \constfunc{void*
}{GetWxObjectPtr
}{\void}
221 Gets the wxObject pointer value.
223 \membersection{wxVariant::Insert
}\label{wxvariantinsert
}
225 \func{void
}{Insert
}{\param{const wxVariant\&
}{ value
}}
227 Inserts a value at the front of the list.
229 \membersection{wxVariant::IsNull
}\label{wxvariantisnull
}
231 \constfunc{bool
}{IsNull
}{\void}
233 Returns true if there is no data associated with this variant, false if there is data.
235 \membersection{wxVariant::IsType
}\label{wxvariantistype
}
237 \constfunc{bool
}{IsType
}{\param{const wxString\&
}{ type
}}
239 Returns true if
{\it type
} matches the type of the variant, false otherwise.
241 \membersection{wxVariant::IsValueKindOf
}\label{wxvariantisvaluekindof
}
243 \constfunc{bool
}{IsValueKindOf
}{\param{const wxClassInfo* type
}{ type
}}
245 Returns true if the data is derived from the class described by
{\it type
}, false otherwise.
247 \membersection{wxVariant::MakeNull
}\label{wxvariantmakenull
}
249 \func{void
}{MakeNull
}{\void}
251 Makes the variant null by deleting the internal data.
253 \membersection{wxVariant::MakeString
}\label{wxvariantmakestring
}
255 \constfunc{wxString
}{MakeString
}{\void}
257 Makes a string representation of the variant value (for any type).
259 \membersection{wxVariant::Member
}\label{wxvariantmember
}
261 \constfunc{bool
}{Member
}{\param{const wxVariant\&
}{ value
}}
263 Returns true if
{\it value
} matches an element in the list.
265 \membersection{wxVariant::NullList
}\label{wxvariantnulllist
}
267 \func{void
}{NullList
}{\void}
269 Makes an empty list. This differs from a null variant which has no data; a null list
270 is of type list, but the number of elements in the list is zero.
272 \membersection{wxVariant::SetData
}\label{wxvariantsetdata
}
274 \func{void
}{SetData
}{\param{wxVariantData*
}{ data
}}
276 Sets the internal variant data, deleting the existing data if there is any.
278 \membersection{wxVariant::operator $=$
}\label{wxvariantassignment
}
280 \func{void
}{operator $=$
}{\param{const wxVariant\&
}{value
}}
282 \func{void
}{operator $=$
}{\param{wxVariantData*
}{value
}}
284 \func{void
}{operator $=$
}{\param{const wxString\&
}{value
}}
286 \func{void
}{operator $=$
}{\param{const char*
}{value
}}
288 \func{void
}{operator $=$
}{\param{char
}{value
}}
290 \func{void
}{operator $=$
}{\param{const long
}{value
}}
292 \func{void
}{operator $=$
}{\param{const bool
}{value
}}
294 \func{void
}{operator $=$
}{\param{const double
}{value
}}
296 \func{void
}{operator $=$
}{\param{void*
}{value
}}
298 \func{void
}{operator $=$
}{\param{const wxList\&
}{value
}}
300 \func{void
}{operator $=$
}{\param{const wxDateTime\&
}{value
}}
302 \func{void
}{operator $=$
}{\param{const wxArrayString\&
}{value
}}
304 \func{void
}{operator $=$
}{\param{const DATE
\_STRUCT*
}{value
}}
306 \func{void
}{operator $=$
}{\param{const TIME
\_STRUCT*
}{value
}}
308 \func{void
}{operator $=$
}{\param{const TIMESTAMP
\_STRUCT*
}{value
}}
310 Assignment operators.
312 \membersection{wxVariant::operator $==$
}\label{wxvarianteq
}
314 \constfunc{bool
}{operator $==$
}{\param{const wxVariant\&
}{value
}}
316 \constfunc{bool
}{operator $==$
}{\param{const wxString\&
}{value
}}
318 \constfunc{bool
}{operator $==$
}{\param{const char*
}{value
}}
320 \constfunc{bool
}{operator $==$
}{\param{char
}{value
}}
322 \constfunc{bool
}{operator $==$
}{\param{const long
}{value
}}
324 \constfunc{bool
}{operator $==$
}{\param{const bool
}{value
}}
326 \constfunc{bool
}{operator $==$
}{\param{const double
}{value
}}
328 \constfunc{bool
}{operator $==$
}{\param{void*
}{value
}}
330 \constfunc{bool
}{operator $==$
}{\param{const wxList\&
}{value
}}
332 \constfunc{bool
}{operator $==$
}{\param{const wxArrayString\&
}{value
}}
334 \constfunc{bool
}{operator $==$
}{\param{const wxDateTime\&
}{value
}}
336 Equality test operators.
338 \membersection{wxVariant::operator $!=$
}\label{wxvariantneq
}
340 \constfunc{bool
}{operator $!=$
}{\param{const wxVariant\&
}{value
}}
342 \constfunc{bool
}{operator $!=$
}{\param{const wxString\&
}{value
}}
344 \constfunc{bool
}{operator $!=$
}{\param{const char*
}{value
}}
346 \constfunc{bool
}{operator $!=$
}{\param{char
}{value
}}
348 \constfunc{bool
}{operator $!=$
}{\param{const long
}{value
}}
350 \constfunc{bool
}{operator $!=$
}{\param{const bool
}{value
}}
352 \constfunc{bool
}{operator $!=$
}{\param{const double
}{value
}}
354 \constfunc{bool
}{operator $!=$
}{\param{void*
}{value
}}
356 \constfunc{bool
}{operator $!=$
}{\param{const wxList\&
}{value
}}
358 \constfunc{bool
}{operator $!=$
}{\param{const wxArrayString\&
}{value
}}
360 \constfunc{bool
}{operator $!=$
}{\param{const wxDateTime\&
}{value
}}
362 Inequality test operators.
364 \membersection{wxVariant::operator $
[]$
}\label{wxvariantarray
}
366 \constfunc{wxVariant
}{operator $
[]$
}{\param{size
\_t }{idx
}}
368 Returns the value at
{\it idx
} (zero-based).
370 \func{wxVariant\&
}{operator $
[]$
}{\param{size
\_t }{idx
}}
372 Returns a reference to the value at
{\it idx
} (zero-based). This can be used
373 to change the value at this index.
375 \membersection{wxVariant::operator char
}\label{wxvariantchar
}
377 \constfunc{char
}{operator char
}{\void}
379 Operator for implicit conversion to a char, using
\helpref{wxVariant::GetChar
}{wxvariantgetchar
}.
381 \membersection{wxVariant::operator double
}\label{wxvariantdouble
}
383 \constfunc{double
}{operator double
}{\void}
385 Operator for implicit conversion to a double, using
\helpref{wxVariant::GetDouble
}{wxvariantgetdouble
}.
387 \constfunc{long
}{operator long
}{\void}
389 Operator for implicit conversion to a long, using
\helpref{wxVariant::GetLong
}{wxvariantgetlong
}.
391 \membersection{wxVariant::operator wxString
}\label{wxvariantwxstring
}
393 \constfunc{wxString
}{operator wxString
}{\void}
395 Operator for implicit conversion to a string, using
\helpref{wxVariant::MakeString
}{wxvariantmakestring
}.
397 \membersection{wxVariant::operator void*
}\label{wxvariantvoid
}
399 \constfunc{void*
}{operator void*
}{\void}
401 Operator for implicit conversion to a pointer to a void, using
\helpref{wxVariant::GetVoidPtr
}{wxvariantgetvoidptr
}.
403 \membersection{wxVariant::operator wxDateTime
}\label{wxvariantdatetime
}
405 \constfunc{void*
}{operator wxDateTime
}{\void}
407 Operator for implicit conversion to a pointer to a
\helpref{wxDateTime
}{wxdatetime
}, using
\helpref{wxVariant::GetDateTime
}{wxvariantgetdatetime
}.
409 \section{\class{wxVariantData
}}\label{wxvariantdata
}
411 The
{\bf wxVariantData
} is used to implement a new type for wxVariant. Derive from wxVariantData,
412 and override the pure virtual functions.
414 \wxheading{Derived from
}
416 \helpref{wxObject
}{wxobject
}
418 \wxheading{Include files
}
424 \helpref{wxVariant
}{wxvariant
}
426 \latexignore{\rtfignore{\wxheading{Members
}}}
428 \membersection{wxVariantData::wxVariantData
}\label{wxvariantdatactor
}
430 \func{}{wxVariantData
}{\void}
434 \membersection{wxVariantData::Copy
}\label{wxvariantdatacopy
}
436 \func{void
}{Copy
}{\param{wxVariantData\&
}{ data
}}
438 Copy the data from `this' object to
{\it data
}.
440 \membersection{wxVariantData::Eq
}\label{wxvariantdataeq
}
442 \constfunc{bool
}{Eq
}{\param{wxVariantData\&
}{ data
}}
444 Returns true if this object is equal to
{\it data
}.
446 \membersection{wxVariantData::GetType
}\label{wxvariantdatagettype
}
448 \constfunc{wxString
}{GetType
}{\void}
450 Returns the string type of the data.
452 \membersection{wxVariantData::GetValueClassInfo
}\label{wxvariantdatagetvalueclassinfo
}
454 \constfunc{wxClassInfo*
}{GetValueClassInfo
}{\void}
456 If the data is a wxObject returns a pointer to the objects wxClassInfo structure, if
457 the data isn't a wxObject the method returns NULL.
459 \membersection{wxVariantData::Read
}\label{wxvariantdataread
}
461 \func{bool
}{Read
}{\param{ostream\&
}{ stream
}}
463 \func{bool
}{Read
}{\param{wxString\&
}{ string
}}
465 Reads the data from
{\it stream
} or
{\it string
}.
467 \membersection{wxVariantData::Write
}\label{wxvariantdatawrite
}
469 \constfunc{bool
}{Write
}{\param{ostream\&
}{ stream
}}
471 \constfunc{bool
}{Write
}{\param{wxString\&
}{ string
}}
473 Writes the data to
{\it stream
} or
{\it string
}.
476 \membersection{wxGetVariantCast
}\label{wxgetvariantcast
}
478 \func{classname *
}{wxGetVariantCast
}{wxVariant\&, classname
}
480 This macro returns the data stored in
{\it variant
} cast to the type
{\it classname *
} if
481 the data is of this type (the check is done during the run-time) or
482 {\tt NULL
} otherwise.
487 \helpref{RTTI overview
}{runtimeclassoverview
}\\
488 \helpref{wxDynamicCast
}{wxdynamiccast
}