]>
Commit | Line | Data |
---|---|---|
23324ae1 FM |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: variant.h | |
e54c96f1 | 3 | // Purpose: interface of wxVariant |
23324ae1 FM |
4 | // Author: wxWidgets team |
5 | // RCS-ID: $Id$ | |
526954c5 | 6 | // Licence: wxWindows licence |
23324ae1 FM |
7 | ///////////////////////////////////////////////////////////////////////////// |
8 | ||
9 | /** | |
10 | @class wxVariant | |
7c913512 | 11 | |
09ad05fa | 12 | The wxVariant class represents a container for any type. A variant's value |
c1996262 | 13 | can be changed at run time, possibly to a different type of value. |
7c913512 | 14 | |
0bf14ab8 JS |
15 | @note As of wxWidgets 2.9.1, wxAny has become the preferred variant class. |
16 | While most controls still use wxVariant in their interface, you | |
17 | can start using wxAny in your code because of an implicit conversion | |
18 | layer. See below for more information. | |
19 | ||
23324ae1 | 20 | As standard, wxVariant can store values of type bool, wxChar, double, long, |
09ad05fa BP |
21 | string, string list, time, date, void pointer, list of strings, and list of |
22 | variants. However, an application can extend wxVariant's capabilities by | |
23 | deriving from the class wxVariantData and using the wxVariantData form of | |
24 | the wxVariant constructor or assignment operator to assign this data to a | |
25 | variant. Actual values for user-defined types will need to be accessed via | |
26 | the wxVariantData object, unlike the case for basic data types where | |
27 | convenience functions such as GetLong() can be used. | |
28 | ||
29 | Pointers to any wxObject derived class can also easily be stored in a | |
30 | wxVariant. wxVariant will then use wxWidgets' built-in RTTI system to set | |
31 | the type name (returned by GetType()) and to perform type-safety checks at | |
32 | runtime. | |
33 | ||
34 | This class is useful for reducing the programming for certain tasks, such | |
35 | as an editor for different data types, or a remote procedure call protocol. | |
7c913512 | 36 | |
c1996262 | 37 | An optional name member is associated with a wxVariant. This might be used, |
09ad05fa BP |
38 | for example, in CORBA or OLE automation classes, where named parameters are |
39 | required. | |
7c913512 | 40 | |
09ad05fa BP |
41 | Note that as of wxWidgets 2.7.1, wxVariant is |
42 | @ref overview_refcount "reference counted". Additionally, the convenience | |
43 | macros DECLARE_VARIANT_OBJECT() and IMPLEMENT_VARIANT_OBJECT() were added | |
44 | so that adding (limited) support for conversion to and from wxVariant can | |
45 | be very easily implemented without modifying either wxVariant or the class | |
46 | to be stored by wxVariant. Since assignment operators cannot be declared | |
47 | outside the class, the shift left operators are used like this: | |
7c913512 | 48 | |
23324ae1 FM |
49 | @code |
50 | // in the header file | |
c1996262 | 51 | DECLARE_VARIANT_OBJECT(MyClass) |
7c913512 | 52 | |
c1996262 RR |
53 | // in the implementation file |
54 | IMPLEMENT_VARIANT_OBJECT(MyClass) | |
7c913512 | 55 | |
c1996262 RR |
56 | // in the user code |
57 | wxVariant variant; | |
58 | MyClass value; | |
59 | variant << value; | |
7c913512 | 60 | |
c1996262 RR |
61 | // or |
62 | value << variant; | |
23324ae1 | 63 | @endcode |
7c913512 | 64 | |
09ad05fa BP |
65 | For this to work, MyClass must derive from wxObject, implement the |
66 | @ref overview_rtti "wxWidgets RTTI system" and support the assignment | |
67 | operator and equality operator for itself. Ideally, it should also be | |
68 | reference counted to make copying operations cheap and fast. This can be | |
69 | most easily implemented using the reference counting support offered by | |
70 | wxObject itself. By default, wxWidgets already implements the shift | |
71 | operator conversion for a few of its drawing related classes: | |
7c913512 | 72 | |
23324ae1 FM |
73 | @code |
74 | IMPLEMENT_VARIANT_OBJECT(wxColour) | |
75 | IMPLEMENT_VARIANT_OBJECT(wxImage) | |
76 | IMPLEMENT_VARIANT_OBJECT(wxIcon) | |
77 | IMPLEMENT_VARIANT_OBJECT(wxBitmap) | |
78 | @endcode | |
7c913512 | 79 | |
09ad05fa BP |
80 | Note that as of wxWidgets 2.9.0, wxVariantData no longer inherits from |
81 | wxObject and wxVariant no longer uses the type-unsafe wxList class for list | |
23324ae1 | 82 | operations but the type-safe wxVariantList class. Also, wxVariantData now |
09ad05fa BP |
83 | supports the wxVariantData::Clone() function for implementing the Unshare() |
84 | function. wxVariantData::Clone() is implemented automatically by | |
85 | IMPLEMENT_VARIANT_OBJECT(). | |
7c913512 | 86 | |
09ad05fa BP |
87 | Since wxVariantData no longer derives from wxObject, any code that tests |
88 | the type of the data using wxDynamicCast() will require adjustment. You can | |
89 | use the macro wxDynamicCastVariantData() with the same arguments as | |
90 | wxDynamicCast(), to use C++ RTTI type information instead of wxWidgets | |
91 | RTTI. | |
7c913512 | 92 | |
0bf14ab8 JS |
93 | @section variant_wxanyconversion wxVariant to wxAny Conversion Layer |
94 | ||
95 | wxAny is a more modern, template-based variant class. It is not | |
96 | directly compatible with wxVariant, but there is a transparent conversion | |
97 | layer. | |
98 | ||
99 | Following is an example how to use these conversions with wxPropertyGrid's | |
100 | property class wxPGProperty (which currently uses wxVariants both | |
101 | internally and in the public API): | |
102 | ||
103 | @code | |
104 | // Get property value as wxAny instead of wxVariant | |
105 | wxAny value = property->GetValue(); | |
106 | ||
107 | // Do something with it | |
108 | DoSomethingWithString(value.As<wxString>()); | |
109 | ||
110 | // Write back new value to property | |
111 | value = "New Value"; | |
112 | property->SetValue(value); | |
113 | ||
114 | @endcode | |
115 | ||
116 | Some caveats: | |
117 | @li In wxAny, there are no separate types for handling integers of | |
118 | different sizes, so converting wxAny with 'long long' value | |
119 | will yield wxVariant of "long" type when the value is small | |
120 | enough to fit in without overflow. Otherwise, variant type | |
121 | "longlong" is used. Also note that wxAny holding unsigned integer | |
122 | will always be converted to "ulonglong" wxVariant type. | |
123 | ||
124 | @li Unlike wxVariant, wxAny does not store a (rarely needed) name string. | |
125 | ||
126 | @li Because of implicit conversion of wxVariant to wxAny, wxAny cannot | |
127 | usually contain value of type wxVariant. In other words, | |
128 | any.CheckType<wxVariant>() can never return @true. | |
129 | ||
130 | Supplied conversion functions will automatically work with all | |
131 | built-in wxVariant types, and also with all user-specified types generated | |
132 | using IMPLEMENT_VARIANT_OBJECT(). For hand-built wxVariantData classes, | |
133 | you will need to use supplied macros in a following manner: | |
134 | ||
135 | @code | |
136 | ||
137 | // Declare wxVariantData for data type Foo | |
138 | class wxVariantDataFoo: public wxVariantData | |
139 | { | |
140 | public: | |
141 | // interface | |
142 | // ... | |
143 | ||
144 | DECLARE_WXANY_CONVERSION() | |
145 | protected: | |
146 | // data storage etc | |
147 | // ... | |
148 | }; | |
149 | ||
150 | IMPLEMENT_TRIVIAL_WXANY_CONVERSION(Foo, wxVariantDataFoo) | |
151 | ||
152 | @endcode | |
153 | ||
23324ae1 FM |
154 | @library{wxbase} |
155 | @category{data} | |
7c913512 | 156 | |
0bf14ab8 | 157 | @see wxVariantData, wxAny |
23324ae1 FM |
158 | */ |
159 | class wxVariant : public wxObject | |
160 | { | |
161 | public: | |
23324ae1 | 162 | /** |
c1996262 | 163 | Default constructor. |
23324ae1 FM |
164 | */ |
165 | wxVariant(); | |
da1ed74c | 166 | |
c1996262 | 167 | /** |
09ad05fa BP |
168 | Constructs a variant directly with a wxVariantData object. wxVariant |
169 | will take ownership of the wxVariantData and will not increase its | |
170 | reference count. | |
c1996262 | 171 | */ |
da1ed74c FM |
172 | wxVariant(wxVariantData* data, const wxString& name = wxEmptyString); |
173 | ||
c1996262 | 174 | /** |
09ad05fa BP |
175 | Constructs a variant from another variant by increasing the reference |
176 | count. | |
c1996262 | 177 | */ |
7c913512 | 178 | wxVariant(const wxVariant& variant); |
da1ed74c | 179 | |
0bf14ab8 JS |
180 | /** |
181 | Constructs a variant by converting it from wxAny. | |
182 | */ | |
183 | wxVariant(const wxAny& any); | |
184 | ||
c1996262 RR |
185 | /** |
186 | Constructs a variant from a wide string literal. | |
187 | */ | |
da1ed74c FM |
188 | wxVariant(const wxChar* value, const wxString& name = wxEmptyString); |
189 | ||
c1996262 RR |
190 | /** |
191 | Constructs a variant from a string. | |
192 | */ | |
da1ed74c FM |
193 | wxVariant(const wxString& value, const wxString& name = wxEmptyString); |
194 | ||
c1996262 RR |
195 | /** |
196 | Constructs a variant from a wide char. | |
197 | */ | |
da1ed74c FM |
198 | wxVariant(wxChar value, const wxString& name = wxEmptyString); |
199 | ||
c1996262 RR |
200 | /** |
201 | Constructs a variant from a long. | |
202 | */ | |
da1ed74c FM |
203 | wxVariant(long value, const wxString& name = wxEmptyString); |
204 | ||
c1996262 RR |
205 | /** |
206 | Constructs a variant from a bool. | |
207 | */ | |
da1ed74c FM |
208 | wxVariant(bool value, const wxString& name = wxEmptyString); |
209 | ||
c1996262 RR |
210 | /** |
211 | Constructs a variant from a double. | |
212 | */ | |
da1ed74c FM |
213 | wxVariant(double value, const wxString& name = wxEmptyString); |
214 | ||
4e00b908 JS |
215 | /** |
216 | Constructs a variant from a wxLongLong. | |
217 | */ | |
218 | wxVariant(wxLongLong value, const wxString& name = wxEmptyString); | |
219 | ||
220 | /** | |
221 | Constructs a variant from a wxULongLong. | |
222 | */ | |
223 | wxVariant(wxULongLong value, const wxString& name = wxEmptyString); | |
224 | ||
c1996262 RR |
225 | /** |
226 | Constructs a variant from a list of variants | |
227 | */ | |
da1ed74c FM |
228 | wxVariant(const wxVariantList& value, const wxString& name = wxEmptyString); |
229 | ||
c1996262 RR |
230 | /** |
231 | Constructs a variant from a void pointer. | |
232 | */ | |
da1ed74c FM |
233 | wxVariant(void* value, const wxString& name = wxEmptyString); |
234 | ||
c1996262 RR |
235 | /** |
236 | Constructs a variant from a pointer to an wxObject | |
237 | derived class. | |
238 | */ | |
da1ed74c FM |
239 | wxVariant(wxObject* value, const wxString& name = wxEmptyString); |
240 | ||
c1996262 RR |
241 | /** |
242 | Constructs a variant from a wxDateTime. | |
243 | */ | |
cfbe5614 | 244 | wxVariant(const wxDateTime& val, const wxString& name = wxEmptyString); |
da1ed74c | 245 | |
c1996262 RR |
246 | /** |
247 | Constructs a variant from a wxArrayString. | |
248 | */ | |
cfbe5614 | 249 | wxVariant(const wxArrayString& val, const wxString& name = wxEmptyString); |
23324ae1 FM |
250 | |
251 | /** | |
252 | Destructor. | |
09ad05fa BP |
253 | |
254 | @note wxVariantData's destructor is protected, so wxVariantData cannot | |
255 | usually be deleted. Instead, wxVariantData::DecRef() should be | |
256 | called. See @ref overview_refcount_destruct | |
257 | "reference-counted object destruction" for more info. | |
23324ae1 | 258 | */ |
adaaa686 | 259 | virtual ~wxVariant(); |
23324ae1 | 260 | |
09ad05fa | 261 | |
c1996262 | 262 | /** |
09ad05fa | 263 | @name List Functionality |
c1996262 RR |
264 | */ |
265 | //@{ | |
09ad05fa | 266 | |
c1996262 RR |
267 | /** |
268 | Returns the value at @a idx (zero-based). | |
269 | */ | |
09ad05fa | 270 | wxVariant operator [](size_t idx) const; |
c1996262 | 271 | /** |
09ad05fa BP |
272 | Returns a reference to the value at @a idx (zero-based). This can be |
273 | used to change the value at this index. | |
c1996262 | 274 | */ |
09ad05fa BP |
275 | wxVariant& operator [](size_t idx); |
276 | ||
23324ae1 FM |
277 | /** |
278 | Appends a value to the list. | |
279 | */ | |
280 | void Append(const wxVariant& value); | |
09ad05fa BP |
281 | |
282 | /** | |
283 | Makes the variant null by deleting the internal data and set the name | |
284 | to wxEmptyString. | |
285 | */ | |
286 | void Clear(); | |
287 | ||
c1996262 RR |
288 | /** |
289 | Deletes the contents of the list. | |
290 | */ | |
291 | void ClearList(); | |
09ad05fa | 292 | |
c1996262 RR |
293 | /** |
294 | Deletes the zero-based @a item from the list. | |
295 | */ | |
296 | bool Delete(size_t item); | |
09ad05fa | 297 | |
c1996262 RR |
298 | /** |
299 | Returns the number of elements in the list. | |
300 | */ | |
301 | size_t GetCount() const; | |
09ad05fa | 302 | |
c1996262 | 303 | /** |
09ad05fa BP |
304 | Returns a reference to the wxVariantList class used by wxVariant if |
305 | this wxVariant is currently a list of variants. | |
c1996262 RR |
306 | */ |
307 | wxVariantList& GetList() const; | |
09ad05fa | 308 | |
23324ae1 | 309 | /** |
c1996262 | 310 | Inserts a value at the front of the list. |
23324ae1 | 311 | */ |
c1996262 | 312 | void Insert(const wxVariant& value); |
09ad05fa | 313 | |
c1996262 | 314 | /** |
09ad05fa BP |
315 | Makes an empty list. This differs from a null variant which has no |
316 | data; a null list is of type list, but the number of elements in the | |
317 | list is zero. | |
c1996262 RR |
318 | */ |
319 | void NullList(); | |
09ad05fa | 320 | |
c1996262 | 321 | //@} |
23324ae1 | 322 | |
09ad05fa | 323 | |
23324ae1 FM |
324 | //@{ |
325 | /** | |
09ad05fa BP |
326 | Retrieves and converts the value of this variant to the type that |
327 | @a value is. | |
23324ae1 | 328 | */ |
328f5751 | 329 | bool Convert(long* value) const; |
09ad05fa BP |
330 | bool Convert(bool* value) const; |
331 | bool Convert(double* value) const; | |
332 | bool Convert(wxString* value) const; | |
333 | bool Convert(wxChar* value) const; | |
4e00b908 JS |
334 | bool Convert(wxLongLong* value) const; |
335 | bool Convert(wxULongLong* value) const; | |
09ad05fa | 336 | bool Convert(wxDateTime* value) const; |
23324ae1 FM |
337 | //@} |
338 | ||
0bf14ab8 JS |
339 | /** |
340 | Converts wxVariant into wxAny. | |
341 | */ | |
342 | wxAny GetAny() const; | |
343 | ||
23324ae1 FM |
344 | /** |
345 | Returns the string array value. | |
346 | */ | |
328f5751 | 347 | wxArrayString GetArrayString() const; |
23324ae1 FM |
348 | |
349 | /** | |
350 | Returns the boolean value. | |
351 | */ | |
328f5751 | 352 | bool GetBool() const; |
23324ae1 FM |
353 | |
354 | /** | |
355 | Returns the character value. | |
356 | */ | |
cfbe5614 | 357 | wxUniChar GetChar() const; |
23324ae1 | 358 | |
23324ae1 | 359 | /** |
09ad05fa BP |
360 | Returns a pointer to the internal variant data. To take ownership of |
361 | this data, you must call its wxVariantData::IncRef() method. When you | |
362 | stop using it, wxVariantData::DecRef() must be called as well. | |
23324ae1 | 363 | */ |
328f5751 | 364 | wxVariantData* GetData() const; |
23324ae1 FM |
365 | |
366 | /** | |
367 | Returns the date value. | |
368 | */ | |
328f5751 | 369 | wxDateTime GetDateTime() const; |
23324ae1 FM |
370 | |
371 | /** | |
372 | Returns the floating point value. | |
373 | */ | |
328f5751 | 374 | double GetDouble() const; |
23324ae1 | 375 | |
23324ae1 FM |
376 | /** |
377 | Returns the integer value. | |
378 | */ | |
328f5751 | 379 | long GetLong() const; |
23324ae1 | 380 | |
4e00b908 JS |
381 | /** |
382 | Returns the signed 64-bit integer value. | |
383 | */ | |
384 | wxLongLong GetLongLong() const; | |
385 | ||
23324ae1 FM |
386 | /** |
387 | Returns a constant reference to the variant name. | |
388 | */ | |
cfbe5614 | 389 | const wxString& GetName() const; |
23324ae1 FM |
390 | |
391 | /** | |
392 | Gets the string value. | |
393 | */ | |
328f5751 | 394 | wxString GetString() const; |
23324ae1 FM |
395 | |
396 | /** | |
09ad05fa BP |
397 | Returns the value type as a string. |
398 | ||
399 | The built-in types are: | |
400 | - "bool" | |
401 | - "char" | |
402 | - "datetime" | |
403 | - "double" | |
404 | - "list" | |
405 | - "long" | |
4e00b908 | 406 | - "longlong" |
09ad05fa | 407 | - "string" |
4e00b908 | 408 | - "ulonglong" |
09ad05fa BP |
409 | - "arrstring" |
410 | - "void*" | |
411 | ||
412 | If the variant is null, the value type returned is the string "null" | |
413 | (not the empty string). | |
23324ae1 | 414 | */ |
328f5751 | 415 | wxString GetType() const; |
23324ae1 | 416 | |
4e00b908 JS |
417 | /** |
418 | Returns the unsigned 64-bit integer value. | |
419 | */ | |
420 | wxULongLong GetULongLong() const; | |
421 | ||
23324ae1 FM |
422 | /** |
423 | Gets the void pointer value. | |
d099c754 VZ |
424 | |
425 | Notice that this method can be used for null objects (i.e. those for | |
426 | which IsNull() returns @true) and will return @NULL for them. | |
23324ae1 | 427 | */ |
328f5751 | 428 | void* GetVoidPtr() const; |
23324ae1 FM |
429 | |
430 | /** | |
431 | Gets the wxObject pointer value. | |
432 | */ | |
328f5751 | 433 | wxObject* GetWxObjectPtr() const; |
23324ae1 | 434 | |
23324ae1 | 435 | /** |
09ad05fa BP |
436 | Returns @true if there is no data associated with this variant, @false |
437 | if there is data. | |
23324ae1 | 438 | */ |
328f5751 | 439 | bool IsNull() const; |
23324ae1 FM |
440 | |
441 | /** | |
09ad05fa BP |
442 | Returns @true if @a type matches the type of the variant, @false |
443 | otherwise. | |
23324ae1 | 444 | */ |
328f5751 | 445 | bool IsType(const wxString& type) const; |
23324ae1 FM |
446 | |
447 | /** | |
09ad05fa BP |
448 | Returns @true if the data is derived from the class described by |
449 | @a type, @false otherwise. | |
23324ae1 | 450 | */ |
09ad05fa | 451 | bool IsValueKindOf(const wxClassInfo* type) const; |
23324ae1 FM |
452 | |
453 | /** | |
454 | Makes the variant null by deleting the internal data. | |
455 | */ | |
456 | void MakeNull(); | |
457 | ||
458 | /** | |
459 | Makes a string representation of the variant value (for any type). | |
460 | */ | |
328f5751 | 461 | wxString MakeString() const; |
23324ae1 FM |
462 | |
463 | /** | |
4cc4bfaf | 464 | Returns @true if @a value matches an element in the list. |
23324ae1 | 465 | */ |
328f5751 | 466 | bool Member(const wxVariant& value) const; |
23324ae1 | 467 | |
23324ae1 | 468 | /** |
09ad05fa BP |
469 | Sets the internal variant data, deleting the existing data if there is |
470 | any. | |
23324ae1 FM |
471 | */ |
472 | void SetData(wxVariantData* data); | |
473 | ||
474 | /** | |
09ad05fa BP |
475 | Makes sure that any data associated with this variant is not shared |
476 | with other variants. For this to work, wxVariantData::Clone() must be | |
477 | implemented for the data types you are working with. | |
478 | wxVariantData::Clone() is implemented for all the default data types. | |
23324ae1 FM |
479 | */ |
480 | bool Unshare(); | |
481 | ||
482 | //@{ | |
483 | /** | |
09ad05fa | 484 | Inequality test operator. |
23324ae1 | 485 | */ |
328f5751 | 486 | bool operator !=(const wxVariant& value) const; |
09ad05fa BP |
487 | bool operator !=(const wxString& value) const; |
488 | bool operator !=(const wxChar* value) const; | |
489 | bool operator !=(wxChar value) const; | |
11e3af6e FM |
490 | bool operator !=(long value) const; |
491 | bool operator !=(bool value) const; | |
492 | bool operator !=(double value) const; | |
4e00b908 JS |
493 | bool operator !=(wxLongLong value) const; |
494 | bool operator !=(wxULongLong value) const; | |
09ad05fa BP |
495 | bool operator !=(void* value) const; |
496 | bool operator !=(wxObject* value) const; | |
497 | bool operator !=(const wxVariantList& value) const; | |
498 | bool operator !=(const wxArrayString& value) const; | |
499 | bool operator !=(const wxDateTime& value) const; | |
23324ae1 FM |
500 | //@} |
501 | ||
502 | //@{ | |
503 | /** | |
09ad05fa BP |
504 | Assignment operator, using @ref overview_refcount "reference counting" |
505 | if possible. | |
23324ae1 FM |
506 | */ |
507 | void operator =(const wxVariant& value); | |
7c913512 FM |
508 | void operator =(wxVariantData* value); |
509 | void operator =(const wxString& value); | |
510 | void operator =(const wxChar* value); | |
511 | void operator =(wxChar value); | |
11e3af6e FM |
512 | void operator =(long value); |
513 | void operator =(bool value); | |
514 | void operator =(double value); | |
4e00b908 JS |
515 | bool operator =(wxLongLong value) const; |
516 | bool operator =(wxULongLong value) const; | |
7c913512 FM |
517 | void operator =(void* value); |
518 | void operator =(wxObject* value); | |
519 | void operator =(const wxVariantList& value); | |
520 | void operator =(const wxDateTime& value); | |
521 | void operator =(const wxArrayString& value); | |
23324ae1 FM |
522 | //@} |
523 | ||
524 | //@{ | |
525 | /** | |
09ad05fa | 526 | Equality test operator. |
23324ae1 | 527 | */ |
328f5751 | 528 | bool operator ==(const wxVariant& value) const; |
09ad05fa BP |
529 | bool operator ==(const wxString& value) const; |
530 | bool operator ==(const wxChar* value) const; | |
531 | bool operator ==(wxChar value) const; | |
11e3af6e FM |
532 | bool operator ==(long value) const; |
533 | bool operator ==(bool value) const; | |
534 | bool operator ==(double value) const; | |
4e00b908 JS |
535 | bool operator ==(wxLongLong value) const; |
536 | bool operator ==(wxULongLong value) const; | |
09ad05fa BP |
537 | bool operator ==(void* value) const; |
538 | bool operator ==(wxObject* value) const; | |
539 | bool operator ==(const wxVariantList& value) const; | |
540 | bool operator ==(const wxArrayString& value) const; | |
541 | bool operator ==(const wxDateTime& value) const; | |
23324ae1 FM |
542 | //@} |
543 | ||
23324ae1 FM |
544 | //@{ |
545 | /** | |
4e00b908 JS |
546 | Operators for implicit conversion, using appropriate getter member |
547 | function. | |
23324ae1 | 548 | */ |
328f5751 | 549 | double operator double() const; |
09ad05fa | 550 | long operator long() const; |
4e00b908 JS |
551 | wxLongLong operator wxLongLong() const; |
552 | wxULongLong operator wxULongLong() const; | |
23324ae1 FM |
553 | //@} |
554 | ||
555 | /** | |
09ad05fa BP |
556 | Operator for implicit conversion to a pointer to a void, using |
557 | GetVoidPtr(). | |
23324ae1 | 558 | */ |
328f5751 | 559 | void* operator void*() const; |
23324ae1 FM |
560 | |
561 | /** | |
562 | Operator for implicit conversion to a wxChar, using GetChar(). | |
563 | */ | |
328f5751 | 564 | char operator wxChar() const; |
23324ae1 FM |
565 | |
566 | /** | |
567 | Operator for implicit conversion to a pointer to a wxDateTime, using | |
568 | GetDateTime(). | |
569 | */ | |
328f5751 | 570 | void* operator wxDateTime() const; |
23324ae1 FM |
571 | |
572 | /** | |
573 | Operator for implicit conversion to a string, using MakeString(). | |
574 | */ | |
328f5751 | 575 | wxString operator wxString() const; |
23324ae1 FM |
576 | }; |
577 | ||
578 | ||
e54c96f1 | 579 | |
23324ae1 FM |
580 | /** |
581 | @class wxVariantData | |
7c913512 | 582 | |
09ad05fa | 583 | The wxVariantData class is used to implement a new type for wxVariant. |
23324ae1 | 584 | Derive from wxVariantData, and override the pure virtual functions. |
7c913512 | 585 | |
23324ae1 | 586 | wxVariantData is @ref overview_refcount "reference counted", but you don't |
09ad05fa BP |
587 | normally have to care about this, as wxVariant manages the count |
588 | automatically. However, in case your application needs to take ownership of | |
589 | wxVariantData, be aware that the object is created with a reference count | |
590 | of 1, and passing it to wxVariant will not increase this. In other words, | |
591 | IncRef() needs to be called only if you both take ownership of | |
592 | wxVariantData and pass it to a wxVariant. Also note that the destructor is | |
593 | protected, so you can never explicitly delete a wxVariantData instance. | |
594 | Instead, DecRef() will delete the object automatically when the reference | |
595 | count reaches zero. | |
7c913512 | 596 | |
23324ae1 | 597 | @library{wxbase} |
09ad05fa | 598 | @category{data} |
7c913512 | 599 | |
09ad05fa | 600 | @see wxVariant, wxGetVariantCast() |
23324ae1 | 601 | */ |
43087da7 | 602 | class wxVariantData : public wxObjectRefData |
23324ae1 FM |
603 | { |
604 | public: | |
605 | /** | |
606 | Default constructor. | |
607 | */ | |
608 | wxVariantData(); | |
609 | ||
610 | /** | |
09ad05fa BP |
611 | This function can be overridden to clone the data. You must implement |
612 | this function in order for wxVariant::Unshare() to work for your data. | |
613 | This function is implemented for all built-in data types. | |
23324ae1 | 614 | */ |
adaaa686 | 615 | virtual wxVariantData* Clone() const; |
23324ae1 FM |
616 | |
617 | /** | |
618 | Decreases reference count. If the count reaches zero, the object is | |
619 | automatically deleted. | |
09ad05fa BP |
620 | |
621 | @note The destructor of wxVariantData is protected, so delete cannot be | |
622 | used as normal. Instead, DecRef() should be called. | |
23324ae1 FM |
623 | */ |
624 | void DecRef(); | |
625 | ||
626 | /** | |
09ad05fa | 627 | Returns @true if this object is equal to @a data. |
23324ae1 | 628 | */ |
da1ed74c | 629 | virtual bool Eq(wxVariantData& data) const = 0; |
23324ae1 | 630 | |
0bf14ab8 JS |
631 | /** |
632 | Converts value to wxAny, if possible. Return @true if successful. | |
633 | */ | |
634 | virtual bool GetAny(wxAny* any) const; | |
635 | ||
23324ae1 FM |
636 | /** |
637 | Returns the string type of the data. | |
638 | */ | |
da1ed74c | 639 | virtual wxString GetType() const = 0; |
23324ae1 FM |
640 | |
641 | /** | |
642 | If the data is a wxObject returns a pointer to the objects wxClassInfo | |
09ad05fa | 643 | structure, if the data isn't a wxObject the method returns @NULL. |
23324ae1 | 644 | */ |
adaaa686 | 645 | virtual wxClassInfo* GetValueClassInfo(); |
23324ae1 FM |
646 | |
647 | /** | |
09ad05fa BP |
648 | Increases reference count. Note that initially wxVariantData has |
649 | reference count of 1. | |
23324ae1 FM |
650 | */ |
651 | void IncRef(); | |
652 | ||
23324ae1 | 653 | /** |
09ad05fa | 654 | Reads the data from @a stream. |
23324ae1 | 655 | */ |
cfbe5614 FM |
656 | virtual bool Read(istream& stream); |
657 | ||
09ad05fa BP |
658 | /** |
659 | Reads the data from @a string. | |
660 | */ | |
adaaa686 | 661 | virtual bool Read(wxString& string); |
23324ae1 | 662 | |
23324ae1 | 663 | /** |
09ad05fa | 664 | Writes the data to @a stream. |
23324ae1 | 665 | */ |
adaaa686 | 666 | virtual bool Write(ostream& stream) const; |
23324ae1 | 667 | /** |
09ad05fa | 668 | Writes the data to @a string. |
23324ae1 | 669 | */ |
adaaa686 | 670 | virtual bool Write(wxString& string) const; |
23324ae1 | 671 | }; |
e54c96f1 | 672 | |
09ad05fa BP |
673 | |
674 | ||
675 | // ============================================================================ | |
676 | // Global functions/macros | |
677 | // ============================================================================ | |
678 | ||
b21126db | 679 | /** @addtogroup group_funcmacro_rtti */ |
09ad05fa BP |
680 | //@{ |
681 | ||
682 | /** | |
683 | This macro returns a pointer to the data stored in @a var (wxVariant) cast | |
684 | to the type @a classname if the data is of this type (the check is done | |
685 | during the run-time) or @NULL otherwise. | |
686 | ||
687 | @header{wx/variant.h} | |
688 | ||
689 | @see @ref overview_rtti, wxDynamicCast() | |
690 | */ | |
691 | #define wxGetVariantCast(var, classname) | |
692 | ||
693 | //@} | |
694 |