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 \wxheading{Derived from
}
22 \helpref{wxObject
}{wxobject
}
24 \wxheading{Include files
}
30 \helpref{wxVariantData
}{wxvariantdata
}
32 \latexignore{\rtfignore{\wxheading{Members
}}}
34 \membersection{wxVariant::wxVariant
}\label{wxvariantctor
}
36 \func{}{wxVariant
}{\void}
40 \func{}{wxVariant
}{\param{const wxVariant\&
}{variant
}}
44 \func{}{wxVariant
}{\param{const char*
}{ value
},
\param{const wxString\&
}{name = ``"
}}
46 \func{}{wxVariant
}{\param{const wxString\&
}{ value
},
\param{const wxString\&
}{name = ``"
}}
48 Construction from a string value.
50 \func{}{wxVariant
}{\param{char
}{ value
},
\param{const wxString\&
}{name = ``"
}}
52 Construction from a character value.
54 \func{}{wxVariant
}{\param{long
}{ value
},
\param{const wxString\&
}{name = ``"
}}
56 Construction from an integer value. You may need to cast to (long) to
57 avoid confusion with other constructors (such as the bool constructor).
59 \func{}{wxVariant
}{\param{bool
}{ value
},
\param{const wxString\&
}{name = ``"
}}
61 Construction from a boolean value.
63 \func{}{wxVariant
}{\param{double
}{ value
},
\param{const wxString\&
}{name = ``"
}}
65 Construction from a double-precision floating point value.
67 \func{}{wxVariant
}{\param{const wxList\&
}{ value
},
\param{const wxString\&
}{name = ``"
}}
69 Construction from a list of wxVariant objects. This constructor
70 copies
{\it value
}, the application is still responsible for
71 deleting
{\it value
} and its contents.
73 \func{}{wxVariant
}{\param{const wxStringList\&
}{ value
},
\param{const wxString\&
}{name = ``"
}}
75 Construction from a list of strings. 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 on to the
{\it data
} pointer.
91 \membersection{wxVariant::
\destruct{wxVariant
}}\label{wxvariantdtor
}
93 \func{}{\destruct{wxVariant
}}{\void}
97 \membersection{wxVariant::Append
}\label{wxvariantappend
}
99 \func{void
}{Append
}{\param{const wxVariant\&
}{ value
}}
101 Appends a value to the list.
103 \membersection{wxVariant::ClearList
}\label{wxvariantclearlist
}
105 \func{void
}{ClearList
}{\void}
107 Deletes the contents of the list.
109 \membersection{wxVariant::GetCount
}\label{wxvariantgetcount
}
111 \constfunc{int
}{GetCount
}{\void}
113 Returns the number of elements in the list.
115 \membersection{wxVariant::Delete
}\label{wxvariantdelete
}
117 \func{bool
}{Delete
}{\param{int
}{item
}}
119 Deletes the zero-based
{\it item
} from the list.
121 \membersection{wxVariant::GetBool
}\label{wxvariantgetbool
}
123 \constfunc{bool
}{GetBool
}{\void}
125 Returns the boolean value.
127 \membersection{wxVariant::GetChar
}\label{wxvariantgetchar
}
129 \constfunc{char
}{GetChar
}{\void}
131 Returns the character value.
133 \membersection{wxVariant::GetData
}\label{wxvariantgetdata
}
135 \constfunc{wxVariantData*
}{GetData
}{\void}
137 Returns a pointer to the internal variant data.
139 \membersection{wxVariant::GetDouble
}\label{wxvariantgetdouble
}
141 \constfunc{double
}{GetDouble
}{\void}
143 Returns the floating point value.
145 \membersection{wxVariant::GetLong
}\label{wxvariantgetlong
}
147 \constfunc{long
}{GetLong
}{\void}
149 Returns the integer value.
151 \membersection{wxVariant::GetName
}\label{wxvariantgetname
}
153 \constfunc{const wxString\&
}{GetName
}{\void}
155 Returns a constant reference to the variant name.
157 \membersection{wxVariant::GetString
}\label{wxvariantgetstring
}
159 \constfunc{wxString
}{GetString
}{\void}
161 Gets the string value.
163 \membersection{wxVariant::GetType
}\label{wxvariantgettype
}
165 \constfunc{wxString
}{GetType
}{\void}
167 Returns the value type as a string. The built-in types are: bool, char, date, double, list, long, string, stringlist, time, void*.
169 If the variant is null, the value type returned is the string ``null" (not the empty string).
171 \membersection{wxVariant::GetVoidPtr
}\label{wxvariantgetvoidptr
}
173 \constfunc{void*
}{GetVoidPtr
}{\void}
175 Gets the void pointer value.
177 \membersection{wxVariant::GetWxObjectPtr
}\label{wxvariantgetwxobjectptr
}
179 \constfunc{void*
}{GetWxObjectPtr
}{\void}
181 Gets the wxObject pointer value.
183 \membersection{wxVariant::Insert
}\label{wxvariantinsert
}
185 \func{void
}{Insert
}{\param{const wxVariant\&
}{ value
}}
187 Inserts a value at the front of the list.
189 \membersection{wxVariant::IsNull
}\label{wxvariantisnull
}
191 \constfunc{bool
}{IsNull
}{\void}
193 Returns true if there is no data associated with this variant, false if there is data.
195 \membersection{wxVariant::IsType
}\label{wxvariantistype
}
197 \constfunc{bool
}{IsType
}{\param{const wxString\&
}{ type
}}
199 Returns true if
{\it type
} matches the type of the variant, false otherwise.
201 \membersection{wxVariant::IsValueKindOf
}\label{wxvariantisvaluekindof
}
203 \constfunc{bool
}{IsValueKindOf
}{\param{const wxClassInfo* type
}{ type
}}
205 Returns true if the data is derived from the class described by
{\it type
}, false otherwise.
207 \membersection{wxVariant::MakeNull
}\label{wxvariantmakenull
}
209 \func{void
}{MakeNull
}{\void}
211 Makes the variant null by deleting the internal data.
213 \membersection{wxVariant::MakeString
}\label{wxvariantmakestring
}
215 \constfunc{wxString
}{MakeString
}{\void}
217 Makes a string representation of the variant value (for any type).
219 \membersection{wxVariant::Member
}\label{wxvariantmember
}
221 \constfunc{bool
}{Member
}{\param{const wxVariant\&
}{ value
}}
223 Returns true if
{\it value
} matches an element in the list.
225 \membersection{wxVariant::NullList
}\label{wxvariantnulllist
}
227 \func{void
}{NullList
}{\void}
229 Makes an empty list. This differs from a null variant which has no data; a null list
230 is of type list, but the number of elements in the list is zero.
232 \membersection{wxVariant::SetData
}\label{wxvariantsetdata
}
234 \func{void
}{SetData
}{\param{wxVariantData*
}{ data
}}
236 Sets the internal variant data, deleting the existing data if there is any.
238 \membersection{wxVariant::operator $=$
}\label{wxvariantassignment
}
240 \func{void
}{operator $=$
}{\param{const wxVariant\&
}{value
}}
242 \func{void
}{operator $=$
}{\param{wxVariantData*
}{value
}}
244 \func{void
}{operator $=$
}{\param{const wxString\&
}{value
}}
246 \func{void
}{operator $=$
}{\param{const char*
}{value
}}
248 \func{void
}{operator $=$
}{\param{char
}{value
}}
250 \func{void
}{operator $=$
}{\param{const long
}{value
}}
252 \func{void
}{operator $=$
}{\param{const bool
}{value
}}
254 \func{void
}{operator $=$
}{\param{const double
}{value
}}
256 \func{void
}{operator $=$
}{\param{void*
}{value
}}
258 \func{void
}{operator $=$
}{\param{const wxList\&
}{value
}}
260 \func{void
}{operator $=$
}{\param{const wxStringList\&
}{value
}}
262 Assignment operators.
264 \membersection{wxVariant::operator $==$
}\label{wxvarianteq
}
266 \func{bool
}{operator $==$
}{\param{const wxVariant\&
}{value
}}
268 \func{bool
}{operator $==$
}{\param{const wxString\&
}{value
}}
270 \func{bool
}{operator $==$
}{\param{const char*
}{value
}}
272 \func{bool
}{operator $==$
}{\param{char
}{value
}}
274 \func{bool
}{operator $==$
}{\param{const long
}{value
}}
276 \func{bool
}{operator $==$
}{\param{const bool
}{value
}}
278 \func{bool
}{operator $==$
}{\param{const double
}{value
}}
280 \func{bool
}{operator $==$
}{\param{void*
}{value
}}
282 \func{bool
}{operator $==$
}{\param{const wxList\&
}{value
}}
284 \func{bool
}{operator $==$
}{\param{const wxStringList\&
}{value
}}
286 Equality test operators.
288 \membersection{wxVariant::operator $!=$
}\label{wxvariantneq
}
290 \func{bool
}{operator $!=$
}{\param{const wxVariant\&
}{value
}}
292 \func{bool
}{operator $!=$
}{\param{const wxString\&
}{value
}}
294 \func{bool
}{operator $!=$
}{\param{const char*
}{value
}}
296 \func{bool
}{operator $!=$
}{\param{char
}{value
}}
298 \func{bool
}{operator $!=$
}{\param{const long
}{value
}}
300 \func{bool
}{operator $!=$
}{\param{const bool
}{value
}}
302 \func{bool
}{operator $!=$
}{\param{const double
}{value
}}
304 \func{bool
}{operator $!=$
}{\param{void*
}{value
}}
306 \func{bool
}{operator $!=$
}{\param{const wxList\&
}{value
}}
308 \func{bool
}{operator $!=$
}{\param{const wxStringList\&
}{value
}}
310 Inequality test operators.
312 \membersection{wxVariant::operator $
[]$
}\label{wxvariantarray
}
314 \constfunc{wxVariant
}{operator $
[]$
}{\param{size
\_t }{idx
}}
316 Returns the value at
{\it idx
} (zero-based).
318 \func{wxVariant\&
}{operator $
[]$
}{\param{size
\_t }{idx
}}
320 Returns a reference to the value at
{\it idx
} (zero-based). This can be used
321 to change the value at this index.
323 \membersection{wxVariant::operator char
}\label{wxvariantchar
}
325 \constfunc{char
}{operator char
}{\void}
327 Operator for implicit conversion to a char, using
\helpref{wxVariant::GetChar
}{wxvariantgetchar
}.
329 \membersection{wxVariant::operator double
}\label{wxvariantdouble
}
331 \constfunc{double
}{operator double
}{\void}
333 Operator for implicit conversion to a double, using
\helpref{wxVariant::GetDouble
}{wxvariantgetdouble
}.
335 \constfunc{long
}{operator long
}{\void}
337 Operator for implicit conversion to a long, using
\helpref{wxVariant::GetLong
}{wxvariantgetlong
}.
339 \membersection{wxVariant::operator wxString
}\label{wxvariantwxstring
}
341 \constfunc{wxString
}{operator wxString
}{\void}
343 Operator for implicit conversion to a string, using
\helpref{wxVariant::MakeString
}{wxvariantmakestring
}.
345 \membersection{wxVariant::operator void*
}\label{wxvariantvoid
}
347 \constfunc{void*
}{operator void*
}{\void}
349 Operator for implicit conversion to a pointer to a void, using
\helpref{wxVariant::GetVoidPtr
}{wxvariantgetvoidptr
}.
351 \section{\class{wxVariantData
}}\label{wxvariantdata
}
353 The
{\bf wxVariantData
} is used to implement a new type for wxVariant. Derive from wxVariantData,
354 and override the pure virtual functions.
356 \wxheading{Derived from
}
358 \helpref{wxObject
}{wxobject
}
360 \wxheading{Include files
}
366 \helpref{wxVariant
}{wxvariant
}
368 \latexignore{\rtfignore{\wxheading{Members
}}}
370 \membersection{wxVariantData::wxVariantData
}\label{wxvariantdatactor
}
372 \func{}{wxVariantData
}{\void}
376 \membersection{wxVariantData::Copy
}\label{wxvariantdatacopy
}
378 \func{void
}{Copy
}{\param{wxVariantData\&
}{ data
}}
380 Copy the data from `this' object to
{\it data
}.
382 \membersection{wxVariantData::Eq
}\label{wxvariantdataeq
}
384 \constfunc{bool
}{Eq
}{\param{wxVariantData\&
}{ data
}}
386 Returns true if this object is equal to
{\it data
}.
388 \membersection{wxVariantData::GetType
}\label{wxvariantdatagettype
}
390 \constfunc{wxString
}{GetType
}{\void}
392 Returns the string type of the data.
394 \membersection{wxVariantData::GetValueClassInfo
}\label{wxvariantdatagetvalueclassinfo
}
396 \constfunc{wxClassInfo*
}{GetValueClassInfo
}{\void}
398 If the data is a wxObject returns a pointer to the objects wxClassInfo structure, if
399 the data isn't a wxObject the method returns NULL.
401 \membersection{wxVariantData::Read
}\label{wxvariantdataread
}
403 \func{bool
}{Read
}{\param{ostream\&
}{ stream
}}
405 \func{bool
}{Read
}{\param{wxString\&
}{ string
}}
407 Reads the data from
{\it stream
} or
{\it string
}.
409 \membersection{wxVariantData::Write
}\label{wxvariantdatawrite
}
411 \constfunc{bool
}{Write
}{\param{ostream\&
}{ stream
}}
413 \constfunc{bool
}{Write
}{\param{wxString\&
}{ string
}}
415 Writes the data to
{\it stream
} or
{\it string
}.
418 \membersection{wxGetVariantCast
}\label{wxgetvariantcast
}
420 \func{classname *
}{wxGetVariantCast
}{wxVariant\&, classname
}
422 This macro returns the data stored in
{\it variant
} cast to the type
{\it classname *
} if
423 the data is of this type (the check is done during the run-time) or
424 {\tt NULL
} otherwise.
429 \helpref{RTTI overview
}{runtimeclassoverview
}\\
430 \helpref{wxDynamicCast
}{wxdynamiccast
}