1 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3 %% Purpose: wxVariant docs
4 %% Author: wxWidgets Team
8 %% Copyright: (c) wxWidgets Team
9 %% License: wxWindows license
10 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
12 \section{\class{wxVariant
}}\label{wxvariant
}
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.
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.
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.
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.
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.
37 Note that as of wxWidgets
2.7.1, wxVariant is reference counted.
39 \wxheading{Derived from
}
41 \helpref{wxObject
}{wxobject
}
43 \wxheading{Include files
}
49 \helpref{wxVariantData
}{wxvariantdata
}
51 \latexignore{\rtfignore{\wxheading{Members
}}}
53 \membersection{wxVariant::wxVariant
}\label{wxvariantctor
}
55 \func{}{wxVariant
}{\void}
59 \func{}{wxVariant
}{\param{const wxVariant\&
}{variant
}}
63 \func{}{wxVariant
}{\param{const char*
}{ value
},
\param{const wxString\&
}{name = ``"
}}
65 \func{}{wxVariant
}{\param{const wxString\&
}{ value
},
\param{const wxString\&
}{name = ``"
}}
67 Construction from a string value.
69 \func{}{wxVariant
}{\param{char
}{ value
},
\param{const wxString\&
}{name = ``"
}}
71 Construction from a character value.
73 \func{}{wxVariant
}{\param{long
}{ value
},
\param{const wxString\&
}{name = ``"
}}
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).
78 \func{}{wxVariant
}{\param{bool
}{ value
},
\param{const wxString\&
}{name = ``"
}}
80 Construction from a boolean value.
82 \func{}{wxVariant
}{\param{double
}{ value
},
\param{const wxString\&
}{name = ``"
}}
84 Construction from a double-precision floating point value.
86 \func{}{wxVariant
}{\param{const wxList\&
}{ value
},
\param{const wxString\&
}{name = ``"
}}
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.
92 \func{}{wxVariant
}{\param{void*
}{ value
},
\param{const wxString\&
}{name = ``"
}}
94 Construction from a void pointer.
96 \func{}{wxVariant
}{\param{wxObject*
}{ value
},
\param{const wxString\&
}{name = ``"
}}
98 Construction from a wxObject pointer.
100 \func{}{wxVariant
}{\param{wxVariantData*
}{ data
},
\param{const wxString\&
}{name = ``"
}}
102 Construction from user-defined data. The variant holds onto the
{\it data
} pointer.
104 \func{}{wxVariant
}{\param{wxDateTime\&
}{ val
},
\param{const wxString\&
}{name = ``"
}}
106 Construction from a
\helpref{wxDateTime
}{wxdatetime
}.
108 \func{}{wxVariant
}{\param{wxArrayString\&
}{ val
},
\param{const wxString\&
}{name = ``"
}}
110 Construction from an array of strings. This constructor copies
{\it value
} and its contents.
112 \func{}{wxVariant
}{\param{DATE
\_STRUCT*
}{ val
},
\param{const wxString\&
}{name = ``"
}}
114 Construction from a odbc date value. Represented internally by a
\helpref{wxDateTime
}{wxdatetime
} value.
116 \func{}{wxVariant
}{\param{TIME
\_STRUCT*
}{ val
},
\param{const wxString\&
}{name = ``"
}}
118 Construction from a odbc time value. Represented internally by a
\helpref{wxDateTime
}{wxdatetime
} value.
120 \func{}{wxVariant
}{\param{TIMESTAMP
\_STRUCT*
}{ val
},
\param{const wxString\&
}{name = ``"
}}
122 Construction from a odbc timestamp value. Represented internally by a
\helpref{wxDateTime
}{wxdatetime
} value.
124 \membersection{wxVariant::
\destruct{wxVariant
}}\label{wxvariantdtor
}
126 \func{}{\destruct{wxVariant
}}{\void}
130 Note that destructor is protected, so wxVariantData cannot usually
131 be deleted. Instead,
\helpref{DecRef
}{wxvariantdatadecref
} should be called.
134 \membersection{wxVariant::Append
}\label{wxvariantappend
}
136 \func{void
}{Append
}{\param{const wxVariant\&
}{ value
}}
138 Appends a value to the list.
140 \membersection{wxVariant::Clear
}\label{wxvariantclear
}
142 \func{void
}{Clear
}{\void}
144 Makes the variant null by deleting the internal data and
145 set the name to
{\it wxEmptyString
}.
147 \membersection{wxVariant::ClearList
}\label{wxvariantclearlist
}
149 \func{void
}{ClearList
}{\void}
151 Deletes the contents of the list.
154 \membersection{wxVariant::Convert
}\label{wxvariantconvert
}
156 \constfunc{bool
}{Convert
}{\param{long*
}{ value
}}
158 \constfunc{bool
}{Convert
}{\param{bool*
}{ value
}}
160 \constfunc{bool
}{Convert
}{\param{double*
}{ value
}}
162 \constfunc{bool
}{Convert
}{\param{wxString*
}{ value
}}
164 \constfunc{bool
}{Convert
}{\param{char*
}{ value
}}
166 \constfunc{bool
}{Convert
}{\param{wxDateTime*
}{ value
}}
168 Retrieves and converts the value of this variant to the type that
{\it value
} is.
171 \membersection{wxVariant::GetCount
}\label{wxvariantgetcount
}
173 \constfunc{size
\_t}{GetCount
}{\void}
175 Returns the number of elements in the list.
177 \membersection{wxVariant::Delete
}\label{wxvariantdelete
}
179 \func{bool
}{Delete
}{\param{size
\_t }{item
}}
181 Deletes the zero-based
{\it item
} from the list.
183 \membersection{wxVariant::GetArrayString
}\label{wxvariantgetarraystring
}
185 \constfunc{wxArrayString
}{GetArrayString
}{\void}
187 Returns the string array value.
189 \membersection{wxVariant::GetBool
}\label{wxvariantgetbool
}
191 \constfunc{bool
}{GetBool
}{\void}
193 Returns the boolean value.
195 \membersection{wxVariant::GetChar
}\label{wxvariantgetchar
}
197 \constfunc{char
}{GetChar
}{\void}
199 Returns the character value.
201 \membersection{wxVariant::GetData
}\label{wxvariantgetdata
}
203 \constfunc{wxVariantData*
}{GetData
}{\void}
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.
210 \membersection{wxVariant::GetDateTime
}\label{wxvariantgetdatetime
}
212 \constfunc{wxDateTime
}{GetDateTime
}{\void}
214 Returns the date value.
216 \membersection{wxVariant::GetDouble
}\label{wxvariantgetdouble
}
218 \constfunc{double
}{GetDouble
}{\void}
220 Returns the floating point value.
222 \membersection{wxVariant::GetLong
}\label{wxvariantgetlong
}
224 \constfunc{long
}{GetLong
}{\void}
226 Returns the integer value.
228 \membersection{wxVariant::GetName
}\label{wxvariantgetname
}
230 \constfunc{const wxString\&
}{GetName
}{\void}
232 Returns a constant reference to the variant name.
234 \membersection{wxVariant::GetString
}\label{wxvariantgetstring
}
236 \constfunc{wxString
}{GetString
}{\void}
238 Gets the string value.
240 \membersection{wxVariant::GetType
}\label{wxvariantgettype
}
242 \constfunc{wxString
}{GetType
}{\void}
244 Returns the value type as a string. The built-in types are: bool, char, date, double, list, long, string, stringlist, time, void*.
246 If the variant is null, the value type returned is the string ``null" (not the empty string).
248 \membersection{wxVariant::GetVoidPtr
}\label{wxvariantgetvoidptr
}
250 \constfunc{void*
}{GetVoidPtr
}{\void}
252 Gets the void pointer value.
254 \membersection{wxVariant::GetWxObjectPtr
}\label{wxvariantgetwxobjectptr
}
256 \constfunc{wxObject*
}{GetWxObjectPtr
}{\void}
258 Gets the wxObject pointer value.
260 \membersection{wxVariant::Insert
}\label{wxvariantinsert
}
262 \func{void
}{Insert
}{\param{const wxVariant\&
}{ value
}}
264 Inserts a value at the front of the list.
266 \membersection{wxVariant::IsNull
}\label{wxvariantisnull
}
268 \constfunc{bool
}{IsNull
}{\void}
270 Returns true if there is no data associated with this variant, false if there is data.
272 \membersection{wxVariant::IsType
}\label{wxvariantistype
}
274 \constfunc{bool
}{IsType
}{\param{const wxString\&
}{ type
}}
276 Returns true if
{\it type
} matches the type of the variant, false otherwise.
278 \membersection{wxVariant::IsValueKindOf
}\label{wxvariantisvaluekindof
}
280 \constfunc{bool
}{IsValueKindOf
}{\param{const wxClassInfo* type
}{ type
}}
282 Returns true if the data is derived from the class described by
{\it type
}, false otherwise.
284 \membersection{wxVariant::MakeNull
}\label{wxvariantmakenull
}
286 \func{void
}{MakeNull
}{\void}
288 Makes the variant null by deleting the internal data.
290 \membersection{wxVariant::MakeString
}\label{wxvariantmakestring
}
292 \constfunc{wxString
}{MakeString
}{\void}
294 Makes a string representation of the variant value (for any type).
296 \membersection{wxVariant::Member
}\label{wxvariantmember
}
298 \constfunc{bool
}{Member
}{\param{const wxVariant\&
}{ value
}}
300 Returns true if
{\it value
} matches an element in the list.
302 \membersection{wxVariant::NullList
}\label{wxvariantnulllist
}
304 \func{void
}{NullList
}{\void}
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.
309 \membersection{wxVariant::SetData
}\label{wxvariantsetdata
}
311 \func{void
}{SetData
}{\param{wxVariantData*
}{ data
}}
313 Sets the internal variant data, deleting the existing data if there is any.
315 \membersection{wxVariant::operator $=$
}\label{wxvariantassignment
}
317 \func{void
}{operator $=$
}{\param{const wxVariant\&
}{value
}}
319 \func{void
}{operator $=$
}{\param{wxVariantData*
}{value
}}
321 \func{void
}{operator $=$
}{\param{const wxString\&
}{value
}}
323 \func{void
}{operator $=$
}{\param{const char*
}{value
}}
325 \func{void
}{operator $=$
}{\param{char
}{value
}}
327 \func{void
}{operator $=$
}{\param{const long
}{value
}}
329 \func{void
}{operator $=$
}{\param{const bool
}{value
}}
331 \func{void
}{operator $=$
}{\param{const double
}{value
}}
333 \func{void
}{operator $=$
}{\param{void*
}{value
}}
335 \func{void
}{operator $=$
}{\param{wxObject*
}{value
}}
337 \func{void
}{operator $=$
}{\param{const wxList\&
}{value
}}
339 \func{void
}{operator $=$
}{\param{const wxDateTime\&
}{value
}}
341 \func{void
}{operator $=$
}{\param{const wxArrayString\&
}{value
}}
343 \func{void
}{operator $=$
}{\param{const DATE
\_STRUCT*
}{value
}}
345 \func{void
}{operator $=$
}{\param{const TIME
\_STRUCT*
}{value
}}
347 \func{void
}{operator $=$
}{\param{const TIMESTAMP
\_STRUCT*
}{value
}}
349 Assignment operators.
351 \membersection{wxVariant::operator $==$
}\label{wxvarianteq
}
353 \constfunc{bool
}{operator $==$
}{\param{const wxVariant\&
}{value
}}
355 \constfunc{bool
}{operator $==$
}{\param{const wxString\&
}{value
}}
357 \constfunc{bool
}{operator $==$
}{\param{const char*
}{value
}}
359 \constfunc{bool
}{operator $==$
}{\param{char
}{value
}}
361 \constfunc{bool
}{operator $==$
}{\param{const long
}{value
}}
363 \constfunc{bool
}{operator $==$
}{\param{const bool
}{value
}}
365 \constfunc{bool
}{operator $==$
}{\param{const double
}{value
}}
367 \constfunc{bool
}{operator $==$
}{\param{void*
}{value
}}
369 \constfunc{bool
}{operator $==$
}{\param{wxObject*
}{value
}}
371 \constfunc{bool
}{operator $==$
}{\param{const wxList\&
}{value
}}
373 \constfunc{bool
}{operator $==$
}{\param{const wxArrayString\&
}{value
}}
375 \constfunc{bool
}{operator $==$
}{\param{const wxDateTime\&
}{value
}}
377 Equality test operators.
379 \membersection{wxVariant::operator $!=$
}\label{wxvariantneq
}
381 \constfunc{bool
}{operator $!=$
}{\param{const wxVariant\&
}{value
}}
383 \constfunc{bool
}{operator $!=$
}{\param{const wxString\&
}{value
}}
385 \constfunc{bool
}{operator $!=$
}{\param{const char*
}{value
}}
387 \constfunc{bool
}{operator $!=$
}{\param{char
}{value
}}
389 \constfunc{bool
}{operator $!=$
}{\param{const long
}{value
}}
391 \constfunc{bool
}{operator $!=$
}{\param{const bool
}{value
}}
393 \constfunc{bool
}{operator $!=$
}{\param{const double
}{value
}}
395 \constfunc{bool
}{operator $!=$
}{\param{void*
}{value
}}
397 \constfunc{bool
}{operator $!=$
}{\param{wxObject*
}{value
}}
399 \constfunc{bool
}{operator $!=$
}{\param{const wxList\&
}{value
}}
401 \constfunc{bool
}{operator $!=$
}{\param{const wxArrayString\&
}{value
}}
403 \constfunc{bool
}{operator $!=$
}{\param{const wxDateTime\&
}{value
}}
405 Inequality test operators.
407 \membersection{wxVariant::operator $
[]$
}\label{wxvariantarray
}
409 \constfunc{wxVariant
}{operator $
[]$
}{\param{size
\_t }{idx
}}
411 Returns the value at
{\it idx
} (zero-based).
413 \func{wxVariant\&
}{operator $
[]$
}{\param{size
\_t }{idx
}}
415 Returns a reference to the value at
{\it idx
} (zero-based). This can be used
416 to change the value at this index.
418 \membersection{wxVariant::operator char
}\label{wxvariantchar
}
420 \constfunc{char
}{operator char
}{\void}
422 Operator for implicit conversion to a char, using
\helpref{wxVariant::GetChar
}{wxvariantgetchar
}.
424 \membersection{wxVariant::operator double
}\label{wxvariantdouble
}
426 \constfunc{double
}{operator double
}{\void}
428 Operator for implicit conversion to a double, using
\helpref{wxVariant::GetDouble
}{wxvariantgetdouble
}.
430 \constfunc{long
}{operator long
}{\void}
432 Operator for implicit conversion to a long, using
\helpref{wxVariant::GetLong
}{wxvariantgetlong
}.
434 \membersection{wxVariant::operator wxString
}\label{wxvariantwxstring
}
436 \constfunc{wxString
}{operator wxString
}{\void}
438 Operator for implicit conversion to a string, using
\helpref{wxVariant::MakeString
}{wxvariantmakestring
}.
440 \membersection{wxVariant::operator void*
}\label{wxvariantvoid
}
442 \constfunc{void*
}{operator void*
}{\void}
444 Operator for implicit conversion to a pointer to a void, using
\helpref{wxVariant::GetVoidPtr
}{wxvariantgetvoidptr
}.
446 \membersection{wxVariant::operator wxDateTime
}\label{wxvariantdatetime
}
448 \constfunc{void*
}{operator wxDateTime
}{\void}
450 Operator for implicit conversion to a pointer to a
\helpref{wxDateTime
}{wxdatetime
}, using
\helpref{wxVariant::GetDateTime
}{wxvariantgetdatetime
}.
452 \section{\class{wxVariantData
}}\label{wxvariantdata
}
454 The
{\bf wxVariantData
} is used to implement a new type for wxVariant. Derive from wxVariantData,
455 and override the pure virtual functions.
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.
466 \wxheading{Derived from
}
468 \helpref{wxObject
}{wxobject
}
470 \wxheading{Include files
}
476 \helpref{wxVariant
}{wxvariant
}
478 \latexignore{\rtfignore{\wxheading{Members
}}}
480 \membersection{wxVariantData::wxVariantData
}\label{wxvariantdatactor
}
482 \func{}{wxVariantData
}{\void}
486 \membersection{wxVariantData::DecRef
}\label{wxvariantdatadecref
}
488 \func{void
}{DecRef
}{\void}
490 Decreases reference count. If the count reaches zero, the object is
491 automatically deleted.
493 Note that destructor of wxVariantData is protected, so delete
494 cannot be used as normal. Instead, DecRef should be called.
496 \membersection{wxVariantData::Eq
}\label{wxvariantdataeq
}
498 \constfunc{bool
}{Eq
}{\param{wxVariantData\&
}{ data
}}
500 Returns true if this object is equal to
{\it data
}.
502 \membersection{wxVariantData::GetType
}\label{wxvariantdatagettype
}
504 \constfunc{wxString
}{GetType
}{\void}
506 Returns the string type of the data.
508 \membersection{wxVariantData::GetValueClassInfo
}\label{wxvariantdatagetvalueclassinfo
}
510 \constfunc{wxClassInfo*
}{GetValueClassInfo
}{\void}
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.
515 \membersection{wxVariantData::IncRef
}\label{wxvariantdataincref
}
517 \func{void
}{IncRef
}{\void}
519 Increases reference count. Note that initially wxVariantData has reference count of
1.
521 \membersection{wxVariantData::Read
}\label{wxvariantdataread
}
523 \func{bool
}{Read
}{\param{ostream\&
}{ stream
}}
525 \func{bool
}{Read
}{\param{wxString\&
}{ string
}}
527 Reads the data from
{\it stream
} or
{\it string
}.
529 \membersection{wxVariantData::Write
}\label{wxvariantdatawrite
}
531 \constfunc{bool
}{Write
}{\param{ostream\&
}{ stream
}}
533 \constfunc{bool
}{Write
}{\param{wxString\&
}{ string
}}
535 Writes the data to
{\it stream
} or
{\it string
}.
538 \membersection{wxGetVariantCast
}\label{wxgetvariantcast
}
540 \func{classname *
}{wxGetVariantCast
}{wxVariant\&, classname
}
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.
549 \helpref{RTTI overview
}{runtimeclassoverview
}\\
550 \helpref{wxDynamicCast
}{wxdynamiccast
}