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. 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.
20 This class is useful for reducing the programming for certain tasks, such as an editor
21 for different data types, or a remote procedure call protocol.
23 An optional name member is associated with a wxVariant. This might be used, for example, in CORBA
24 or OLE automation classes, where named parameters are required.
26 \wxheading{Derived from
}
28 \helpref{wxObject
}{wxobject
}
30 \wxheading{Include files
}
36 \helpref{wxVariantData
}{wxvariantdata
}
38 \latexignore{\rtfignore{\wxheading{Members
}}}
40 \membersection{wxVariant::wxVariant
}\label{wxvariantctor
}
42 \func{}{wxVariant
}{\void}
46 \func{}{wxVariant
}{\param{const wxVariant\&
}{variant
}}
50 \func{}{wxVariant
}{\param{const char*
}{ value
},
\param{const wxString\&
}{name = ``"
}}
52 \func{}{wxVariant
}{\param{const wxString\&
}{ value
},
\param{const wxString\&
}{name = ``"
}}
54 Construction from a string value.
56 \func{}{wxVariant
}{\param{char
}{ value
},
\param{const wxString\&
}{name = ``"
}}
58 Construction from a character value.
60 \func{}{wxVariant
}{\param{long
}{ value
},
\param{const wxString\&
}{name = ``"
}}
62 Construction from an integer value. You may need to cast to (long) to
63 avoid confusion with other constructors (such as the bool constructor).
65 \func{}{wxVariant
}{\param{bool
}{ value
},
\param{const wxString\&
}{name = ``"
}}
67 Construction from a boolean value.
69 \func{}{wxVariant
}{\param{double
}{ value
},
\param{const wxString\&
}{name = ``"
}}
71 Construction from a double-precision floating point value.
73 \func{}{wxVariant
}{\param{const wxList\&
}{ value
},
\param{const wxString\&
}{name = ``"
}}
75 Construction from a list of wxVariant objects. This constructor
76 copies
{\it value
}, the application is still responsible for
77 deleting
{\it value
} and its contents.
79 \func{}{wxVariant
}{\param{void*
}{ value
},
\param{const wxString\&
}{name = ``"
}}
81 Construction from a void pointer.
83 \func{}{wxVariant
}{\param{wxObject*
}{ value
},
\param{const wxString\&
}{name = ``"
}}
85 Construction from a wxObject pointer.
87 \func{}{wxVariant
}{\param{wxVariantData*
}{ data
},
\param{const wxString\&
}{name = ``"
}}
89 Construction from user-defined data. The variant holds onto the
{\it data
} pointer.
91 \func{}{wxVariant
}{\param{wxDateTime\&
}{ val
},
\param{const wxString\&
}{name = ``"
}}
93 Construction from a
\helpref{wxDateTime
}{wxdatetime
}.
95 \func{}{wxVariant
}{\param{wxArrayString\&
}{ val
},
\param{const wxString\&
}{name = ``"
}}
97 Construction from an array of strings. This constructor copies
{\it value
} and its contents.
99 \func{}{wxVariant
}{\param{DATE
\_STRUCT*
}{ val
},
\param{const wxString\&
}{name = ``"
}}
101 Construction from a odbc date value. Represented internally by a
\helpref{wxDateTime
}{wxdatetime
} value.
103 \func{}{wxVariant
}{\param{TIME
\_STRUCT*
}{ val
},
\param{const wxString\&
}{name = ``"
}}
105 Construction from a odbc time value. Represented internally by a
\helpref{wxDateTime
}{wxdatetime
} value.
107 \func{}{wxVariant
}{\param{TIMESTAMP
\_STRUCT*
}{ val
},
\param{const wxString\&
}{name = ``"
}}
109 Construction from a odbc timestamp value. Represented internally by a
\helpref{wxDateTime
}{wxdatetime
} value.
111 \membersection{wxVariant::
\destruct{wxVariant
}}\label{wxvariantdtor
}
113 \func{}{\destruct{wxVariant
}}{\void}
118 \membersection{wxVariant::Append
}\label{wxvariantappend
}
120 \func{void
}{Append
}{\param{const wxVariant\&
}{ value
}}
122 Appends a value to the list.
124 \membersection{wxVariant::ClearList
}\label{wxvariantclearlist
}
126 \func{void
}{ClearList
}{\void}
128 Deletes the contents of the list.
131 \membersection{wxVariant::Convert
}\label{wxvariantconvert
}
133 \constfunc{bool
}{Convert
}{\param{long*
}{ value
}}
135 \constfunc{bool
}{Convert
}{\param{bool*
}{ value
}}
137 \constfunc{bool
}{Convert
}{\param{double*
}{ value
}}
139 \constfunc{bool
}{Convert
}{\param{wxString*
}{ value
}}
141 \constfunc{bool
}{Convert
}{\param{char*
}{ value
}}
143 \constfunc{bool
}{Convert
}{\param{wxDateTime*
}{ value
}}
145 Retrieves and converts the value of this variant to the type that
{\it value
} is.
148 \membersection{wxVariant::GetCount
}\label{wxvariantgetcount
}
150 \constfunc{size
\_t}{GetCount
}{\void}
152 Returns the number of elements in the list.
154 \membersection{wxVariant::Delete
}\label{wxvariantdelete
}
156 \func{bool
}{Delete
}{\param{size
\_t }{item
}}
158 Deletes the zero-based
{\it item
} from the list.
160 \membersection{wxVariant::GetArrayString
}\label{wxvariantgetarraystring
}
162 \constfunc{wxArrayString
}{GetArrayString
}{\void}
164 Returns the string array value.
166 \membersection{wxVariant::GetBool
}\label{wxvariantgetbool
}
168 \constfunc{bool
}{GetBool
}{\void}
170 Returns the boolean value.
172 \membersection{wxVariant::GetChar
}\label{wxvariantgetchar
}
174 \constfunc{char
}{GetChar
}{\void}
176 Returns the character value.
178 \membersection{wxVariant::GetData
}\label{wxvariantgetdata
}
180 \constfunc{wxVariantData*
}{GetData
}{\void}
182 Returns a pointer to the internal variant data.
184 \membersection{wxVariant::GetDateTime
}\label{wxvariantgetdatetime
}
186 \constfunc{wxDateTime
}{GetDateTime
}{\void}
188 Returns the date value.
190 \membersection{wxVariant::GetDouble
}\label{wxvariantgetdouble
}
192 \constfunc{double
}{GetDouble
}{\void}
194 Returns the floating point value.
196 \membersection{wxVariant::GetLong
}\label{wxvariantgetlong
}
198 \constfunc{long
}{GetLong
}{\void}
200 Returns the integer value.
202 \membersection{wxVariant::GetName
}\label{wxvariantgetname
}
204 \constfunc{const wxString\&
}{GetName
}{\void}
206 Returns a constant reference to the variant name.
208 \membersection{wxVariant::GetString
}\label{wxvariantgetstring
}
210 \constfunc{wxString
}{GetString
}{\void}
212 Gets the string value.
214 \membersection{wxVariant::GetType
}\label{wxvariantgettype
}
216 \constfunc{wxString
}{GetType
}{\void}
218 Returns the value type as a string. The built-in types are: bool, char, date, double, list, long, string, stringlist, time, void*.
220 If the variant is null, the value type returned is the string ``null" (not the empty string).
222 \membersection{wxVariant::GetVoidPtr
}\label{wxvariantgetvoidptr
}
224 \constfunc{void*
}{GetVoidPtr
}{\void}
226 Gets the void pointer value.
228 \membersection{wxVariant::GetWxObjectPtr
}\label{wxvariantgetwxobjectptr
}
230 \constfunc{void*
}{GetWxObjectPtr
}{\void}
232 Gets the wxObject pointer value.
234 \membersection{wxVariant::Insert
}\label{wxvariantinsert
}
236 \func{void
}{Insert
}{\param{const wxVariant\&
}{ value
}}
238 Inserts a value at the front of the list.
240 \membersection{wxVariant::IsNull
}\label{wxvariantisnull
}
242 \constfunc{bool
}{IsNull
}{\void}
244 Returns true if there is no data associated with this variant, false if there is data.
246 \membersection{wxVariant::IsType
}\label{wxvariantistype
}
248 \constfunc{bool
}{IsType
}{\param{const wxString\&
}{ type
}}
250 Returns true if
{\it type
} matches the type of the variant, false otherwise.
252 \membersection{wxVariant::IsValueKindOf
}\label{wxvariantisvaluekindof
}
254 \constfunc{bool
}{IsValueKindOf
}{\param{const wxClassInfo* type
}{ type
}}
256 Returns true if the data is derived from the class described by
{\it type
}, false otherwise.
258 \membersection{wxVariant::MakeNull
}\label{wxvariantmakenull
}
260 \func{void
}{MakeNull
}{\void}
262 Makes the variant null by deleting the internal data.
264 \membersection{wxVariant::MakeString
}\label{wxvariantmakestring
}
266 \constfunc{wxString
}{MakeString
}{\void}
268 Makes a string representation of the variant value (for any type).
270 \membersection{wxVariant::Member
}\label{wxvariantmember
}
272 \constfunc{bool
}{Member
}{\param{const wxVariant\&
}{ value
}}
274 Returns true if
{\it value
} matches an element in the list.
276 \membersection{wxVariant::NullList
}\label{wxvariantnulllist
}
278 \func{void
}{NullList
}{\void}
280 Makes an empty list. This differs from a null variant which has no data; a null list
281 is of type list, but the number of elements in the list is zero.
283 \membersection{wxVariant::SetData
}\label{wxvariantsetdata
}
285 \func{void
}{SetData
}{\param{wxVariantData*
}{ data
}}
287 Sets the internal variant data, deleting the existing data if there is any.
289 \membersection{wxVariant::operator $=$
}\label{wxvariantassignment
}
291 \func{void
}{operator $=$
}{\param{const wxVariant\&
}{value
}}
293 \func{void
}{operator $=$
}{\param{wxVariantData*
}{value
}}
295 \func{void
}{operator $=$
}{\param{const wxString\&
}{value
}}
297 \func{void
}{operator $=$
}{\param{const char*
}{value
}}
299 \func{void
}{operator $=$
}{\param{char
}{value
}}
301 \func{void
}{operator $=$
}{\param{const long
}{value
}}
303 \func{void
}{operator $=$
}{\param{const bool
}{value
}}
305 \func{void
}{operator $=$
}{\param{const double
}{value
}}
307 \func{void
}{operator $=$
}{\param{void*
}{value
}}
309 \func{void
}{operator $=$
}{\param{const wxList\&
}{value
}}
311 \func{void
}{operator $=$
}{\param{const wxDateTime\&
}{value
}}
313 \func{void
}{operator $=$
}{\param{const wxArrayString\&
}{value
}}
315 \func{void
}{operator $=$
}{\param{const DATE
\_STRUCT*
}{value
}}
317 \func{void
}{operator $=$
}{\param{const TIME
\_STRUCT*
}{value
}}
319 \func{void
}{operator $=$
}{\param{const TIMESTAMP
\_STRUCT*
}{value
}}
321 Assignment operators.
323 \membersection{wxVariant::operator $==$
}\label{wxvarianteq
}
325 \constfunc{bool
}{operator $==$
}{\param{const wxVariant\&
}{value
}}
327 \constfunc{bool
}{operator $==$
}{\param{const wxString\&
}{value
}}
329 \constfunc{bool
}{operator $==$
}{\param{const char*
}{value
}}
331 \constfunc{bool
}{operator $==$
}{\param{char
}{value
}}
333 \constfunc{bool
}{operator $==$
}{\param{const long
}{value
}}
335 \constfunc{bool
}{operator $==$
}{\param{const bool
}{value
}}
337 \constfunc{bool
}{operator $==$
}{\param{const double
}{value
}}
339 \constfunc{bool
}{operator $==$
}{\param{void*
}{value
}}
341 \constfunc{bool
}{operator $==$
}{\param{const wxList\&
}{value
}}
343 \constfunc{bool
}{operator $==$
}{\param{const wxArrayString\&
}{value
}}
345 \constfunc{bool
}{operator $==$
}{\param{const wxDateTime\&
}{value
}}
347 Equality test operators.
349 \membersection{wxVariant::operator $!=$
}\label{wxvariantneq
}
351 \constfunc{bool
}{operator $!=$
}{\param{const wxVariant\&
}{value
}}
353 \constfunc{bool
}{operator $!=$
}{\param{const wxString\&
}{value
}}
355 \constfunc{bool
}{operator $!=$
}{\param{const char*
}{value
}}
357 \constfunc{bool
}{operator $!=$
}{\param{char
}{value
}}
359 \constfunc{bool
}{operator $!=$
}{\param{const long
}{value
}}
361 \constfunc{bool
}{operator $!=$
}{\param{const bool
}{value
}}
363 \constfunc{bool
}{operator $!=$
}{\param{const double
}{value
}}
365 \constfunc{bool
}{operator $!=$
}{\param{void*
}{value
}}
367 \constfunc{bool
}{operator $!=$
}{\param{const wxList\&
}{value
}}
369 \constfunc{bool
}{operator $!=$
}{\param{const wxArrayString\&
}{value
}}
371 \constfunc{bool
}{operator $!=$
}{\param{const wxDateTime\&
}{value
}}
373 Inequality test operators.
375 \membersection{wxVariant::operator $
[]$
}\label{wxvariantarray
}
377 \constfunc{wxVariant
}{operator $
[]$
}{\param{size
\_t }{idx
}}
379 Returns the value at
{\it idx
} (zero-based).
381 \func{wxVariant\&
}{operator $
[]$
}{\param{size
\_t }{idx
}}
383 Returns a reference to the value at
{\it idx
} (zero-based). This can be used
384 to change the value at this index.
386 \membersection{wxVariant::operator char
}\label{wxvariantchar
}
388 \constfunc{char
}{operator char
}{\void}
390 Operator for implicit conversion to a char, using
\helpref{wxVariant::GetChar
}{wxvariantgetchar
}.
392 \membersection{wxVariant::operator double
}\label{wxvariantdouble
}
394 \constfunc{double
}{operator double
}{\void}
396 Operator for implicit conversion to a double, using
\helpref{wxVariant::GetDouble
}{wxvariantgetdouble
}.
398 \constfunc{long
}{operator long
}{\void}
400 Operator for implicit conversion to a long, using
\helpref{wxVariant::GetLong
}{wxvariantgetlong
}.
402 \membersection{wxVariant::operator wxString
}\label{wxvariantwxstring
}
404 \constfunc{wxString
}{operator wxString
}{\void}
406 Operator for implicit conversion to a string, using
\helpref{wxVariant::MakeString
}{wxvariantmakestring
}.
408 \membersection{wxVariant::operator void*
}\label{wxvariantvoid
}
410 \constfunc{void*
}{operator void*
}{\void}
412 Operator for implicit conversion to a pointer to a void, using
\helpref{wxVariant::GetVoidPtr
}{wxvariantgetvoidptr
}.
414 \membersection{wxVariant::operator wxDateTime
}\label{wxvariantdatetime
}
416 \constfunc{void*
}{operator wxDateTime
}{\void}
418 Operator for implicit conversion to a pointer to a
\helpref{wxDateTime
}{wxdatetime
}, using
\helpref{wxVariant::GetDateTime
}{wxvariantgetdatetime
}.
420 \section{\class{wxVariantData
}}\label{wxvariantdata
}
422 The
{\bf wxVariantData
} is used to implement a new type for wxVariant. Derive from wxVariantData,
423 and override the pure virtual functions.
425 \wxheading{Derived from
}
427 \helpref{wxObject
}{wxobject
}
429 \wxheading{Include files
}
435 \helpref{wxVariant
}{wxvariant
}
437 \latexignore{\rtfignore{\wxheading{Members
}}}
439 \membersection{wxVariantData::wxVariantData
}\label{wxvariantdatactor
}
441 \func{}{wxVariantData
}{\void}
445 \membersection{wxVariantData::Copy
}\label{wxvariantdatacopy
}
447 \func{void
}{Copy
}{\param{wxVariantData\&
}{ data
}}
449 Copy the data from `this' object to
{\it data
}.
451 \membersection{wxVariantData::Eq
}\label{wxvariantdataeq
}
453 \constfunc{bool
}{Eq
}{\param{wxVariantData\&
}{ data
}}
455 Returns true if this object is equal to
{\it data
}.
457 \membersection{wxVariantData::GetType
}\label{wxvariantdatagettype
}
459 \constfunc{wxString
}{GetType
}{\void}
461 Returns the string type of the data.
463 \membersection{wxVariantData::GetValueClassInfo
}\label{wxvariantdatagetvalueclassinfo
}
465 \constfunc{wxClassInfo*
}{GetValueClassInfo
}{\void}
467 If the data is a wxObject returns a pointer to the objects wxClassInfo structure, if
468 the data isn't a wxObject the method returns NULL.
470 \membersection{wxVariantData::Read
}\label{wxvariantdataread
}
472 \func{bool
}{Read
}{\param{ostream\&
}{ stream
}}
474 \func{bool
}{Read
}{\param{wxString\&
}{ string
}}
476 Reads the data from
{\it stream
} or
{\it string
}.
478 \membersection{wxVariantData::Write
}\label{wxvariantdatawrite
}
480 \constfunc{bool
}{Write
}{\param{ostream\&
}{ stream
}}
482 \constfunc{bool
}{Write
}{\param{wxString\&
}{ string
}}
484 Writes the data to
{\it stream
} or
{\it string
}.
487 \membersection{wxGetVariantCast
}\label{wxgetvariantcast
}
489 \func{classname *
}{wxGetVariantCast
}{wxVariant\&, classname
}
491 This macro returns the data stored in
{\it variant
} cast to the type
{\it classname *
} if
492 the data is of this type (the check is done during the run-time) or
493 {\tt NULL
} otherwise.
498 \helpref{RTTI overview
}{runtimeclassoverview
}\\
499 \helpref{wxDynamicCast
}{wxdynamiccast
}