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
8 wxVariant's capabilities by deriving from the class
\helpref{wxVariantData
}{wxvariantdata
} and
9 using the wxVariantData form of the wxVariant constructor or assignment operator
10 to assign this data to a variant. Actual values for user-defined types will need to be accessed
11 via the wxVariantData object, unlike the case for basic data types where convenience
12 functions such as GetLong can be used.
14 This class is useful for reducing the programming for certain tasks, such as an editor
15 for different data types, or a remote procedure call protocol.
17 An optional name member is associated with a wxVariant. This might be used, for example, in CORBA
18 or OLE automation classes, where named parameters are required.
20 wxVariant is similar to wxExpr and also to wxPropertyValue. However, wxExpr is efficiency-optimized for
21 a restricted range of data types, whereas wxVariant is less efficient but more extensible.
22 wxPropertyValue may be replaced by wxVariant eventually.
24 \wxheading{Derived from
}
26 \helpref{wxObject
}{wxobject
}
28 \wxheading{Include files
}
34 \helpref{wxVariantData
}{wxvariantdata
}
36 \latexignore{\rtfignore{\wxheading{Members
}}}
38 \membersection{wxVariant::wxVariant
}\label{wxvariantctor
}
40 \func{}{wxVariant
}{\void}
44 \func{}{wxVariant
}{\param{const wxVariant\&
}{variant
}}
48 \func{}{wxVariant
}{\param{const char*
}{ value
},
\param{const wxString\&
}{name = ``"
}}
50 \func{}{wxVariant
}{\param{const wxString\&
}{ value
},
\param{const wxString\&
}{name = ``"
}}
52 Construction from a string value.
54 \func{}{wxVariant
}{\param{char
}{ value
},
\param{const wxString\&
}{name = ``"
}}
56 Construction from a character value.
58 \func{}{wxVariant
}{\param{long
}{ value
},
\param{const wxString\&
}{name = ``"
}}
60 Construction from an integer value. You may need to cast to (long) to
61 avoid confusion with other constructors (such as the bool constructor).
63 \func{}{wxVariant
}{\param{bool
}{ value
},
\param{const wxString\&
}{name = ``"
}}
65 Construction from a boolean value.
67 \func{}{wxVariant
}{\param{double
}{ value
},
\param{const wxString\&
}{name = ``"
}}
69 Construction from a double-precision floating point value.
71 \func{}{wxVariant
}{\param{const wxList\&
}{ value
},
\param{const wxString\&
}{name = ``"
}}
73 Construction from a list of wxVariant objects. This constructor
74 copies
{\it value
}, the application is still responsible for
75 deleting
{\it value
} and its contents.
77 \func{}{wxVariant
}{\param{const wxStringList\&
}{ value
},
\param{const wxString\&
}{name = ``"
}}
79 Construction from a list of strings. This constructor
80 copies
{\it value
}, the application is still responsible for
81 deleting
{\it value
} and its contents.
83 \func{}{wxVariant
}{\param{void*
}{ value
},
\param{const wxString\&
}{name = ``"
}}
85 Construction from a void pointer.
87 \func{}{wxVariant
}{\param{wxObject*
}{ value
},
\param{const wxString\&
}{name = ``"
}}
89 Construction from a wxObject pointer.
91 \func{}{wxVariant
}{\param{wxVariantData*
}{ data
},
\param{const wxString\&
}{name = ``"
}}
93 Construction from user-defined data. The variant holds on to the
{\it data
} pointer.
95 \membersection{wxVariant::
\destruct{wxVariant
}}\label{wxvariantdtor
}
97 \func{}{\destruct{wxVariant
}}{\void}
101 \membersection{wxVariant::Append
}\label{wxvariantappend
}
103 \func{void
}{Append
}{\param{const wxVariant\&
}{ value
}}
105 Appends a value to the list.
107 \membersection{wxVariant::ClearList
}\label{wxvariantclearlist
}
109 \func{void
}{ClearList
}{\void}
111 Deletes the contents of the list.
113 \membersection{wxVariant::GetCount
}\label{wxvariantgetcount
}
115 \constfunc{int
}{GetCount
}{\void}
117 Returns the number of elements in the list.
119 \membersection{wxVariant::Delete
}\label{wxvariantdelete
}
121 \func{bool
}{Delete
}{\param{int
}{item
}}
123 Deletes the zero-based
{\it item
} from the list.
125 \membersection{wxVariant::GetBool
}\label{wxvariantgetbool
}
127 \constfunc{bool
}{GetBool
}{\void}
129 Returns the boolean value.
131 \membersection{wxVariant::GetChar
}\label{wxvariantgetchar
}
133 \constfunc{char
}{GetChar
}{\void}
135 Returns the character value.
137 \membersection{wxVariant::GetData
}\label{wxvariantgetdata
}
139 \constfunc{wxVariantData*
}{GetData
}{\void}
141 Returns a pointer to the internal variant data.
143 \membersection{wxVariant::GetDouble
}\label{wxvariantgetdouble
}
145 \constfunc{double
}{GetDouble
}{\void}
147 Returns the floating point value.
149 \membersection{wxVariant::GetLong
}\label{wxvariantgetlong
}
151 \constfunc{long
}{GetLong
}{\void}
153 Returns the integer value.
155 \membersection{wxVariant::GetName
}\label{wxvariantgetname
}
157 \constfunc{const wxString\&
}{GetName
}{\void}
159 Returns a constant reference to the variant name.
161 \membersection{wxVariant::GetString
}\label{wxvariantgetstring
}
163 \constfunc{wxString
}{GetString
}{\void}
165 Gets the string value.
167 \membersection{wxVariant::GetType
}\label{wxvariantgettype
}
169 \constfunc{wxString
}{GetType
}{\void}
171 Returns the value type as a string. The built-in types are: bool, char, date, double, list, long, string, stringlist, time, void*.
173 If the variant is null, the value type returned is the string ``null" (not the empty string).
175 \membersection{wxVariant::GetVoidPtr
}\label{wxvariantgetvoidptr
}
177 \constfunc{void*
}{GetVoidPtr
}{\void}
179 Gets the void pointer value.
181 \membersection{wxVariant::GetWxObjectPtr
}\label{wxvariantgetwxobjectptr
}
183 \constfunc{void*
}{GetWxObjectPtr
}{\void}
185 Gets the wxObject pointer value.
187 \membersection{wxVariant::Insert
}\label{wxvariantinsert
}
189 \func{void
}{Insert
}{\param{const wxVariant\&
}{ value
}}
191 Inserts a value at the front of the list.
193 \membersection{wxVariant::IsNull
}\label{wxvariantisnull
}
195 \constfunc{bool
}{IsNull
}{\void}
197 Returns true if there is no data associated with this variant, false if there is data.
199 \membersection{wxVariant::IsType
}\label{wxvariantistype
}
201 \constfunc{bool
}{IsType
}{\param{const wxString\&
}{ type
}}
203 Returns true if
{\it type
} matches the type of the variant, false otherwise.
205 \membersection{wxVariant::IsValueKindOf
}\label{wxvariantisvaluekindof
}
207 \constfunc{bool
}{IsValueKindOf
}{\param{const wxClassInfo* type
}{ type
}}
209 Returns true if the data is derived from the class described by
{\it type
}, false otherwise.
211 \membersection{wxVariant::MakeNull
}\label{wxvariantmakenull
}
213 \func{void
}{MakeNull
}{\void}
215 Makes the variant null by deleting the internal data.
217 \membersection{wxVariant::MakeString
}\label{wxvariantmakestring
}
219 \constfunc{wxString
}{MakeString
}{\void}
221 Makes a string representation of the variant value (for any type).
223 \membersection{wxVariant::Member
}\label{wxvariantmember
}
225 \constfunc{bool
}{Member
}{\param{const wxVariant\&
}{ value
}}
227 Returns true if
{\it value
} matches an element in the list.
229 \membersection{wxVariant::NullList
}\label{wxvariantnulllist
}
231 \func{void
}{NullList
}{\void}
233 Makes an empty list. This differs from a null variant which has no data; a null list
234 is of type list, but the number of elements in the list is zero.
236 \membersection{wxVariant::SetData
}\label{wxvariantsetdata
}
238 \func{void
}{SetData
}{\param{wxVariantData*
}{ data
}}
240 Sets the internal variant data, deleting the existing data if there is any.
242 \membersection{wxVariant::operator $=$
}\label{wxvariantassignment
}
244 \func{void
}{operator $=$
}{\param{const wxVariant\&
}{value
}}
246 \func{void
}{operator $=$
}{\param{wxVariantData*
}{value
}}
248 \func{void
}{operator $=$
}{\param{const wxString\&
}{value
}}
250 \func{void
}{operator $=$
}{\param{const char*
}{value
}}
252 \func{void
}{operator $=$
}{\param{char
}{value
}}
254 \func{void
}{operator $=$
}{\param{const long
}{value
}}
256 \func{void
}{operator $=$
}{\param{const bool
}{value
}}
258 \func{void
}{operator $=$
}{\param{const double
}{value
}}
260 \func{void
}{operator $=$
}{\param{void*
}{value
}}
262 \func{void
}{operator $=$
}{\param{const wxList\&
}{value
}}
264 \func{void
}{operator $=$
}{\param{const wxStringList\&
}{value
}}
266 Assignment operators.
268 \membersection{wxVariant::operator $==$
}\label{wxvarianteq
}
270 \func{bool
}{operator $==$
}{\param{const wxVariant\&
}{value
}}
272 \func{bool
}{operator $==$
}{\param{const wxString\&
}{value
}}
274 \func{bool
}{operator $==$
}{\param{const char*
}{value
}}
276 \func{bool
}{operator $==$
}{\param{char
}{value
}}
278 \func{bool
}{operator $==$
}{\param{const long
}{value
}}
280 \func{bool
}{operator $==$
}{\param{const bool
}{value
}}
282 \func{bool
}{operator $==$
}{\param{const double
}{value
}}
284 \func{bool
}{operator $==$
}{\param{void*
}{value
}}
286 \func{bool
}{operator $==$
}{\param{const wxList\&
}{value
}}
288 \func{bool
}{operator $==$
}{\param{const wxStringList\&
}{value
}}
290 Equality test operators.
292 \membersection{wxVariant::operator $!=$
}\label{wxvariantneq
}
294 \func{bool
}{operator $!=$
}{\param{const wxVariant\&
}{value
}}
296 \func{bool
}{operator $!=$
}{\param{const wxString\&
}{value
}}
298 \func{bool
}{operator $!=$
}{\param{const char*
}{value
}}
300 \func{bool
}{operator $!=$
}{\param{char
}{value
}}
302 \func{bool
}{operator $!=$
}{\param{const long
}{value
}}
304 \func{bool
}{operator $!=$
}{\param{const bool
}{value
}}
306 \func{bool
}{operator $!=$
}{\param{const double
}{value
}}
308 \func{bool
}{operator $!=$
}{\param{void*
}{value
}}
310 \func{bool
}{operator $!=$
}{\param{const wxList\&
}{value
}}
312 \func{bool
}{operator $!=$
}{\param{const wxStringList\&
}{value
}}
314 Inequality test operators.
316 \membersection{wxVariant::operator $
[]$
}\label{wxvariantarray
}
318 \constfunc{wxVariant
}{operator $
[]$
}{\param{size
\_t }{idx
}}
320 Returns the value at
{\it idx
} (zero-based).
322 \func{wxVariant\&
}{operator $
[]$
}{\param{size
\_t }{idx
}}
324 Returns a reference to the value at
{\it idx
} (zero-based). This can be used
325 to change the value at this index.
327 \membersection{wxVariant::operator char
}\label{wxvariantchar
}
329 \constfunc{char
}{operator char
}{\void}
331 Operator for implicit conversion to a char, using
\helpref{wxVariant::GetChar
}{wxvariantgetchar
}.
333 \membersection{wxVariant::operator double
}\label{wxvariantdouble
}
335 \constfunc{double
}{operator double
}{\void}
337 Operator for implicit conversion to a double, using
\helpref{wxVariant::GetDouble
}{wxvariantgetdouble
}.
339 \constfunc{long
}{operator long
}{\void}
341 Operator for implicit conversion to a long, using
\helpref{wxVariant::GetLong
}{wxvariantgetlong
}.
343 \membersection{wxVariant::operator wxString
}\label{wxvariantwxstring
}
345 \constfunc{wxString
}{operator wxString
}{\void}
347 Operator for implicit conversion to a string, using
\helpref{wxVariant::MakeString
}{wxvariantmakestring
}.
349 \membersection{wxVariant::operator void*
}\label{wxvariantvoid
}
351 \constfunc{void*
}{operator void*
}{\void}
353 Operator for implicit conversion to a pointer to a void, using
\helpref{wxVariant::GetVoidPtr
}{wxvariantgetvoidptr
}.
355 \section{\class{wxVariantData
}}\label{wxvariantdata
}
357 The
{\bf wxVariantData
} is used to implement a new type for wxVariant. Derive from wxVariantData,
358 and override the pure virtual functions.
360 \wxheading{Derived from
}
362 \helpref{wxObject
}{wxobject
}
364 \wxheading{Include files
}
370 \helpref{wxVariant
}{wxvariant
}
372 \latexignore{\rtfignore{\wxheading{Members
}}}
374 \membersection{wxVariantData::wxVariantData
}\label{wxvariantdatactor
}
376 \func{}{wxVariantData
}{\void}
380 \membersection{wxVariantData::Copy
}\label{wxvariantdatacopy
}
382 \func{void
}{Copy
}{\param{wxVariantData\&
}{ data
}}
384 Copy the data from `this' object to
{\it data
}.
386 \membersection{wxVariantData::Eq
}\label{wxvariantdataeq
}
388 \constfunc{bool
}{Eq
}{\param{wxVariantData\&
}{ data
}}
390 Returns true if this object is equal to
{\it data
}.
392 \membersection{wxVariantData::GetType
}\label{wxvariantdatagettype
}
394 \constfunc{wxString
}{GetType
}{\void}
396 Returns the string type of the data.
398 \membersection{wxVariantData::GetValueClassInfo
}\label{wxvariantdatagetvalueclassinfo
}
400 \constfunc{wxClassInfo*
}{GetValueClassInfo
}{\void}
402 If the data is a wxObject returns a pointer to the objects wxClassInfo structure, if
403 the data isn't a wxObject the method returns NULL.
405 \membersection{wxVariantData::Read
}\label{wxvariantdataread
}
407 \func{bool
}{Read
}{\param{ostream\&
}{ stream
}}
409 \func{bool
}{Read
}{\param{wxString\&
}{ string
}}
411 Reads the data from
{\it stream
} or
{\it string
}.
413 \membersection{wxVariantData::Write
}\label{wxvariantdatawrite
}
415 \constfunc{bool
}{Write
}{\param{ostream\&
}{ stream
}}
417 \constfunc{bool
}{Write
}{\param{wxString\&
}{ string
}}
419 Writes the data to
{\it stream
} or
{\it string
}.
422 \membersection{wxGetVariantCast
}\label{wxgetvariantcast
}
424 \func{classname *
}{wxGetVariantCast
}{wxVariant\&, classname
}
426 This macro returns the data stored in
{\it variant
} cast to the type
{\it classname *
} if
427 the data is of this type (the check is done during the run-time) or
428 {\tt NULL
} otherwise.
433 \helpref{RTTI overview
}{runtimeclassoverview
}\\
434 \helpref{wxDynamicCast
}{wxdynamiccast
}\\