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 %Note: this constructor is currently disabled because it causes a C++ ambiguity.
85 \func{}{wxVariant
}{\param{void*
}{ value
},
\param{const wxString\&
}{name = ``"
}}
87 Construction from a void pointer.
89 \func{}{wxVariant
}{\param{wxVariantData*
}{ data
},
\param{const wxString\&
}{name = ``"
}}
91 Construction from user-defined data. The variant holds on to the
{\it data
} pointer.
93 \membersection{wxVariant::
\destruct{wxVariant
}}\label{wxvariantdtor
}
95 \func{}{\destruct{wxVariant
}}{\void}
99 \membersection{wxVariant::Append
}\label{wxvariantappend
}
101 \func{void
}{Append
}{\param{const wxVariant\&
}{ value
}}
103 Appends a value to the list.
105 \membersection{wxVariant::ClearList
}\label{wxvariantclearlist
}
107 \func{void
}{ClearList
}{\void}
109 Deletes the contents of the list.
111 \membersection{wxVariant::GetCount
}\label{wxvariantgetcount
}
113 \constfunc{int
}{GetCount
}{\void}
115 Returns the number of elements in the list.
117 \membersection{wxVariant::Delete
}\label{wxvariantdelete
}
119 \func{bool
}{Delete
}{\param{int
}{item
}}
121 Deletes the zero-based
{\it item
} from the list.
123 \membersection{wxVariant::GetBool
}\label{wxvariantgetbool
}
125 \constfunc{bool
}{GetBool
}{\void}
127 Returns the boolean value.
129 \membersection{wxVariant::GetChar
}\label{wxvariantgetchar
}
131 \constfunc{char
}{GetChar
}{\void}
133 Returns the character value.
135 \membersection{wxVariant::GetData
}\label{wxvariantgetdata
}
137 \constfunc{wxVariantData*
}{GetData
}{\void}
139 Returns a pointer to the internal variant data.
141 \membersection{wxVariant::GetDouble
}\label{wxvariantgetdouble
}
143 \constfunc{double
}{GetDouble
}{\void}
145 Returns the floating point value.
147 \membersection{wxVariant::GetLong
}\label{wxvariantgetlong
}
149 \constfunc{long
}{GetLong
}{\void}
151 Returns the integer value.
153 \membersection{wxVariant::GetName
}\label{wxvariantgetname
}
155 \constfunc{const wxString\&
}{GetName
}{\void}
157 Returns a constant reference to the variant name.
159 \membersection{wxVariant::GetString
}\label{wxvariantgetstring
}
161 \constfunc{wxString
}{GetString
}{\void}
163 Gets the string value.
165 \membersection{wxVariant::GetType
}\label{wxvariantgettype
}
167 \constfunc{wxString
}{GetType
}{\void}
169 Returns the value type as a string. The built-in types are: bool, char, date, double, list, long, string, stringlist, time, void*.
171 If the variant is null, the value type returned is the string ``null" (not the empty string).
173 \membersection{wxVariant::GetVoidPtr
}\label{wxvariantgetvoidptr
}
175 \constfunc{void*
}{GetVoidPtr
}{\void}
177 Gets the void pointer value.
179 \membersection{wxVariant::Insert
}\label{wxvariantinsert
}
181 \func{void
}{Insert
}{\param{const wxVariant\&
}{ value
}}
183 Inserts a value at the front of the list.
185 \membersection{wxVariant::IsNull
}\label{wxvariantisnull
}
187 \constfunc{bool
}{IsNull
}{\void}
189 Returns true if there is no data associated with this variant, false if there is data.
191 \membersection{wxVariant::IsType
}\label{wxvariantistype
}
193 \constfunc{bool
}{IsType
}{\param{const wxString\&
}{ type
}}
195 Returns true if
{\it type
} matches the type of the variant, false otherwise.
197 \membersection{wxVariant::MakeNull
}\label{wxvariantmakenull
}
199 \func{void
}{MakeNull
}{\void}
201 Makes the variant null by deleting the internal data.
203 \membersection{wxVariant::MakeString
}\label{wxvariantmakestring
}
205 \constfunc{wxString
}{MakeString
}{\void}
207 Makes a string representation of the variant value (for any type).
209 \membersection{wxVariant::Member
}\label{wxvariantmember
}
211 \constfunc{bool
}{Member
}{\param{const wxVariant\&
}{ value
}}
213 Returns true if
{\it value
} matches an element in the list.
215 \membersection{wxVariant::NullList
}\label{wxvariantnulllist
}
217 \func{void
}{NullList
}{\void}
219 Makes an empty list. This differs from a null variant which has no data; a null list
220 is of type list, but the number of elements in the list is zero.
222 \membersection{wxVariant::SetData
}\label{wxvariantsetdata
}
224 \func{void
}{SetData
}{\param{wxVariantData*
}{ data
}}
226 Sets the internal variant data, deleting the existing data if there is any.
228 \membersection{wxVariant::operator $=$
}\label{wxvariantassignment
}
230 \func{void
}{operator $=$
}{\param{const wxVariant\&
}{value
}}
232 \func{void
}{operator $=$
}{\param{wxVariantData*
}{value
}}
234 \func{void
}{operator $=$
}{\param{const wxString\&
}{value
}}
236 \func{void
}{operator $=$
}{\param{const char*
}{value
}}
238 \func{void
}{operator $=$
}{\param{char
}{value
}}
240 \func{void
}{operator $=$
}{\param{const long
}{value
}}
242 \func{void
}{operator $=$
}{\param{const bool
}{value
}}
244 \func{void
}{operator $=$
}{\param{const double
}{value
}}
246 \func{void
}{operator $=$
}{\param{void*
}{value
}}
248 \func{void
}{operator $=$
}{\param{const wxList\&
}{value
}}
250 \func{void
}{operator $=$
}{\param{const wxStringList\&
}{value
}}
252 Assignment operators.
254 \membersection{wxVariant::operator $==$
}\label{wxvarianteq
}
256 \func{bool
}{operator $==$
}{\param{const wxVariant\&
}{value
}}
258 \func{bool
}{operator $==$
}{\param{const wxString\&
}{value
}}
260 \func{bool
}{operator $==$
}{\param{const char*
}{value
}}
262 \func{bool
}{operator $==$
}{\param{char
}{value
}}
264 \func{bool
}{operator $==$
}{\param{const long
}{value
}}
266 \func{bool
}{operator $==$
}{\param{const bool
}{value
}}
268 \func{bool
}{operator $==$
}{\param{const double
}{value
}}
270 \func{bool
}{operator $==$
}{\param{void*
}{value
}}
272 \func{bool
}{operator $==$
}{\param{const wxList\&
}{value
}}
274 \func{bool
}{operator $==$
}{\param{const wxStringList\&
}{value
}}
276 Equality test operators.
278 \membersection{wxVariant::operator $!=$
}\label{wxvariantneq
}
280 \func{bool
}{operator $!=$
}{\param{const wxVariant\&
}{value
}}
282 \func{bool
}{operator $!=$
}{\param{const wxString\&
}{value
}}
284 \func{bool
}{operator $!=$
}{\param{const char*
}{value
}}
286 \func{bool
}{operator $!=$
}{\param{char
}{value
}}
288 \func{bool
}{operator $!=$
}{\param{const long
}{value
}}
290 \func{bool
}{operator $!=$
}{\param{const bool
}{value
}}
292 \func{bool
}{operator $!=$
}{\param{const double
}{value
}}
294 \func{bool
}{operator $!=$
}{\param{void*
}{value
}}
296 \func{bool
}{operator $!=$
}{\param{const wxList\&
}{value
}}
298 \func{bool
}{operator $!=$
}{\param{const wxStringList\&
}{value
}}
300 Inequality test operators.
302 \membersection{wxVariant::operator $
[]$
}\label{wxvariantarray
}
304 \constfunc{wxVariant
}{operator $
[]$
}{\param{size
\_t }{idx
}}
306 Returns the value at
{\it idx
} (zero-based).
308 \func{wxVariant\&
}{operator $
[]$
}{\param{size
\_t }{idx
}}
310 Returns a reference to the value at
{\it idx
} (zero-based). This can be used
311 to change the value at this index.
313 \membersection{wxVariant::operator char
}\label{wxvariantchar
}
315 \constfunc{char
}{operator char
}{\void}
317 Operator for implicit conversion to a char, using
\helpref{wxVariant::GetChar
}{wxvariantgetchar
}.
319 \membersection{wxVariant::operator double
}\label{wxvariantdouble
}
321 \constfunc{double
}{operator double
}{\void}
323 Operator for implicit conversion to a double, using
\helpref{wxVariant::GetDouble
}{wxvariantgetdouble
}.
325 \constfunc{long
}{operator long
}{\void}
327 Operator for implicit conversion to a long, using
\helpref{wxVariant::GetLong
}{wxvariantgetlong
}.
329 \membersection{wxVariant::operator wxString
}\label{wxvariantwxstring
}
331 \constfunc{wxString
}{operator wxString
}{\void}
333 Operator for implicit conversion to a string, using
\helpref{wxVariant::MakeString
}{wxvariantmakestring
}.
335 \membersection{wxVariant::operator void*
}\label{wxvariantvoid
}
337 \constfunc{void*
}{operator void*
}{\void}
339 Operator for implicit conversion to a pointer to a void, using
\helpref{wxVariant::GetVoidPtr
}{wxvariantgetvoidptr
}.
341 \section{\class{wxVariantData
}}\label{wxvariantdata
}
343 The
{\bf wxVariantData
} is used to implement a new type for wxVariant. Derive from wxVariantData,
344 and override the pure virtual functions.
346 \wxheading{Derived from
}
348 \helpref{wxObject
}{wxobject
}
350 \wxheading{Include files
}
356 \helpref{wxVariant
}{wxvariant
}
358 \latexignore{\rtfignore{\wxheading{Members
}}}
360 \membersection{wxVariantData::wxVariantData
}\label{wxvariantdatactor
}
362 \func{}{wxVariantData
}{\void}
366 \membersection{wxVariantData::Copy
}\label{wxvariantdatacopy
}
368 \func{void
}{Copy
}{\param{wxVariantData\&
}{ data
}}
370 Copy the data from `this' object to
{\it data
}.
372 \membersection{wxVariantData::Eq
}\label{wxvariantdataeq
}
374 \constfunc{bool
}{Eq
}{\param{wxVariantData\&
}{ data
}}
376 Returns true if this object is equal to
{\it data
}.
378 \membersection{wxVariantData::GetType
}\label{wxvariantdatagettype
}
380 \constfunc{wxString
}{GetType
}{\void}
382 Returns the string type of the data.
384 \membersection{wxVariantData::Read
}\label{wxvariantdataread
}
386 \func{bool
}{Read
}{\param{ostream\&
}{ stream
}}
388 \func{bool
}{Read
}{\param{wxString\&
}{ string
}}
390 Reads the data from
{\it stream
} or
{\it string
}.
392 \membersection{wxVariantData::Write
}\label{wxvariantdatawrite
}
394 \constfunc{bool
}{Write
}{\param{ostream\&
}{ stream
}}
396 \constfunc{bool
}{Write
}{\param{wxString\&
}{ string
}}
398 Writes the data to
{\it stream
} or
{\it string
}.