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, wxChar, 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
}{wxobject
} 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,
35 in CORBA or OLE automation classes, where named parameters are required.
37 Note that as of wxWidgets
2.7.1, wxVariant is reference counted. Additionally, the
38 conveniance macros
{\bf DECLARE
\_VARIANT\_OBJECT} and
{\bf IMPLEMENT
\_VARIANT\_OBJECT}
39 were added so that adding (limited) support for conversion to and from wxVariant
40 can be very easily implemented without modifiying either wxVariant or the class
41 to be stored by wxVariant. Since assignement operators cannot be declared outside
42 the class, the shift left operators are used like this:
46 DECLARE_VARIANT_OBJECT(MyClass)
48 // in the implementation file
49 IMPLMENT_VARIANT_OBJECT(MyClass)
60 For this to work, MyClass must derive from
\helpref{wxObject
}{wxobject
}, implement
61 the
\helpref{wxWidgets RTTI system
}{runtimeclassoverview
}
62 and support the assignment operator and equality operator for itself. Ideally, it
63 should also be reference counted to make copying operations cheap and fast. This
64 can be most easily implemented using the reference counting support offered by
65 \helpref{wxObject
}{wxobject
} itself. By default, wxWidgets already implements
66 the shift operator conversion for a few of its drawing related classes:
69 IMPLEMENT_VARIANT_OBJECT(wxColour)
70 IMPLEMENT_VARIANT_OBJECT(wxImage)
71 IMPLEMENT_VARIANT_OBJECT(wxIcon)
72 IMPLEMENT_VARIANT_OBJECT(wxBitmap)
75 \wxheading{Derived from
}
77 \helpref{wxObject
}{wxobject
}
79 \wxheading{Include files
}
85 \helpref{wxVariantData
}{wxvariantdata
}
87 \latexignore{\rtfignore{\wxheading{Members
}}}
89 \membersection{wxVariant::wxVariant
}\label{wxvariantctor
}
91 \func{}{wxVariant
}{\void}
95 \func{}{wxVariant
}{\param{const wxVariant\&
}{variant
}}
99 \func{}{wxVariant
}{\param{const wxChar*
}{ value
},
\param{const wxString\&
}{name = ``"
}}
101 \func{}{wxVariant
}{\param{const wxString\&
}{ value
},
\param{const wxString\&
}{name = ``"
}}
103 Construction from a string value.
105 \func{}{wxVariant
}{\param{wxChar
}{ value
},
\param{const wxString\&
}{name = ``"
}}
107 Construction from a character value.
109 \func{}{wxVariant
}{\param{long
}{ value
},
\param{const wxString\&
}{name = ``"
}}
111 Construction from an integer value. You may need to cast to (long) to
112 avoid confusion with other constructors (such as the bool constructor).
114 \func{}{wxVariant
}{\param{bool
}{ value
},
\param{const wxString\&
}{name = ``"
}}
116 Construction from a boolean value.
118 \func{}{wxVariant
}{\param{double
}{ value
},
\param{const wxString\&
}{name = ``"
}}
120 Construction from a double-precision floating point value.
122 \func{}{wxVariant
}{\param{const wxList\&
}{ value
},
\param{const wxString\&
}{name = ``"
}}
124 Construction from a list of wxVariant objects. This constructor
125 copies
{\it value
}, the application is still responsible for
126 deleting
{\it value
} and its contents.
128 \func{}{wxVariant
}{\param{void*
}{ value
},
\param{const wxString\&
}{name = ``"
}}
130 Construction from a void pointer.
132 \func{}{wxVariant
}{\param{wxObject*
}{ value
},
\param{const wxString\&
}{name = ``"
}}
134 Construction from a wxObject pointer.
136 \func{}{wxVariant
}{\param{wxVariantData*
}{ data
},
\param{const wxString\&
}{name = ``"
}}
138 Construction from user-defined data. The variant holds onto the
{\it data
} pointer.
140 \func{}{wxVariant
}{\param{wxDateTime\&
}{ val
},
\param{const wxString\&
}{name = ``"
}}
142 Construction from a
\helpref{wxDateTime
}{wxdatetime
}.
144 \func{}{wxVariant
}{\param{wxArrayString\&
}{ val
},
\param{const wxString\&
}{name = ``"
}}
146 Construction from an array of strings. This constructor copies
{\it value
} and its contents.
148 \func{}{wxVariant
}{\param{DATE
\_STRUCT*
}{ val
},
\param{const wxString\&
}{name = ``"
}}
150 Construction from a odbc date value. Represented internally by a
\helpref{wxDateTime
}{wxdatetime
} value.
152 \func{}{wxVariant
}{\param{TIME
\_STRUCT*
}{ val
},
\param{const wxString\&
}{name = ``"
}}
154 Construction from a odbc time value. Represented internally by a
\helpref{wxDateTime
}{wxdatetime
} value.
156 \func{}{wxVariant
}{\param{TIMESTAMP
\_STRUCT*
}{ val
},
\param{const wxString\&
}{name = ``"
}}
158 Construction from a odbc timestamp value. Represented internally by a
\helpref{wxDateTime
}{wxdatetime
} value.
160 \membersection{wxVariant::
\destruct{wxVariant
}}\label{wxvariantdtor
}
162 \func{}{\destruct{wxVariant
}}{\void}
166 Note that destructor is protected, so wxVariantData cannot usually
167 be deleted. Instead,
\helpref{DecRef
}{wxvariantdatadecref
} should be called.
170 \membersection{wxVariant::Append
}\label{wxvariantappend
}
172 \func{void
}{Append
}{\param{const wxVariant\&
}{ value
}}
174 Appends a value to the list.
176 \membersection{wxVariant::Clear
}\label{wxvariantclear
}
178 \func{void
}{Clear
}{\void}
180 Makes the variant null by deleting the internal data and
181 set the name to
{\it wxEmptyString
}.
183 \membersection{wxVariant::ClearList
}\label{wxvariantclearlist
}
185 \func{void
}{ClearList
}{\void}
187 Deletes the contents of the list.
190 \membersection{wxVariant::Convert
}\label{wxvariantconvert
}
192 \constfunc{bool
}{Convert
}{\param{long*
}{ value
}}
194 \constfunc{bool
}{Convert
}{\param{bool*
}{ value
}}
196 \constfunc{bool
}{Convert
}{\param{double*
}{ value
}}
198 \constfunc{bool
}{Convert
}{\param{wxString*
}{ value
}}
200 \constfunc{bool
}{Convert
}{\param{wxChar*
}{ value
}}
202 \constfunc{bool
}{Convert
}{\param{wxDateTime*
}{ value
}}
204 Retrieves and converts the value of this variant to the type that
{\it value
} is.
207 \membersection{wxVariant::GetCount
}\label{wxvariantgetcount
}
209 \constfunc{size
\_t}{GetCount
}{\void}
211 Returns the number of elements in the list.
213 \membersection{wxVariant::Delete
}\label{wxvariantdelete
}
215 \func{bool
}{Delete
}{\param{size
\_t }{item
}}
217 Deletes the zero-based
{\it item
} from the list.
219 \membersection{wxVariant::GetArrayString
}\label{wxvariantgetarraystring
}
221 \constfunc{wxArrayString
}{GetArrayString
}{\void}
223 Returns the string array value.
225 \membersection{wxVariant::GetBool
}\label{wxvariantgetbool
}
227 \constfunc{bool
}{GetBool
}{\void}
229 Returns the boolean value.
231 \membersection{wxVariant::GetChar
}\label{wxvariantgetchar
}
233 \constfunc{wxChar
}{GetChar
}{\void}
235 Returns the character value.
237 \membersection{wxVariant::GetData
}\label{wxvariantgetdata
}
239 \constfunc{wxVariantData*
}{GetData
}{\void}
241 Returns a pointer to the internal variant data. To take ownership
242 of this data, you must call its
\helpref{IncRef
}{wxvariantdataincref
}
243 method. When you stop using it,
\helpref{DecRef
}{wxvariantdatadecref
}
244 must be likewise called.
246 \membersection{wxVariant::GetDateTime
}\label{wxvariantgetdatetime
}
248 \constfunc{wxDateTime
}{GetDateTime
}{\void}
250 Returns the date value.
252 \membersection{wxVariant::GetDouble
}\label{wxvariantgetdouble
}
254 \constfunc{double
}{GetDouble
}{\void}
256 Returns the floating point value.
258 \membersection{wxVariant::GetLong
}\label{wxvariantgetlong
}
260 \constfunc{long
}{GetLong
}{\void}
262 Returns the integer value.
264 \membersection{wxVariant::GetName
}\label{wxvariantgetname
}
266 \constfunc{const wxString\&
}{GetName
}{\void}
268 Returns a constant reference to the variant name.
270 \membersection{wxVariant::GetString
}\label{wxvariantgetstring
}
272 \constfunc{wxString
}{GetString
}{\void}
274 Gets the string value.
276 \membersection{wxVariant::GetType
}\label{wxvariantgettype
}
278 \constfunc{wxString
}{GetType
}{\void}
280 Returns the value type as a string. The built-in types are: bool, char, date, double, list, long, string, stringlist, time, void*.
282 If the variant is null, the value type returned is the string ``null" (not the empty string).
284 \membersection{wxVariant::GetVoidPtr
}\label{wxvariantgetvoidptr
}
286 \constfunc{void*
}{GetVoidPtr
}{\void}
288 Gets the void pointer value.
290 \membersection{wxVariant::GetWxObjectPtr
}\label{wxvariantgetwxobjectptr
}
292 \constfunc{wxObject*
}{GetWxObjectPtr
}{\void}
294 Gets the wxObject pointer value.
296 \membersection{wxVariant::Insert
}\label{wxvariantinsert
}
298 \func{void
}{Insert
}{\param{const wxVariant\&
}{ value
}}
300 Inserts a value at the front of the list.
302 \membersection{wxVariant::IsNull
}\label{wxvariantisnull
}
304 \constfunc{bool
}{IsNull
}{\void}
306 Returns true if there is no data associated with this variant, false if there is data.
308 \membersection{wxVariant::IsType
}\label{wxvariantistype
}
310 \constfunc{bool
}{IsType
}{\param{const wxString\&
}{ type
}}
312 Returns true if
{\it type
} matches the type of the variant, false otherwise.
314 \membersection{wxVariant::IsValueKindOf
}\label{wxvariantisvaluekindof
}
316 \constfunc{bool
}{IsValueKindOf
}{\param{const wxClassInfo* type
}{ type
}}
318 Returns true if the data is derived from the class described by
{\it type
}, false otherwise.
320 \membersection{wxVariant::MakeNull
}\label{wxvariantmakenull
}
322 \func{void
}{MakeNull
}{\void}
324 Makes the variant null by deleting the internal data.
326 \membersection{wxVariant::MakeString
}\label{wxvariantmakestring
}
328 \constfunc{wxString
}{MakeString
}{\void}
330 Makes a string representation of the variant value (for any type).
332 \membersection{wxVariant::Member
}\label{wxvariantmember
}
334 \constfunc{bool
}{Member
}{\param{const wxVariant\&
}{ value
}}
336 Returns true if
{\it value
} matches an element in the list.
338 \membersection{wxVariant::NullList
}\label{wxvariantnulllist
}
340 \func{void
}{NullList
}{\void}
342 Makes an empty list. This differs from a null variant which has no data; a null list
343 is of type list, but the number of elements in the list is zero.
345 \membersection{wxVariant::SetData
}\label{wxvariantsetdata
}
347 \func{void
}{SetData
}{\param{wxVariantData*
}{ data
}}
349 Sets the internal variant data, deleting the existing data if there is any.
351 \membersection{wxVariant::operator $=$
}\label{wxvariantassignment
}
353 \func{void
}{operator $=$
}{\param{const wxVariant\&
}{value
}}
355 \func{void
}{operator $=$
}{\param{wxVariantData*
}{value
}}
357 \func{void
}{operator $=$
}{\param{const wxString\&
}{value
}}
359 \func{void
}{operator $=$
}{\param{const wxChar*
}{value
}}
361 \func{void
}{operator $=$
}{\param{wxChar
}{value
}}
363 \func{void
}{operator $=$
}{\param{const long
}{value
}}
365 \func{void
}{operator $=$
}{\param{const bool
}{value
}}
367 \func{void
}{operator $=$
}{\param{const double
}{value
}}
369 \func{void
}{operator $=$
}{\param{void*
}{value
}}
371 \func{void
}{operator $=$
}{\param{wxObject*
}{value
}}
373 \func{void
}{operator $=$
}{\param{const wxList\&
}{value
}}
375 \func{void
}{operator $=$
}{\param{const wxDateTime\&
}{value
}}
377 \func{void
}{operator $=$
}{\param{const wxArrayString\&
}{value
}}
379 \func{void
}{operator $=$
}{\param{const DATE
\_STRUCT*
}{value
}}
381 \func{void
}{operator $=$
}{\param{const TIME
\_STRUCT*
}{value
}}
383 \func{void
}{operator $=$
}{\param{const TIMESTAMP
\_STRUCT*
}{value
}}
385 Assignment operators.
387 \membersection{wxVariant::operator $==$
}\label{wxvarianteq
}
389 \constfunc{bool
}{operator $==$
}{\param{const wxVariant\&
}{value
}}
391 \constfunc{bool
}{operator $==$
}{\param{const wxString\&
}{value
}}
393 \constfunc{bool
}{operator $==$
}{\param{const wxChar*
}{value
}}
395 \constfunc{bool
}{operator $==$
}{\param{wxChar
}{value
}}
397 \constfunc{bool
}{operator $==$
}{\param{const long
}{value
}}
399 \constfunc{bool
}{operator $==$
}{\param{const bool
}{value
}}
401 \constfunc{bool
}{operator $==$
}{\param{const double
}{value
}}
403 \constfunc{bool
}{operator $==$
}{\param{void*
}{value
}}
405 \constfunc{bool
}{operator $==$
}{\param{wxObject*
}{value
}}
407 \constfunc{bool
}{operator $==$
}{\param{const wxList\&
}{value
}}
409 \constfunc{bool
}{operator $==$
}{\param{const wxArrayString\&
}{value
}}
411 \constfunc{bool
}{operator $==$
}{\param{const wxDateTime\&
}{value
}}
413 Equality test operators.
415 \membersection{wxVariant::operator $!=$
}\label{wxvariantneq
}
417 \constfunc{bool
}{operator $!=$
}{\param{const wxVariant\&
}{value
}}
419 \constfunc{bool
}{operator $!=$
}{\param{const wxString\&
}{value
}}
421 \constfunc{bool
}{operator $!=$
}{\param{const wxChar*
}{value
}}
423 \constfunc{bool
}{operator $!=$
}{\param{wxChar
}{value
}}
425 \constfunc{bool
}{operator $!=$
}{\param{const long
}{value
}}
427 \constfunc{bool
}{operator $!=$
}{\param{const bool
}{value
}}
429 \constfunc{bool
}{operator $!=$
}{\param{const double
}{value
}}
431 \constfunc{bool
}{operator $!=$
}{\param{void*
}{value
}}
433 \constfunc{bool
}{operator $!=$
}{\param{wxObject*
}{value
}}
435 \constfunc{bool
}{operator $!=$
}{\param{const wxList\&
}{value
}}
437 \constfunc{bool
}{operator $!=$
}{\param{const wxArrayString\&
}{value
}}
439 \constfunc{bool
}{operator $!=$
}{\param{const wxDateTime\&
}{value
}}
441 Inequality test operators.
443 \membersection{wxVariant::operator $
[]$
}\label{wxvariantarray
}
445 \constfunc{wxVariant
}{operator $
[]$
}{\param{size
\_t }{idx
}}
447 Returns the value at
{\it idx
} (zero-based).
449 \func{wxVariant\&
}{operator $
[]$
}{\param{size
\_t }{idx
}}
451 Returns a reference to the value at
{\it idx
} (zero-based). This can be used
452 to change the value at this index.
454 \membersection{wxVariant::operator wxChar
}\label{wxvariantchar
}
456 \constfunc{char
}{operator wxChar
}{\void}
458 Operator for implicit conversion to a wxChar, using
\helpref{wxVariant::GetChar
}{wxvariantgetchar
}.
460 \membersection{wxVariant::operator double
}\label{wxvariantdouble
}
462 \constfunc{double
}{operator double
}{\void}
464 Operator for implicit conversion to a double, using
\helpref{wxVariant::GetDouble
}{wxvariantgetdouble
}.
466 \constfunc{long
}{operator long
}{\void}
468 Operator for implicit conversion to a long, using
\helpref{wxVariant::GetLong
}{wxvariantgetlong
}.
470 \membersection{wxVariant::operator wxString
}\label{wxvariantwxstring
}
472 \constfunc{wxString
}{operator wxString
}{\void}
474 Operator for implicit conversion to a string, using
\helpref{wxVariant::MakeString
}{wxvariantmakestring
}.
476 \membersection{wxVariant::operator void*
}\label{wxvariantvoid
}
478 \constfunc{void*
}{operator void*
}{\void}
480 Operator for implicit conversion to a pointer to a void, using
\helpref{wxVariant::GetVoidPtr
}{wxvariantgetvoidptr
}.
482 \membersection{wxVariant::operator wxDateTime
}\label{wxvariantdatetime
}
484 \constfunc{void*
}{operator wxDateTime
}{\void}
486 Operator for implicit conversion to a pointer to a
\helpref{wxDateTime
}{wxdatetime
}, using
\helpref{wxVariant::GetDateTime
}{wxvariantgetdatetime
}.
488 \section{\class{wxVariantData
}}\label{wxvariantdata
}
490 The
{\bf wxVariantData
} is used to implement a new type for wxVariant. Derive from wxVariantData,
491 and override the pure virtual functions.
493 wxVariantData is reference counted, but you don't normally have to care about this, as
494 wxVariant manages the count automatically. However, incase your application needs to take
495 ownership of wxVariantData, be aware that the object is created with reference count of
1,
496 and passing it to wxVariant will not increase this. In other words,
\helpref{IncRef
}{wxvariantdataincref
}
497 needs to be called only if you both take ownership of wxVariantData and pass it to a wxVariant.
498 Also note that the destructor is protected, so you can never explicitly delete a wxVariantData
499 instance. Instead,
\helpref{DecRef
}{wxvariantdatadecref
} will delete the object automatically
500 when the reference count reaches zero.
502 \wxheading{Derived from
}
504 \helpref{wxObject
}{wxobject
}
506 \wxheading{Include files
}
512 \helpref{wxVariant
}{wxvariant
}
514 \latexignore{\rtfignore{\wxheading{Members
}}}
516 \membersection{wxVariantData::wxVariantData
}\label{wxvariantdatactor
}
518 \func{}{wxVariantData
}{\void}
522 \membersection{wxVariantData::DecRef
}\label{wxvariantdatadecref
}
524 \func{void
}{DecRef
}{\void}
526 Decreases reference count. If the count reaches zero, the object is
527 automatically deleted.
529 Note that destructor of wxVariantData is protected, so delete
530 cannot be used as normal. Instead, DecRef should be called.
532 \membersection{wxVariantData::Eq
}\label{wxvariantdataeq
}
534 \constfunc{bool
}{Eq
}{\param{wxVariantData\&
}{ data
}}
536 Returns true if this object is equal to
{\it data
}.
538 \membersection{wxVariantData::GetType
}\label{wxvariantdatagettype
}
540 \constfunc{wxString
}{GetType
}{\void}
542 Returns the string type of the data.
544 \membersection{wxVariantData::GetValueClassInfo
}\label{wxvariantdatagetvalueclassinfo
}
546 \constfunc{wxClassInfo*
}{GetValueClassInfo
}{\void}
548 If the data is a wxObject returns a pointer to the objects wxClassInfo structure, if
549 the data isn't a wxObject the method returns NULL.
551 \membersection{wxVariantData::IncRef
}\label{wxvariantdataincref
}
553 \func{void
}{IncRef
}{\void}
555 Increases reference count. Note that initially wxVariantData has reference count of
1.
557 \membersection{wxVariantData::Read
}\label{wxvariantdataread
}
559 \func{bool
}{Read
}{\param{ostream\&
}{ stream
}}
561 \func{bool
}{Read
}{\param{wxString\&
}{ string
}}
563 Reads the data from
{\it stream
} or
{\it string
}.
565 \membersection{wxVariantData::Write
}\label{wxvariantdatawrite
}
567 \constfunc{bool
}{Write
}{\param{ostream\&
}{ stream
}}
569 \constfunc{bool
}{Write
}{\param{wxString\&
}{ string
}}
571 Writes the data to
{\it stream
} or
{\it string
}.
574 \membersection{wxGetVariantCast
}\label{wxgetvariantcast
}
576 \func{classname *
}{wxGetVariantCast
}{wxVariant\&, classname
}
578 This macro returns the data stored in
{\it variant
} cast to the type
{\it classname *
} if
579 the data is of this type (the check is done during the run-time) or
580 {\tt NULL
} otherwise.
585 \helpref{RTTI overview
}{runtimeclassoverview
}\\
586 \helpref{wxDynamicCast
}{wxdynamiccast
}