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