]> git.saurik.com Git - wxWidgets.git/blame - include/wx/variant.h
wxDialogBase only has one ctor, so just do initialization in ctor instead of Init()
[wxWidgets.git] / include / wx / variant.h
CommitLineData
8cb50e4b 1/////////////////////////////////////////////////////////////////////////////
43f06cfd 2// Name: wx/variant.h
8cb50e4b
JS
3// Purpose: wxVariant class, container for any type
4// Author: Julian Smart
5// Modified by:
6// Created: 10/09/98
99d80019 7// Copyright: (c) Julian Smart
65571936 8// Licence: wxWindows licence
8cb50e4b
JS
9/////////////////////////////////////////////////////////////////////////////
10
11#ifndef _WX_VARIANT_H_
12#define _WX_VARIANT_H_
13
8cb50e4b 14#include "wx/defs.h"
d5dc103f
VZ
15
16#if wxUSE_VARIANT
17
8cb50e4b
JS
18#include "wx/object.h"
19#include "wx/string.h"
4c3ebca9 20#include "wx/arrstr.h"
8cb50e4b 21#include "wx/list.h"
bde626ce 22#include "wx/cpp.h"
4e00b908 23#include "wx/longlong.h"
8cb50e4b 24
e2b87f38
VZ
25#if wxUSE_DATETIME
26 #include "wx/datetime.h"
27#endif // wxUSE_DATETIME
edca7a82 28
65f19af1 29#include "wx/iosfwrap.h"
8cb50e4b 30
0bf14ab8
JS
31class wxAny;
32
8cb50e4b
JS
33/*
34 * wxVariantData stores the actual data in a wxVariant object,
35 * to allow it to store any type of data.
36 * Derive from this to provide custom data handling.
37 *
2562c823
RR
38 * NB: When you construct a wxVariantData, it will have refcount
39 * of one. Refcount will not be further increased when
40 * it is passed to wxVariant. This simulates old common
41 * scenario where wxVariant took ownership of wxVariantData
42 * passed to it.
43 * If you create wxVariantData for other reasons than passing
44 * it to wxVariant, technically you are not required to call
45 * DecRef() before deleting it.
46 *
8cb50e4b
JS
47 * TODO: in order to replace wxPropertyValue, we would need
48 * to consider adding constructors that take pointers to C++ variables,
49 * or removing that functionality from the wxProperty library.
50 * Essentially wxPropertyValue takes on some of the wxValidator functionality
51 * by storing pointers and not just actual values, allowing update of C++ data
52 * to be handled automatically. Perhaps there's another way of doing this without
53 * overloading wxVariant with unnecessary functionality.
54 */
55
cf25a599 56class WXDLLIMPEXP_BASE wxVariantData : public wxObjectRefData
8cb50e4b 57{
2562c823 58 friend class wxVariant;
8cb50e4b 59public:
92ffc98a 60 wxVariantData() { }
8cb50e4b 61
2562c823 62 // Override these to provide common functionality
8cb50e4b 63 virtual bool Eq(wxVariantData& data) const = 0;
07502d73 64
38830220 65#if wxUSE_STD_IOSTREAM
07502d73 66 virtual bool Write(wxSTD ostream& WXUNUSED(str)) const { return false; }
38830220 67#endif
07502d73 68 virtual bool Write(wxString& WXUNUSED(str)) const { return false; }
38830220 69#if wxUSE_STD_IOSTREAM
07502d73 70 virtual bool Read(wxSTD istream& WXUNUSED(str)) { return false; }
38830220 71#endif
07502d73 72 virtual bool Read(wxString& WXUNUSED(str)) { return false; }
8cb50e4b
JS
73 // What type is it? Return a string name.
74 virtual wxString GetType() const = 0;
cf6ae290
RG
75 // If it based on wxObject return the ClassInfo.
76 virtual wxClassInfo* GetValueClassInfo() { return NULL; }
2562c823 77
cf25a599 78 // Implement this to make wxVariant::UnShare work. Returns
c8058a09
JS
79 // a copy of the data.
80 virtual wxVariantData* Clone() const { return NULL; }
81
0bf14ab8
JS
82#if wxUSE_ANY
83 // Converts value to wxAny, if possible. Return true if successful.
84 virtual bool GetAsAny(wxAny* WXUNUSED(any)) const { return false; }
85#endif
86
2562c823
RR
87protected:
88 // Protected dtor should make some incompatible code
89 // break more louder. That is, they should do data->DecRef()
90 // instead of delete data.
91 virtual ~wxVariantData() { }
8cb50e4b
JS
92};
93
94/*
95 * wxVariant can store any kind of data, but has some basic types
96 * built in.
8cb50e4b 97 */
c8058a09 98
7e6b4780
RR
99class WXDLLIMPEXP_FWD_BASE wxVariant;
100
101WX_DECLARE_LIST_WITH_DECL(wxVariant, wxVariantList, class WXDLLIMPEXP_BASE);
8cb50e4b 102
bddd7a8d 103class WXDLLIMPEXP_BASE wxVariant: public wxObject
8cb50e4b 104{
8cb50e4b 105public:
8cb50e4b 106 wxVariant();
07502d73 107
8cb50e4b 108 wxVariant(const wxVariant& variant);
2562c823 109 wxVariant(wxVariantData* data, const wxString& name = wxEmptyString);
0bf14ab8
JS
110#if wxUSE_ANY
111 wxVariant(const wxAny& any);
112#endif
d3c7fc99 113 virtual ~wxVariant();
8cb50e4b 114
2562c823 115 // generic assignment
8cb50e4b
JS
116 void operator= (const wxVariant& variant);
117
118 // Assignment using data, e.g.
119 // myVariant = new wxStringVariantData("hello");
120 void operator= (wxVariantData* variantData);
07502d73 121
8cb50e4b
JS
122 bool operator== (const wxVariant& variant) const;
123 bool operator!= (const wxVariant& variant) const;
124
2562c823
RR
125 // Sets/gets name
126 inline void SetName(const wxString& name) { m_name = name; }
127 inline const wxString& GetName() const { return m_name; }
128
129 // Tests whether there is data
07502d73 130 bool IsNull() const;
2562c823
RR
131
132 // For compatibility with wxWidgets <= 2.6, this doesn't increase
133 // reference count.
cf25a599
JS
134 wxVariantData* GetData() const
135 {
136 return (wxVariantData*) m_refData;
137 }
2562c823
RR
138 void SetData(wxVariantData* data) ;
139
140 // make a 'clone' of the object
cf25a599 141 void Ref(const wxVariant& clone) { wxObject::Ref(clone); }
2562c823 142
c8058a09
JS
143 // ensure that the data is exclusive to this variant, and not shared
144 bool Unshare();
145
2562c823
RR
146 // Make NULL (i.e. delete the data)
147 void MakeNull();
07502d73 148
2562c823
RR
149 // Delete data and name
150 void Clear();
07502d73 151
2562c823
RR
152 // Returns a string representing the type of the variant,
153 // e.g. "string", "bool", "stringlist", "list", "double", "long"
154 wxString GetType() const;
155
156 bool IsType(const wxString& type) const;
157 bool IsValueKindOf(const wxClassInfo* type) const;
158
07502d73 159 // write contents to a string (e.g. for debugging)
2562c823 160 wxString MakeString() const;
07502d73 161
0bf14ab8
JS
162#if wxUSE_ANY
163 wxAny GetAny() const;
164#endif
165
2562c823
RR
166 // double
167 wxVariant(double val, const wxString& name = wxEmptyString);
8cb50e4b
JS
168 bool operator== (double value) const;
169 bool operator!= (double value) const;
170 void operator= (double value) ;
2562c823
RR
171 inline operator double () const { return GetDouble(); }
172 inline double GetReal() const { return GetDouble(); }
173 double GetDouble() const;
07502d73 174
2562c823
RR
175 // long
176 wxVariant(long val, const wxString& name = wxEmptyString);
177 wxVariant(int val, const wxString& name = wxEmptyString);
178 wxVariant(short val, const wxString& name = wxEmptyString);
8cb50e4b
JS
179 bool operator== (long value) const;
180 bool operator!= (long value) const;
181 void operator= (long value) ;
2562c823
RR
182 inline operator long () const { return GetLong(); }
183 inline long GetInteger() const { return GetLong(); }
184 long GetLong() const;
07502d73
WS
185
186 // bool
2562c823 187 wxVariant(bool val, const wxString& name = wxEmptyString);
8cb50e4b
JS
188 bool operator== (bool value) const;
189 bool operator!= (bool value) const;
190 void operator= (bool value) ;
2562c823
RR
191 inline operator bool () const { return GetBool(); }
192 bool GetBool() const ;
2562c823
RR
193
194 // wxDateTime
195#if wxUSE_DATETIME
07502d73 196 wxVariant(const wxDateTime& val, const wxString& name = wxEmptyString);
2562c823
RR
197 bool operator== (const wxDateTime& value) const;
198 bool operator!= (const wxDateTime& value) const;
199 void operator= (const wxDateTime& value) ;
2562c823
RR
200 inline operator wxDateTime () const { return GetDateTime(); }
201 wxDateTime GetDateTime() const;
57493f9f 202#endif
2562c823
RR
203
204 // wxString
205 wxVariant(const wxString& val, const wxString& name = wxEmptyString);
af717fa8
VS
206 // these overloads are necessary to prevent the compiler from using bool
207 // version instead of wxString one:
208 wxVariant(const char* val, const wxString& name = wxEmptyString);
209 wxVariant(const wchar_t* val, const wxString& name = wxEmptyString);
210 wxVariant(const wxCStrData& val, const wxString& name = wxEmptyString);
de4983f3
VS
211 wxVariant(const wxScopedCharBuffer& val, const wxString& name = wxEmptyString);
212 wxVariant(const wxScopedWCharBuffer& val, const wxString& name = wxEmptyString);
af717fa8 213
8cb50e4b
JS
214 bool operator== (const wxString& value) const;
215 bool operator!= (const wxString& value) const;
af717fa8
VS
216 wxVariant& operator=(const wxString& value);
217 // these overloads are necessary to prevent the compiler from using bool
218 // version instead of wxString one:
219 wxVariant& operator=(const char* value)
220 { return *this = wxString(value); }
221 wxVariant& operator=(const wchar_t* value)
222 { return *this = wxString(value); }
223 wxVariant& operator=(const wxCStrData& value)
224 { return *this = value.AsString(); }
225 template<typename T>
de4983f3 226 wxVariant& operator=(const wxScopedCharTypeBuffer<T>& value)
af717fa8
VS
227 { return *this = value.data(); }
228
2562c823
RR
229 inline operator wxString () const { return MakeString(); }
230 wxString GetString() const;
231
28144838
VS
232#if wxUSE_STD_STRING
233 wxVariant(const std::string& val, const wxString& name = wxEmptyString);
234 bool operator==(const std::string& value) const
235 { return operator==(wxString(value)); }
236 bool operator!=(const std::string& value) const
237 { return operator!=(wxString(value)); }
238 wxVariant& operator=(const std::string& value)
239 { return operator=(wxString(value)); }
240 operator std::string() const { return (operator wxString()).ToStdString(); }
241
242 wxVariant(const wxStdWideString& val, const wxString& name = wxEmptyString);
243 bool operator==(const wxStdWideString& value) const
244 { return operator==(wxString(value)); }
245 bool operator!=(const wxStdWideString& value) const
246 { return operator!=(wxString(value)); }
247 wxVariant& operator=(const wxStdWideString& value)
248 { return operator=(wxString(value)); }
249 operator wxStdWideString() const { return (operator wxString()).ToStdWstring(); }
250#endif // wxUSE_STD_STRING
251
af717fa8
VS
252 // wxUniChar
253 wxVariant(const wxUniChar& val, const wxString& name = wxEmptyString);
254 wxVariant(const wxUniCharRef& val, const wxString& name = wxEmptyString);
255 wxVariant(char val, const wxString& name = wxEmptyString);
256 wxVariant(wchar_t val, const wxString& name = wxEmptyString);
257 bool operator==(const wxUniChar& value) const;
258 bool operator==(const wxUniCharRef& value) const { return *this == wxUniChar(value); }
259 bool operator==(char value) const { return *this == wxUniChar(value); }
260 bool operator==(wchar_t value) const { return *this == wxUniChar(value); }
261 bool operator!=(const wxUniChar& value) const { return !(*this == value); }
262 bool operator!=(const wxUniCharRef& value) const { return !(*this == value); }
263 bool operator!=(char value) const { return !(*this == value); }
264 bool operator!=(wchar_t value) const { return !(*this == value); }
265 wxVariant& operator=(const wxUniChar& value);
266 wxVariant& operator=(const wxUniCharRef& value) { return *this = wxUniChar(value); }
267 wxVariant& operator=(char value) { return *this = wxUniChar(value); }
268 wxVariant& operator=(wchar_t value) { return *this = wxUniChar(value); }
269 operator wxUniChar() const { return GetChar(); }
270 operator char() const { return GetChar(); }
271 operator wchar_t() const { return GetChar(); }
272 wxUniChar GetChar() const;
07502d73 273
2562c823
RR
274 // wxArrayString
275 wxVariant(const wxArrayString& val, const wxString& name = wxEmptyString);
276 bool operator== (const wxArrayString& value) const;
277 bool operator!= (const wxArrayString& value) const;
278 void operator= (const wxArrayString& value);
af717fa8 279 operator wxArrayString () const { return GetArrayString(); }
2562c823
RR
280 wxArrayString GetArrayString() const;
281
282 // void*
283 wxVariant(void* ptr, const wxString& name = wxEmptyString);
284 bool operator== (void* value) const;
285 bool operator!= (void* value) const;
286 void operator= (void* value);
af717fa8 287 operator void* () const { return GetVoidPtr(); }
2562c823
RR
288 void* GetVoidPtr() const;
289
290 // wxObject*
291 wxVariant(wxObject* ptr, const wxString& name = wxEmptyString);
292 bool operator== (wxObject* value) const;
293 bool operator!= (wxObject* value) const;
294 void operator= (wxObject* value);
295 wxObject* GetWxObjectPtr() const;
296
4e00b908
JS
297#if wxUSE_LONGLONG
298 // wxLongLong
299 wxVariant(wxLongLong, const wxString& name = wxEmptyString);
300 bool operator==(wxLongLong value) const;
301 bool operator!=(wxLongLong value) const;
302 void operator=(wxLongLong value);
303 operator wxLongLong() const { return GetLongLong(); }
304 wxLongLong GetLongLong() const;
305
306 // wxULongLong
307 wxVariant(wxULongLong, const wxString& name = wxEmptyString);
308 bool operator==(wxULongLong value) const;
309 bool operator!=(wxULongLong value) const;
310 void operator=(wxULongLong value);
311 operator wxULongLong() const { return GetULongLong(); }
312 wxULongLong GetULongLong() const;
313#endif
2562c823 314
2562c823
RR
315 // ------------------------------
316 // list operations
317 // ------------------------------
318
9a0a58f5
RR
319 wxVariant(const wxVariantList& val, const wxString& name = wxEmptyString); // List of variants
320 bool operator== (const wxVariantList& value) const;
321 bool operator!= (const wxVariantList& value) const;
322 void operator= (const wxVariantList& value) ;
8cb50e4b
JS
323 // Treat a list variant as an array
324 wxVariant operator[] (size_t idx) const;
325 wxVariant& operator[] (size_t idx) ;
9a0a58f5 326 wxVariantList& GetList() const ;
8cb50e4b
JS
327
328 // Return the number of elements in a list
43f06cfd 329 size_t GetCount() const;
07502d73 330
8cb50e4b
JS
331 // Make empty list
332 void NullList();
333
334 // Append to list
335 void Append(const wxVariant& value);
336
337 // Insert at front of list
338 void Insert(const wxVariant& value);
339
cab1a605 340 // Returns true if the variant is a member of the list
8cb50e4b
JS
341 bool Member(const wxVariant& value) const;
342
343 // Deletes the nth element of the list
43f06cfd 344 bool Delete(size_t item);
8cb50e4b
JS
345
346 // Clear list
347 void ClearList();
348
9708db20 349public:
2562c823 350 // Type conversion
8cb50e4b
JS
351 bool Convert(long* value) const;
352 bool Convert(bool* value) const;
353 bool Convert(double* value) const;
354 bool Convert(wxString* value) const;
af717fa8
VS
355 bool Convert(wxUniChar* value) const;
356 bool Convert(char* value) const;
357 bool Convert(wchar_t* value) const;
e2b87f38 358#if wxUSE_DATETIME
edca7a82 359 bool Convert(wxDateTime* value) const;
e2b87f38 360#endif // wxUSE_DATETIME
4e00b908
JS
361#if wxUSE_LONGLONG
362 bool Convert(wxLongLong* value) const;
363 bool Convert(wxULongLong* value) const;
5eedcd5e
JS
364 #ifdef wxLongLong_t
365 bool Convert(wxLongLong_t* value) const
366 {
367 wxLongLong temp;
368 if ( !Convert(&temp) )
369 return false;
370 *value = temp.GetValue();
371 return true;
372 }
373 bool Convert(wxULongLong_t* value) const
374 {
375 wxULongLong temp;
376 if ( !Convert(&temp) )
377 return false;
378 *value = temp.GetValue();
379 return true;
380 }
381 #endif // wxLongLong_t
4e00b908 382#endif // wxUSE_LONGLONG
8cb50e4b
JS
383
384// Attributes
385protected:
cf25a599
JS
386 virtual wxObjectRefData *CreateRefData() const;
387 virtual wxObjectRefData *CloneRefData(const wxObjectRefData *data) const;
388
a0a302dc 389 wxString m_name;
07502d73 390
2562c823
RR
391private:
392 DECLARE_DYNAMIC_CLASS(wxVariant)
8cb50e4b
JS
393};
394
0bf14ab8
JS
395
396//
397// wxVariant <-> wxAny conversion code
398//
399#if wxUSE_ANY
400
401#include "wx/any.h"
402
403// In order to convert wxAny to wxVariant, we need to be able to associate
404// wxAnyValueType with a wxVariantData factory function.
405typedef wxVariantData* (*wxVariantDataFactory)(const wxAny& any);
406
407// Actual Any-to-Variant registration must be postponed to a time when all
408// global variables have been initialized. Hence this arrangement.
409// wxAnyToVariantRegistration instances are kept in global scope and
410// wxAnyValueTypeGlobals in any.cpp will use their data when the time is
411// right.
412class WXDLLIMPEXP_BASE wxAnyToVariantRegistration
413{
414public:
415 wxAnyToVariantRegistration(wxVariantDataFactory factory);
2a227e8c 416 virtual ~wxAnyToVariantRegistration();
0bf14ab8
JS
417
418 virtual wxAnyValueType* GetAssociatedType() = 0;
419 wxVariantDataFactory GetFactory() const { return m_factory; }
420private:
421 wxVariantDataFactory m_factory;
422};
423
424template<typename T>
425class wxAnyToVariantRegistrationImpl : public wxAnyToVariantRegistration
426{
427public:
428 wxAnyToVariantRegistrationImpl(wxVariantDataFactory factory)
429 : wxAnyToVariantRegistration(factory)
430 {
431 }
432
433 virtual wxAnyValueType* GetAssociatedType()
434 {
435 return wxAnyValueTypeImpl<T>::GetInstance();
436 }
437private:
438};
439
440#define DECLARE_WXANY_CONVERSION() \
441virtual bool GetAsAny(wxAny* any) const; \
442static wxVariantData* VariantDataFactory(const wxAny& any);
443
153107b4 444#define _REGISTER_WXANY_CONVERSION(T, CLASSNAME, FUNC) \
0bf14ab8
JS
445static wxAnyToVariantRegistrationImpl<T> \
446 gs_##CLASSNAME##AnyToVariantRegistration = \
153107b4
JS
447 wxAnyToVariantRegistrationImpl<T>(&FUNC);
448
449#define REGISTER_WXANY_CONVERSION(T, CLASSNAME) \
450_REGISTER_WXANY_CONVERSION(T, CLASSNAME, CLASSNAME::VariantDataFactory)
0bf14ab8
JS
451
452#define IMPLEMENT_TRIVIAL_WXANY_CONVERSION(T, CLASSNAME) \
453bool CLASSNAME::GetAsAny(wxAny* any) const \
454{ \
455 *any = m_value; \
456 return true; \
457} \
458wxVariantData* CLASSNAME::VariantDataFactory(const wxAny& any) \
459{ \
460 return new CLASSNAME(wxANY_AS(any, T)); \
461} \
462REGISTER_WXANY_CONVERSION(T, CLASSNAME)
463
0bf14ab8
JS
464#else // if !wxUSE_ANY
465
466#define DECLARE_WXANY_CONVERSION()
467#define REGISTER_WXANY_CONVERSION(T, CLASSNAME)
468#define IMPLEMENT_TRIVIAL_WXANY_CONVERSION(T, CLASSNAME)
469
470#endif // wxUSE_ANY/!wxUSE_ANY
471
472
3f90a399 473#define DECLARE_VARIANT_OBJECT(classname) \
bde626ce 474 DECLARE_VARIANT_OBJECT_EXPORTED(classname, wxEMPTY_PARAMETER_VALUE)
07502d73 475
6f5d7825 476#define DECLARE_VARIANT_OBJECT_EXPORTED(classname,expdecl) \
39a48551
VZ
477expdecl classname& operator << ( classname &object, const wxVariant &variant ); \
478expdecl wxVariant& operator << ( wxVariant &variant, const classname &object );
3f90a399
RR
479
480#define IMPLEMENT_VARIANT_OBJECT(classname) \
bde626ce 481 IMPLEMENT_VARIANT_OBJECT_EXPORTED(classname, wxEMPTY_PARAMETER_VALUE)
6f5d7825 482
55ccdb93 483#define IMPLEMENT_VARIANT_OBJECT_EXPORTED_NO_EQ(classname,expdecl) \
3f90a399
RR
484class classname##VariantData: public wxVariantData \
485{ \
486public:\
487 classname##VariantData() {} \
488 classname##VariantData( const classname &value ) { m_value = value; } \
489\
490 classname &GetValue() { return m_value; } \
491\
492 virtual bool Eq(wxVariantData& data) const; \
493\
494 virtual wxString GetType() const; \
495 virtual wxClassInfo* GetValueClassInfo(); \
c8058a09
JS
496\
497 virtual wxVariantData* Clone() const { return new classname##VariantData(m_value); } \
3f90a399 498\
0bf14ab8 499 DECLARE_WXANY_CONVERSION() \
3f90a399
RR
500protected:\
501 classname m_value; \
3f90a399
RR
502};\
503\
3f90a399
RR
504wxString classname##VariantData::GetType() const\
505{\
506 return m_value.GetClassInfo()->GetClassName();\
507}\
508\
509wxClassInfo* classname##VariantData::GetValueClassInfo()\
510{\
511 return m_value.GetClassInfo();\
512}\
513\
39a48551 514expdecl classname& operator << ( classname &value, const wxVariant &variant )\
3f90a399 515{\
3586d10f 516 wxASSERT( variant.GetType() == #classname );\
3f90a399
RR
517 \
518 classname##VariantData *data = (classname##VariantData*) variant.GetData();\
519 value = data->GetValue();\
520 return value;\
521}\
522\
39a48551 523expdecl wxVariant& operator << ( wxVariant &variant, const classname &value )\
3f90a399
RR
524{\
525 classname##VariantData *data = new classname##VariantData( value );\
526 variant.SetData( data );\
527 return variant;\
0bf14ab8
JS
528} \
529IMPLEMENT_TRIVIAL_WXANY_CONVERSION(classname, classname##VariantData)
3f90a399 530
01df01eb
VZ
531// implements a wxVariantData-derived class using for the Eq() method the
532// operator== which must have been provided by "classname"
55ccdb93 533#define IMPLEMENT_VARIANT_OBJECT_EXPORTED(classname,expdecl) \
5ffa72f4 534IMPLEMENT_VARIANT_OBJECT_EXPORTED_NO_EQ(classname,wxEMPTY_PARAMETER_VALUE expdecl) \
55ccdb93
VZ
535\
536bool classname##VariantData::Eq(wxVariantData& data) const \
537{\
3586d10f 538 wxASSERT( GetType() == data.GetType() );\
55ccdb93
VZ
539\
540 classname##VariantData & otherData = (classname##VariantData &) data;\
541\
542 return otherData.m_value == m_value;\
543}\
544
545
546// implements a wxVariantData-derived class using for the Eq() method a shallow
a3ab1c18 547// comparison (through wxObject::IsSameAs function)
01df01eb
VZ
548#define IMPLEMENT_VARIANT_OBJECT_SHALLOWCMP(classname) \
549 IMPLEMENT_VARIANT_OBJECT_EXPORTED_SHALLOWCMP(classname, wxEMPTY_PARAMETER_VALUE)
55ccdb93 550#define IMPLEMENT_VARIANT_OBJECT_EXPORTED_SHALLOWCMP(classname,expdecl) \
5ffa72f4 551IMPLEMENT_VARIANT_OBJECT_EXPORTED_NO_EQ(classname,wxEMPTY_PARAMETER_VALUE expdecl) \
55ccdb93
VZ
552\
553bool classname##VariantData::Eq(wxVariantData& data) const \
554{\
3586d10f 555 wxASSERT( GetType() == data.GetType() );\
55ccdb93
VZ
556\
557 classname##VariantData & otherData = (classname##VariantData &) data;\
558\
a3ab1c18 559 return (otherData.m_value.IsSameAs(m_value));\
55ccdb93
VZ
560}\
561
562
3f90a399
RR
563// Since we want type safety wxVariant we need to fetch and dynamic_cast
564// in a seemingly safe way so the compiler can check, so we define
565// a dynamic_cast /wxDynamicCast analogue.
cf6ae290
RG
566
567#define wxGetVariantCast(var,classname) \
cab1a605
WS
568 ((classname*)(var.IsValueKindOf(&classname::ms_classInfo) ?\
569 var.GetWxObjectPtr() : NULL));
cf6ae290 570
c8058a09 571// Replacement for using wxDynamicCast on a wxVariantData object
5bdcb1f3
VZ
572#ifndef wxNO_RTTI
573 #define wxDynamicCastVariantData(data, classname) dynamic_cast<classname*>(data)
574#endif
575
576#define wxStaticCastVariantData(data, classname) static_cast<classname*>(data)
c8058a09 577
bddd7a8d 578extern wxVariant WXDLLIMPEXP_BASE wxNullVariant;
a0a302dc 579
d5dc103f
VZ
580#endif // wxUSE_VARIANT
581
582#endif // _WX_VARIANT_H_