1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxVariant class, container for any type
4 // Author: Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
13 #pragma implementation "variant.h"
16 // For compilers that support precompilation, includes "wx/wx.h".
17 #include "wx/wxprec.h"
23 #if wxUSE_STD_IOSTREAM
31 #if defined(__MWERKS__) && __MSL__ >= 0x6000
37 #include "wx/stream.h"
38 #include "wx/txtstrm.h"
41 #include "wx/string.h"
42 #include "wx/tokenzr.h"
44 #include "wx/variant.h"
46 IMPLEMENT_ABSTRACT_CLASS(wxVariantData
, wxObject
)
48 wxVariant WXDLLIMPEXP_BASE wxNullVariant
;
54 class WXDLLIMPEXP_BASE wxVariantDataList
: public wxVariantData
56 DECLARE_DYNAMIC_CLASS(wxVariantDataList
)
58 wxVariantDataList() {}
59 wxVariantDataList(const wxList
& list
);
62 wxList
& GetValue() const { return (wxList
&) m_value
; }
63 void SetValue(const wxList
& value
) ;
65 virtual void Copy(wxVariantData
& data
);
66 virtual bool Eq(wxVariantData
& data
) const;
67 #if wxUSE_STD_IOSTREAM
68 virtual bool Write(wxSTD ostream
& str
) const;
70 virtual bool Write(wxString
& str
) const;
71 #if wxUSE_STD_IOSTREAM
72 virtual bool Read(wxSTD istream
& str
);
74 virtual bool Read(wxString
& str
);
75 virtual wxString
GetType() const { return wxT("list"); };
83 IMPLEMENT_DYNAMIC_CLASS(wxVariantDataList
, wxVariantData
)
85 wxVariantDataList::wxVariantDataList(const wxList
& list
)
90 wxVariantDataList::~wxVariantDataList()
95 void wxVariantDataList::SetValue(const wxList
& value
)
98 wxList::compatibility_iterator node
= value
.GetFirst();
101 wxVariant
* var
= (wxVariant
*) node
->GetData();
102 m_value
.Append(new wxVariant(*var
));
103 node
= node
->GetNext();
107 void wxVariantDataList::Clear()
109 wxList::compatibility_iterator node
= m_value
.GetFirst();
112 wxVariant
* var
= (wxVariant
*) node
->GetData();
114 node
= node
->GetNext();
119 void wxVariantDataList::Copy(wxVariantData
& data
)
121 wxASSERT_MSG( (data
.GetType() == wxT("list")), wxT("wxVariantDataList::Copy: Can't copy to this type of data") );
123 wxVariantDataList
& listData
= (wxVariantDataList
&) data
;
126 wxList::compatibility_iterator node
= m_value
.GetFirst();
129 wxVariant
* var
= (wxVariant
*) node
->GetData();
130 listData
.m_value
.Append(new wxVariant(*var
));
131 node
= node
->GetNext();
135 bool wxVariantDataList::Eq(wxVariantData
& data
) const
137 wxASSERT_MSG( (data
.GetType() == wxT("list")), wxT("wxVariantDataList::Eq: argument mismatch") );
139 wxVariantDataList
& listData
= (wxVariantDataList
&) data
;
140 wxList::compatibility_iterator node1
= m_value
.GetFirst();
141 wxList::compatibility_iterator node2
= listData
.GetValue().GetFirst();
142 while (node1
&& node2
)
144 wxVariant
* var1
= (wxVariant
*) node1
->GetData();
145 wxVariant
* var2
= (wxVariant
*) node2
->GetData();
146 if ((*var1
) != (*var2
))
148 node1
= node1
->GetNext();
149 node2
= node2
->GetNext();
151 if (node1
|| node2
) return false;
155 #if wxUSE_STD_IOSTREAM
156 bool wxVariantDataList::Write(wxSTD ostream
& str
) const
160 str
<< (const char*) s
.mb_str();
165 bool wxVariantDataList::Write(wxString
& str
) const
168 wxList::compatibility_iterator node
= m_value
.GetFirst();
171 wxVariant
* var
= (wxVariant
*) node
->GetData();
172 if (node
!= m_value
.GetFirst())
175 str
+= var
->MakeString();
176 node
= node
->GetNext();
182 #if wxUSE_STD_IOSTREAM
183 bool wxVariantDataList::Read(wxSTD istream
& WXUNUSED(str
))
185 wxFAIL_MSG(wxT("Unimplemented"));
191 bool wxVariantDataList::Read(wxString
& WXUNUSED(str
))
193 wxFAIL_MSG(wxT("Unimplemented"));
199 * wxVariantDataStringList
202 class WXDLLIMPEXP_BASE wxVariantDataStringList
: public wxVariantData
204 DECLARE_DYNAMIC_CLASS(wxVariantDataStringList
)
206 wxVariantDataStringList() {}
207 wxVariantDataStringList(const wxStringList
& list
) { m_value
= list
; }
209 wxStringList
& GetValue() const { return (wxStringList
&) m_value
; }
210 void SetValue(const wxStringList
& value
);
212 virtual void Copy(wxVariantData
& data
);
213 virtual bool Eq(wxVariantData
& data
) const;
214 #if wxUSE_STD_IOSTREAM
215 virtual bool Write(wxSTD ostream
& str
) const;
217 virtual bool Write(wxString
& str
) const;
218 #if wxUSE_STD_IOSTREAM
219 virtual bool Read(wxSTD istream
& str
);
221 virtual bool Read(wxString
& str
);
222 virtual wxString
GetType() const { return wxT("stringlist"); };
225 wxStringList m_value
;
228 IMPLEMENT_DYNAMIC_CLASS(wxVariantDataStringList
, wxVariantData
)
230 void wxVariantDataStringList::SetValue(const wxStringList
& value
)
235 void wxVariantDataStringList::Copy(wxVariantData
& data
)
237 wxASSERT_MSG( (data
.GetType() == wxT("stringlist")), wxT("wxVariantDataStringList::Copy: Can't copy to this type of data") );
239 wxVariantDataStringList
& listData
= (wxVariantDataStringList
&) data
;
241 listData
.m_value
= m_value
;
244 bool wxVariantDataStringList::Eq(wxVariantData
& data
) const
246 wxASSERT_MSG( (data
.GetType() == wxT("stringlist")), wxT("wxVariantDataStringList::Eq: argument mismatch") );
248 wxVariantDataStringList
& listData
= (wxVariantDataStringList
&) data
;
249 wxStringList::compatibility_iterator node1
= m_value
.GetFirst();
250 wxStringList::compatibility_iterator node2
= listData
.GetValue().GetFirst();
251 while (node1
&& node2
)
253 wxString
str1 ( node1
->GetData() );
254 wxString
str2 ( node2
->GetData() );
257 node1
= node1
->GetNext();
258 node2
= node2
->GetNext();
260 if (node1
|| node2
) return false;
264 #if wxUSE_STD_IOSTREAM
265 bool wxVariantDataStringList::Write(wxSTD ostream
& str
) const
269 str
<< (const char*) s
.mb_str();
274 bool wxVariantDataStringList::Write(wxString
& str
) const
277 wxStringList::compatibility_iterator node
= m_value
.GetFirst();
280 const wxChar
* s
= node
->GetData();
281 if (node
!= m_value
.GetFirst())
284 node
= node
->GetNext();
290 #if wxUSE_STD_IOSTREAM
291 bool wxVariantDataStringList::Read(wxSTD istream
& WXUNUSED(str
))
293 wxFAIL_MSG(wxT("Unimplemented"));
299 bool wxVariantDataStringList::Read(wxString
& WXUNUSED(str
))
301 wxFAIL_MSG(wxT("Unimplemented"));
310 class WXDLLIMPEXP_BASE wxVariantDataLong
: public wxVariantData
312 DECLARE_DYNAMIC_CLASS(wxVariantDataLong
)
314 wxVariantDataLong() { m_value
= 0; }
315 wxVariantDataLong(long value
) { m_value
= value
; }
317 inline long GetValue() const { return m_value
; }
318 inline void SetValue(long value
) { m_value
= value
; }
320 virtual void Copy(wxVariantData
& data
);
321 virtual bool Eq(wxVariantData
& data
) const;
323 virtual bool Read(wxString
& str
);
324 virtual bool Write(wxString
& str
) const;
325 #if wxUSE_STD_IOSTREAM
326 virtual bool Read(wxSTD istream
& str
);
327 virtual bool Write(wxSTD ostream
& str
) const;
330 virtual bool Read(wxInputStream
& str
);
331 virtual bool Write(wxOutputStream
&str
) const;
332 #endif // wxUSE_STREAMS
334 virtual wxString
GetType() const { return wxT("long"); };
340 IMPLEMENT_DYNAMIC_CLASS(wxVariantDataLong
, wxVariantData
)
342 void wxVariantDataLong::Copy(wxVariantData
& data
)
344 wxASSERT_MSG( (data
.GetType() == wxT("long")), wxT("wxVariantDataLong::Copy: Can't copy to this type of data") );
346 wxVariantDataLong
& otherData
= (wxVariantDataLong
&) data
;
348 otherData
.m_value
= m_value
;
351 bool wxVariantDataLong::Eq(wxVariantData
& data
) const
353 wxASSERT_MSG( (data
.GetType() == wxT("long")), wxT("wxVariantDataLong::Eq: argument mismatch") );
355 wxVariantDataLong
& otherData
= (wxVariantDataLong
&) data
;
357 return (otherData
.m_value
== m_value
);
360 #if wxUSE_STD_IOSTREAM
361 bool wxVariantDataLong::Write(wxSTD ostream
& str
) const
365 str
<< (const char*) s
.mb_str();
370 bool wxVariantDataLong::Write(wxString
& str
) const
372 str
.Printf(wxT("%ld"), m_value
);
376 #if wxUSE_STD_IOSTREAM
377 bool wxVariantDataLong::Read(wxSTD istream
& str
)
385 bool wxVariantDataLong::Write(wxOutputStream
& str
) const
387 wxTextOutputStream
s(str
);
389 s
.Write32((size_t)m_value
);
393 bool wxVariantDataLong::Read(wxInputStream
& str
)
395 wxTextInputStream
s(str
);
396 m_value
= s
.Read32();
399 #endif // wxUSE_STREAMS
401 bool wxVariantDataLong::Read(wxString
& str
)
403 m_value
= wxAtol((const wxChar
*) str
);
411 class WXDLLIMPEXP_BASE wxVariantDataReal
: public wxVariantData
413 DECLARE_DYNAMIC_CLASS(wxVariantDataReal
)
415 wxVariantDataReal() { m_value
= 0.0; }
416 wxVariantDataReal(double value
) { m_value
= value
; }
418 inline double GetValue() const { return m_value
; }
419 inline void SetValue(double value
) { m_value
= value
; }
421 virtual void Copy(wxVariantData
& data
);
422 virtual bool Eq(wxVariantData
& data
) const;
423 virtual bool Read(wxString
& str
);
424 #if wxUSE_STD_IOSTREAM
425 virtual bool Write(wxSTD ostream
& str
) const;
427 virtual bool Write(wxString
& str
) const;
428 #if wxUSE_STD_IOSTREAM
429 virtual bool Read(wxSTD istream
& str
);
432 virtual bool Read(wxInputStream
& str
);
433 virtual bool Write(wxOutputStream
&str
) const;
434 #endif // wxUSE_STREAMS
435 virtual wxString
GetType() const { return wxT("double"); };
441 IMPLEMENT_DYNAMIC_CLASS(wxVariantDataReal
, wxVariantData
)
443 void wxVariantDataReal::Copy(wxVariantData
& data
)
445 wxASSERT_MSG( (data
.GetType() == wxT("double")), wxT("wxVariantDataReal::Copy: Can't copy to this type of data") );
447 wxVariantDataReal
& otherData
= (wxVariantDataReal
&) data
;
449 otherData
.m_value
= m_value
;
452 bool wxVariantDataReal::Eq(wxVariantData
& data
) const
454 wxASSERT_MSG( (data
.GetType() == wxT("double")), wxT("wxVariantDataReal::Eq: argument mismatch") );
456 wxVariantDataReal
& otherData
= (wxVariantDataReal
&) data
;
458 return (otherData
.m_value
== m_value
);
461 #if wxUSE_STD_IOSTREAM
462 bool wxVariantDataReal::Write(wxSTD ostream
& str
) const
466 str
<< (const char*) s
.mb_str();
471 bool wxVariantDataReal::Write(wxString
& str
) const
473 str
.Printf(wxT("%.4f"), m_value
);
477 #if wxUSE_STD_IOSTREAM
478 bool wxVariantDataReal::Read(wxSTD istream
& str
)
486 bool wxVariantDataReal::Write(wxOutputStream
& str
) const
488 wxTextOutputStream
s(str
);
489 s
.WriteDouble((double)m_value
);
493 bool wxVariantDataReal::Read(wxInputStream
& str
)
495 wxTextInputStream
s(str
);
496 m_value
= (float)s
.ReadDouble();
499 #endif // wxUSE_STREAMS
501 bool wxVariantDataReal::Read(wxString
& str
)
503 m_value
= wxAtof((const wxChar
*) str
);
512 class WXDLLIMPEXP_BASE wxVariantDataBool
: public wxVariantData
514 DECLARE_DYNAMIC_CLASS(wxVariantDataBool
)
516 wxVariantDataBool() { m_value
= 0; }
517 wxVariantDataBool(bool value
) { m_value
= value
; }
519 inline bool GetValue() const { return m_value
; }
520 inline void SetValue(bool value
) { m_value
= value
; }
522 virtual void Copy(wxVariantData
& data
);
523 virtual bool Eq(wxVariantData
& data
) const;
524 #if wxUSE_STD_IOSTREAM
525 virtual bool Write(wxSTD ostream
& str
) const;
527 virtual bool Write(wxString
& str
) const;
528 virtual bool Read(wxString
& str
);
529 #if wxUSE_STD_IOSTREAM
530 virtual bool Read(wxSTD istream
& str
);
533 virtual bool Read(wxInputStream
& str
);
534 virtual bool Write(wxOutputStream
& str
) const;
535 #endif // wxUSE_STREAMS
536 virtual wxString
GetType() const { return wxT("bool"); };
542 IMPLEMENT_DYNAMIC_CLASS(wxVariantDataBool
, wxVariantData
)
544 void wxVariantDataBool::Copy(wxVariantData
& data
)
546 wxASSERT_MSG( (data
.GetType() == wxT("bool")), wxT("wxVariantDataBool::Copy: Can't copy to this type of data") );
548 wxVariantDataBool
& otherData
= (wxVariantDataBool
&) data
;
550 otherData
.m_value
= m_value
;
553 bool wxVariantDataBool::Eq(wxVariantData
& data
) const
555 wxASSERT_MSG( (data
.GetType() == wxT("bool")), wxT("wxVariantDataBool::Eq: argument mismatch") );
557 wxVariantDataBool
& otherData
= (wxVariantDataBool
&) data
;
559 return (otherData
.m_value
== m_value
);
562 #if wxUSE_STD_IOSTREAM
563 bool wxVariantDataBool::Write(wxSTD ostream
& str
) const
567 str
<< (const char*) s
.mb_str();
572 bool wxVariantDataBool::Write(wxString
& str
) const
574 str
.Printf(wxT("%d"), (int) m_value
);
578 #if wxUSE_STD_IOSTREAM
579 bool wxVariantDataBool::Read(wxSTD istream
& WXUNUSED(str
))
581 wxFAIL_MSG(wxT("Unimplemented"));
582 // str >> (long) m_value;
588 bool wxVariantDataBool::Write(wxOutputStream
& str
) const
590 wxTextOutputStream
s(str
);
596 bool wxVariantDataBool::Read(wxInputStream
& str
)
598 wxTextInputStream
s(str
);
600 m_value
= s
.Read8() != 0;
603 #endif // wxUSE_STREAMS
605 bool wxVariantDataBool::Read(wxString
& str
)
607 m_value
= (wxAtol((const wxChar
*) str
) != 0);
616 class WXDLLIMPEXP_BASE wxVariantDataChar
: public wxVariantData
618 DECLARE_DYNAMIC_CLASS(wxVariantDataChar
)
620 wxVariantDataChar() { m_value
= 0; }
621 wxVariantDataChar(char value
) { m_value
= value
; }
623 inline char GetValue() const { return m_value
; }
624 inline void SetValue(char value
) { m_value
= value
; }
626 virtual void Copy(wxVariantData
& data
);
627 virtual bool Eq(wxVariantData
& data
) const;
628 #if wxUSE_STD_IOSTREAM
629 virtual bool Read(wxSTD istream
& str
);
630 virtual bool Write(wxSTD ostream
& str
) const;
632 virtual bool Read(wxString
& str
);
633 virtual bool Write(wxString
& str
) const;
635 virtual bool Read(wxInputStream
& str
);
636 virtual bool Write(wxOutputStream
& str
) const;
637 #endif // wxUSE_STREAMS
638 virtual wxString
GetType() const { return wxT("char"); };
644 IMPLEMENT_DYNAMIC_CLASS(wxVariantDataChar
, wxVariantData
)
646 void wxVariantDataChar::Copy(wxVariantData
& data
)
648 wxASSERT_MSG( (data
.GetType() == wxT("char")), wxT("wxVariantDataChar::Copy: Can't copy to this type of data") );
650 wxVariantDataChar
& otherData
= (wxVariantDataChar
&) data
;
652 otherData
.m_value
= m_value
;
655 bool wxVariantDataChar::Eq(wxVariantData
& data
) const
657 wxASSERT_MSG( (data
.GetType() == wxT("char")), wxT("wxVariantDataChar::Eq: argument mismatch") );
659 wxVariantDataChar
& otherData
= (wxVariantDataChar
&) data
;
661 return (otherData
.m_value
== m_value
);
664 #if wxUSE_STD_IOSTREAM
665 bool wxVariantDataChar::Write(wxSTD ostream
& str
) const
669 str
<< (const char*) s
.mb_str();
674 bool wxVariantDataChar::Write(wxString
& str
) const
676 str
.Printf(wxT("%c"), m_value
);
680 #if wxUSE_STD_IOSTREAM
681 bool wxVariantDataChar::Read(wxSTD istream
& WXUNUSED(str
))
683 wxFAIL_MSG(wxT("Unimplemented"));
690 bool wxVariantDataChar::Write(wxOutputStream
& str
) const
692 wxTextOutputStream
s(str
);
698 bool wxVariantDataChar::Read(wxInputStream
& str
)
700 wxTextInputStream
s(str
);
705 #endif // wxUSE_STREAMS
707 bool wxVariantDataChar::Read(wxString
& str
)
709 m_value
= str
.ToAscii()[0u];
714 * wxVariantDataString
717 class WXDLLIMPEXP_BASE wxVariantDataString
: public wxVariantData
719 DECLARE_DYNAMIC_CLASS(wxVariantDataString
)
721 wxVariantDataString() { }
722 wxVariantDataString(const wxString
& value
) { m_value
= value
; }
724 inline wxString
GetValue() const { return m_value
; }
725 inline void SetValue(const wxString
& value
) { m_value
= value
; }
727 virtual void Copy(wxVariantData
& data
);
728 virtual bool Eq(wxVariantData
& data
) const;
729 #if wxUSE_STD_IOSTREAM
730 virtual bool Write(wxSTD ostream
& str
) const;
732 virtual bool Read(wxString
& str
);
733 virtual bool Write(wxString
& str
) const;
734 #if wxUSE_STD_IOSTREAM
735 virtual bool Read(wxSTD istream
& str
);
738 virtual bool Read(wxInputStream
& str
);
739 virtual bool Write(wxOutputStream
& str
) const;
740 #endif // wxUSE_STREAMS
741 virtual wxString
GetType() const { return wxT("string"); };
747 void wxVariantDataString::Copy(wxVariantData
& data
)
749 wxASSERT_MSG( (data
.GetType() == wxT("string")), wxT("wxVariantDataString::Copy: Can't copy to this type of data") );
751 wxVariantDataString
& otherData
= (wxVariantDataString
&) data
;
753 otherData
.m_value
= m_value
;
756 bool wxVariantDataString::Eq(wxVariantData
& data
) const
758 wxASSERT_MSG( (data
.GetType() == wxT("string")), wxT("wxVariantDataString::Eq: argument mismatch") );
760 wxVariantDataString
& otherData
= (wxVariantDataString
&) data
;
762 return (otherData
.m_value
== m_value
);
765 #if wxUSE_STD_IOSTREAM
766 bool wxVariantDataString::Write(wxSTD ostream
& str
) const
768 str
<< (const char*) m_value
.mb_str();
773 bool wxVariantDataString::Write(wxString
& str
) const
779 #if wxUSE_STD_IOSTREAM
780 bool wxVariantDataString::Read(wxSTD istream
& str
)
788 bool wxVariantDataString::Write(wxOutputStream
& str
) const
790 // why doesn't wxOutputStream::operator<< take "const wxString&"
791 wxTextOutputStream
s(str
);
792 s
.WriteString(m_value
);
796 bool wxVariantDataString::Read(wxInputStream
& str
)
798 wxTextInputStream
s(str
);
800 m_value
= s
.ReadString();
803 #endif // wxUSE_STREAMS
805 bool wxVariantDataString::Read(wxString
& str
)
811 IMPLEMENT_DYNAMIC_CLASS(wxVariantDataString
, wxVariantData
)
814 * wxVariantDataVoidPtr
817 class wxVariantDataVoidPtr
: public wxVariantData
819 DECLARE_DYNAMIC_CLASS(wxVariantDataVoidPtr
)
821 wxVariantDataVoidPtr() { }
822 wxVariantDataVoidPtr(void* value
) { m_value
= value
; }
824 inline void* GetValue() const { return m_value
; }
825 inline void SetValue(void* value
) { m_value
= value
; }
827 virtual void Copy(wxVariantData
& data
);
828 virtual bool Eq(wxVariantData
& data
) const;
829 #if wxUSE_STD_IOSTREAM
830 virtual bool Write(wxSTD ostream
& str
) const;
832 virtual bool Write(wxString
& str
) const;
833 #if wxUSE_STD_IOSTREAM
834 virtual bool Read(wxSTD istream
& str
);
836 virtual bool Read(wxString
& str
);
837 virtual wxString
GetType() const { return wxT("void*"); };
838 virtual wxVariantData
* Clone() { return new wxVariantDataVoidPtr
; }
843 DECLARE_NO_COPY_CLASS(wxVariantDataVoidPtr
)
846 IMPLEMENT_DYNAMIC_CLASS(wxVariantDataVoidPtr
, wxVariantData
)
848 void wxVariantDataVoidPtr::Copy(wxVariantData
& data
)
850 wxASSERT_MSG( (data
.GetType() == wxT("void*")), wxT("wxVariantDataVoidPtr::Copy: Can't copy to this type of data") );
852 wxVariantDataVoidPtr
& otherData
= (wxVariantDataVoidPtr
&) data
;
854 otherData
.m_value
= m_value
;
857 bool wxVariantDataVoidPtr::Eq(wxVariantData
& data
) const
859 wxASSERT_MSG( (data
.GetType() == wxT("void*")), wxT("wxVariantDataVoidPtr::Eq: argument mismatch") );
861 wxVariantDataVoidPtr
& otherData
= (wxVariantDataVoidPtr
&) data
;
863 return (otherData
.m_value
== m_value
);
866 #if wxUSE_STD_IOSTREAM
867 bool wxVariantDataVoidPtr::Write(wxSTD ostream
& str
) const
871 str
<< (const char*) s
.mb_str();
876 bool wxVariantDataVoidPtr::Write(wxString
& str
) const
878 str
.Printf(wxT("%ld"), (long) m_value
);
882 #if wxUSE_STD_IOSTREAM
883 bool wxVariantDataVoidPtr::Read(wxSTD istream
& WXUNUSED(str
))
890 bool wxVariantDataVoidPtr::Read(wxString
& WXUNUSED(str
))
897 * wxVariantDataWxObjectPtr
900 class wxVariantDataWxObjectPtr
: public wxVariantData
902 DECLARE_DYNAMIC_CLASS(wxVariantDataWxObjectPtr
)
904 wxVariantDataWxObjectPtr() { }
905 wxVariantDataWxObjectPtr(wxObject
* value
) { m_value
= value
; }
907 inline wxObject
* GetValue() const { return m_value
; }
908 inline void SetValue(wxObject
* value
) { m_value
= value
; }
910 virtual void Copy(wxVariantData
& data
);
911 virtual bool Eq(wxVariantData
& data
) const;
912 #if wxUSE_STD_IOSTREAM
913 virtual bool Write(wxSTD ostream
& str
) const;
915 virtual bool Write(wxString
& str
) const;
916 #if wxUSE_STD_IOSTREAM
917 virtual bool Read(wxSTD istream
& str
);
919 virtual bool Read(wxString
& str
);
920 virtual wxString
GetType() const ;
921 virtual wxVariantData
* Clone() { return new wxVariantDataWxObjectPtr
; }
923 virtual wxClassInfo
* GetValueClassInfo() ;
927 DECLARE_NO_COPY_CLASS(wxVariantDataWxObjectPtr
)
930 IMPLEMENT_DYNAMIC_CLASS(wxVariantDataWxObjectPtr
, wxVariantData
)
932 void wxVariantDataWxObjectPtr::Copy(wxVariantData
& data
)
934 wxASSERT_MSG( wxIsKindOf((&data
), wxVariantDataWxObjectPtr
) ,\
935 wxT("wxVariantDataWxObjectPtr::Copy: Can't copy to this type of data") \
938 wxVariantDataWxObjectPtr
& otherData
= (wxVariantDataWxObjectPtr
&) data
;
940 otherData
.m_value
= m_value
;
943 bool wxVariantDataWxObjectPtr::Eq(wxVariantData
& data
) const
945 wxASSERT_MSG( wxIsKindOf((&data
), wxVariantDataWxObjectPtr
), wxT("wxVariantDataWxObjectPtr::Eq: argument mismatch") );
947 wxVariantDataWxObjectPtr
& otherData
= (wxVariantDataWxObjectPtr
&) data
;
949 return (otherData
.m_value
== m_value
);
952 wxString
wxVariantDataWxObjectPtr::GetType() const
954 wxString
returnVal(wxT("wxObject"));
956 returnVal
= m_value
->GetClassInfo()->GetClassName();
961 wxClassInfo
* wxVariantDataWxObjectPtr::GetValueClassInfo()
963 wxClassInfo
* returnVal
=NULL
;
965 if (m_value
) returnVal
= m_value
->GetClassInfo();
970 #if wxUSE_STD_IOSTREAM
971 bool wxVariantDataWxObjectPtr::Write(wxSTD ostream
& str
) const
975 str
<< (const char*) s
.mb_str();
980 bool wxVariantDataWxObjectPtr::Write(wxString
& str
) const
982 str
.Printf(wxT("%s(%ld)"), GetType().c_str(), (long) m_value
);
986 #if wxUSE_STD_IOSTREAM
987 bool wxVariantDataWxObjectPtr::Read(wxSTD istream
& WXUNUSED(str
))
994 bool wxVariantDataWxObjectPtr::Read(wxString
& WXUNUSED(str
))
1002 * wxVariantDataDateTime
1007 class wxVariantDataDateTime
: public wxVariantData
1009 DECLARE_DYNAMIC_CLASS(wxVariantDataDateTime
)
1012 wxVariantDataDateTime() { }
1013 wxVariantDataDateTime(const wxDateTime
& value
) { m_value
= value
; }
1015 wxVariantDataDateTime(const TIME_STRUCT
* valptr
)
1016 { m_value
= wxDateTime(valptr
->hour
, valptr
->minute
, valptr
->second
); }
1017 wxVariantDataDateTime(const DATE_STRUCT
* valptr
)
1018 { m_value
= wxDateTime(valptr
->day
, (wxDateTime::Month
) (valptr
->month
- 1),valptr
->year
); }
1019 wxVariantDataDateTime(const TIMESTAMP_STRUCT
* valptr
)
1020 { m_value
= wxDateTime(valptr
->day
, (wxDateTime::Month
) (valptr
->month
- 1), valptr
->year
,
1021 valptr
->hour
, valptr
->minute
, valptr
->second
, (wxDateTime::wxDateTime_t
)valptr
->fraction
); }
1024 inline wxDateTime
GetValue() const { return m_value
; }
1025 inline void SetValue(const wxDateTime
& value
) { m_value
= value
; }
1027 virtual void Copy(wxVariantData
& data
);
1028 virtual bool Eq(wxVariantData
& data
) const;
1029 #if wxUSE_STD_IOSTREAM
1030 virtual bool Write(wxSTD ostream
& str
) const;
1032 virtual bool Write(wxString
& str
) const;
1033 #if wxUSE_STD_IOSTREAM
1034 virtual bool Read(wxSTD istream
& str
);
1036 virtual bool Read(wxString
& str
);
1037 virtual wxString
GetType() const { return wxT("datetime"); };
1038 virtual wxVariantData
* Clone() { return new wxVariantDataDateTime
; }
1045 IMPLEMENT_DYNAMIC_CLASS(wxVariantDataDateTime
, wxVariantData
)
1047 void wxVariantDataDateTime::Copy(wxVariantData
& data
)
1049 wxASSERT_MSG( (data
.GetType() == wxT("datetime")), wxT("wxVariantDataDateTime::Copy: Can't copy to this type of data") );
1051 wxVariantDataDateTime
& otherData
= (wxVariantDataDateTime
&) data
;
1053 otherData
.m_value
= m_value
;
1057 bool wxVariantDataDateTime::Eq(wxVariantData
& data
) const
1059 wxASSERT_MSG( (data
.GetType() == wxT("datetime")), wxT("wxVariantDataDateTime::Eq: argument mismatch") );
1061 wxVariantDataDateTime
& otherData
= (wxVariantDataDateTime
&) data
;
1063 return (otherData
.m_value
== m_value
);
1067 #if wxUSE_STD_IOSTREAM
1068 bool wxVariantDataDateTime::Write(wxSTD ostream
& str
) const
1076 bool wxVariantDataDateTime::Write(wxString
& str
) const
1078 str
= m_value
.Format();
1083 #if wxUSE_STD_IOSTREAM
1084 bool wxVariantDataDateTime::Read(wxSTD istream
& WXUNUSED(str
))
1092 bool wxVariantDataDateTime::Read(wxString
& str
)
1094 if(! m_value
.ParseDateTime(str
))
1099 #endif // wxUSE_DATETIME
1101 // ----------------------------------------------------------------------------
1102 // wxVariantDataArrayString
1103 // ----------------------------------------------------------------------------
1105 class wxVariantDataArrayString
: public wxVariantData
1108 wxVariantDataArrayString() { }
1109 wxVariantDataArrayString(const wxArrayString
& value
) { m_value
= value
; }
1111 wxArrayString
GetValue() const { return m_value
; }
1112 void SetValue(const wxArrayString
& value
) { m_value
= value
; }
1114 virtual void Copy(wxVariantData
& data
);
1115 virtual bool Eq(wxVariantData
& data
) const;
1116 #if wxUSE_STD_IOSTREAM
1117 virtual bool Write(wxSTD ostream
& str
) const;
1119 virtual bool Write(wxString
& str
) const;
1120 #if wxUSE_STD_IOSTREAM
1121 virtual bool Read(wxSTD istream
& str
);
1123 virtual bool Read(wxString
& str
);
1124 virtual wxString
GetType() const { return wxT("arrstring"); };
1125 virtual wxVariantData
* Clone() { return new wxVariantDataArrayString
; }
1128 wxArrayString m_value
;
1130 DECLARE_DYNAMIC_CLASS(wxVariantDataArrayString
)
1133 IMPLEMENT_DYNAMIC_CLASS(wxVariantDataArrayString
, wxVariantData
)
1135 void wxVariantDataArrayString::Copy(wxVariantData
& data
)
1137 wxASSERT_MSG( data
.GetType() == GetType(), wxT("wxVariantDataArrayString::Copy: Can't copy to this type of data") );
1139 wxVariantDataArrayString
& otherData
= (wxVariantDataArrayString
&) data
;
1141 otherData
.m_value
= m_value
;
1145 bool wxVariantDataArrayString::Eq(wxVariantData
& data
) const
1147 wxASSERT_MSG( data
.GetType() == GetType(), wxT("wxVariantDataArrayString::Eq: argument mismatch") );
1149 wxVariantDataArrayString
& otherData
= (wxVariantDataArrayString
&) data
;
1151 return otherData
.m_value
== m_value
;
1155 #if wxUSE_STD_IOSTREAM
1156 bool wxVariantDataArrayString::Write(wxSTD ostream
& str
) const
1164 bool wxVariantDataArrayString::Write(wxString
& str
) const
1166 size_t count
= m_value
.GetCount();
1167 for ( size_t n
= 0; n
< count
; n
++ )
1179 #if wxUSE_STD_IOSTREAM
1180 bool wxVariantDataArrayString::Read(wxSTD istream
& WXUNUSED(str
))
1188 bool wxVariantDataArrayString::Read(wxString
& str
)
1190 wxStringTokenizer
tk(str
, _T(";"));
1191 while ( tk
.HasMoreTokens() )
1193 m_value
.Add(tk
.GetNextToken());
1205 IMPLEMENT_DYNAMIC_CLASS(wxVariant
, wxObject
)
1207 // Construction & destruction
1208 wxVariant::wxVariant()
1210 m_data
= (wxVariantData
*) NULL
;
1213 wxVariant::wxVariant(double val
, const wxString
& name
)
1215 m_data
= new wxVariantDataReal(val
);
1219 wxVariant::wxVariant(long val
, const wxString
& name
)
1221 m_data
= new wxVariantDataLong(val
);
1226 wxVariant::wxVariant(bool val
, const wxString
& name
)
1228 m_data
= new wxVariantDataBool(val
);
1233 wxVariant::wxVariant(char val
, const wxString
& name
)
1235 m_data
= new wxVariantDataChar(val
);
1239 wxVariant::wxVariant(const wxString
& val
, const wxString
& name
)
1241 m_data
= new wxVariantDataString(val
);
1245 wxVariant::wxVariant(const wxChar
* val
, const wxString
& name
)
1247 m_data
= new wxVariantDataString(wxString(val
));
1251 wxVariant::wxVariant(const wxStringList
& val
, const wxString
& name
)
1253 m_data
= new wxVariantDataStringList(val
);
1257 wxVariant::wxVariant(const wxList
& val
, const wxString
& name
) // List of variants
1259 m_data
= new wxVariantDataList(val
);
1263 wxVariant::wxVariant( void* val
, const wxString
& name
)
1265 m_data
= new wxVariantDataVoidPtr(val
);
1269 wxVariant::wxVariant( wxObject
* val
, const wxString
& name
)
1271 m_data
= new wxVariantDataWxObjectPtr(val
);
1276 wxVariant::wxVariant(const wxDateTime
& val
, const wxString
& name
) // Date
1278 m_data
= new wxVariantDataDateTime(val
);
1281 #endif // wxUSE_DATETIME
1284 wxVariant::wxVariant(const TIME_STRUCT
* valptr
, const wxString
& name
) // Date
1286 m_data
= new wxVariantDataDateTime(valptr
);
1290 wxVariant::wxVariant(const TIMESTAMP_STRUCT
* valptr
, const wxString
& name
) // Date
1292 m_data
= new wxVariantDataDateTime(valptr
);
1296 wxVariant::wxVariant(const DATE_STRUCT
* valptr
, const wxString
& name
) // Date
1298 m_data
= new wxVariantDataDateTime(valptr
);
1301 #endif // wxUSE_ODBC
1303 wxVariant::wxVariant(const wxArrayString
& val
, const wxString
& name
) // Strings
1305 m_data
= new wxVariantDataArrayString(val
);
1309 wxVariant::wxVariant(const wxVariant
& variant
)
1312 if (!variant
.IsNull())
1314 m_data
= (wxVariantData
*) variant
.GetData()->GetClassInfo()->CreateObject();
1315 variant
.m_data
->Copy(*m_data
);
1318 m_data
= (wxVariantData
*) NULL
;
1319 m_name
= variant
.m_name
;
1322 wxVariant::wxVariant(wxVariantData
* data
, const wxString
& name
) // User-defined data
1328 wxVariant::~wxVariant()
1334 // Make NULL (i.e. delete the data)
1335 void wxVariant::MakeNull()
1341 // Generic operators
1343 void wxVariant::operator= (const wxVariant
& variant
)
1345 if (variant
.IsNull())
1351 if (IsNull() || (GetType() != variant
.GetType()))
1355 m_data
= (wxVariantData
*) variant
.GetData()->GetClassInfo()->CreateObject();
1358 variant
.GetData()->Copy(* GetData());
1360 m_name
= variant
.m_name
;
1363 // Assignment using data, e.g.
1364 // myVariant = new wxStringVariantData("hello")
1365 void wxVariant::operator= (wxVariantData
* variantData
)
1368 m_data
= variantData
;
1371 bool wxVariant::operator== (const wxVariant
& variant
) const
1373 if (IsNull() || variant
.IsNull())
1374 return (IsNull() == variant
.IsNull());
1376 return (GetData()->Eq(* variant
.GetData()));
1379 bool wxVariant::operator!= (const wxVariant
& variant
) const
1381 return (!(*this == variant
));
1385 // Specific operators
1386 bool wxVariant::operator== (double value
) const
1389 if (!Convert(&thisValue
))
1392 return (value
== thisValue
);
1395 bool wxVariant::operator!= (double value
) const
1397 return (!((*this) == value
));
1400 void wxVariant::operator= (double value
)
1402 if (GetType() == wxT("double"))
1404 ((wxVariantDataReal
*)GetData())->SetValue(value
);
1410 m_data
= new wxVariantDataReal(value
);
1414 bool wxVariant::operator== (long value
) const
1417 if (!Convert(&thisValue
))
1420 return (value
== thisValue
);
1423 bool wxVariant::operator!= (long value
) const
1425 return (!((*this) == value
));
1428 void wxVariant::operator= (long value
)
1430 if (GetType() == wxT("long"))
1432 ((wxVariantDataLong
*)GetData())->SetValue(value
);
1438 m_data
= new wxVariantDataLong(value
);
1442 bool wxVariant::operator== (char value
) const
1445 if (!Convert(&thisValue
))
1448 return (value
== thisValue
);
1451 bool wxVariant::operator!= (char value
) const
1453 return (!((*this) == value
));
1456 void wxVariant::operator= (char value
)
1458 if (GetType() == wxT("char"))
1460 ((wxVariantDataChar
*)GetData())->SetValue(value
);
1466 m_data
= new wxVariantDataChar(value
);
1471 bool wxVariant::operator== (bool value
) const
1474 if (!Convert(&thisValue
))
1477 return (value
== thisValue
);
1480 bool wxVariant::operator!= (bool value
) const
1482 return (!((*this) == value
));
1485 void wxVariant::operator= (bool value
)
1487 if (GetType() == wxT("bool"))
1489 ((wxVariantDataBool
*)GetData())->SetValue(value
);
1495 m_data
= new wxVariantDataBool(value
);
1500 bool wxVariant::operator== (const wxString
& value
) const
1503 if (!Convert(&thisValue
))
1506 return value
== thisValue
;
1509 bool wxVariant::operator!= (const wxString
& value
) const
1511 return (!((*this) == value
));
1514 void wxVariant::operator= (const wxString
& value
)
1516 if (GetType() == wxT("string"))
1518 ((wxVariantDataString
*)GetData())->SetValue(value
);
1524 m_data
= new wxVariantDataString(value
);
1528 void wxVariant::operator= (const wxChar
* value
)
1530 if (GetType() == wxT("string"))
1532 ((wxVariantDataString
*)GetData())->SetValue(wxString(value
));
1538 m_data
= new wxVariantDataString(wxString(value
));
1542 bool wxVariant::operator== (const wxStringList
& value
) const
1544 wxASSERT_MSG( (GetType() == wxT("stringlist")), wxT("Invalid type for == operator") );
1546 wxVariantDataStringList
other(value
);
1547 return (m_data
->Eq(other
));
1550 bool wxVariant::operator!= (const wxStringList
& value
) const
1552 return (!((*this) == value
));
1555 void wxVariant::operator= (const wxStringList
& value
)
1557 if (GetType() == wxT("stringlist"))
1559 ((wxVariantDataStringList
*)GetData())->SetValue(value
);
1565 m_data
= new wxVariantDataStringList(value
);
1569 bool wxVariant::operator== (const wxList
& value
) const
1571 wxASSERT_MSG( (GetType() == wxT("list")), wxT("Invalid type for == operator") );
1573 wxVariantDataList
other(value
);
1574 return (m_data
->Eq(other
));
1577 bool wxVariant::operator!= (const wxList
& value
) const
1579 return (!((*this) == value
));
1582 void wxVariant::operator= (const wxList
& value
)
1584 if (GetType() == wxT("list"))
1586 ((wxVariantDataList
*)GetData())->SetValue(value
);
1592 m_data
= new wxVariantDataList(value
);
1596 bool wxVariant::operator== (void* value
) const
1598 return (value
== ((wxVariantDataVoidPtr
*)GetData())->GetValue());
1601 bool wxVariant::operator!= (void* value
) const
1603 return (!((*this) == (void*) value
));
1606 void wxVariant::operator= (void* value
)
1608 if (GetType() == wxT("void*"))
1610 ((wxVariantDataVoidPtr
*)GetData())->SetValue(value
);
1616 m_data
= new wxVariantDataVoidPtr(value
);
1621 bool wxVariant::operator== (const wxDateTime
& value
) const
1623 wxDateTime thisValue
;
1624 if (!Convert(&thisValue
))
1627 return value
.IsEqualTo(thisValue
);
1630 bool wxVariant::operator!= (const wxDateTime
& value
) const
1632 return (!((*this) == value
));
1635 void wxVariant::operator= (const wxDateTime
& value
)
1637 if (GetType() == wxT("datetime"))
1639 ((wxVariantDataDateTime
*)GetData())->SetValue(value
);
1645 m_data
= new wxVariantDataDateTime(value
);
1648 #endif // wxUSE_DATETIME
1651 void wxVariant::operator= (const DATE_STRUCT
* value
)
1655 m_data
= new wxVariantDataDateTime(value
);
1659 void wxVariant::operator= (const TIME_STRUCT
* value
)
1663 m_data
= new wxVariantDataDateTime(value
);
1667 void wxVariant::operator= (const TIMESTAMP_STRUCT
* value
)
1671 m_data
= new wxVariantDataDateTime(value
);
1674 #endif // wxUSE_ODBC
1676 bool wxVariant::operator==(const wxArrayString
& WXUNUSED(value
)) const
1678 wxFAIL_MSG( _T("TODO") );
1683 bool wxVariant::operator!=(const wxArrayString
& value
) const
1685 return !(*this == value
);
1688 void wxVariant::operator=(const wxArrayString
& value
)
1690 if (GetType() == wxT("arrstring"))
1692 ((wxVariantDataArrayString
*)GetData())->SetValue(value
);
1697 m_data
= new wxVariantDataArrayString(value
);
1701 wxArrayString
wxVariant::GetArrayString() const
1703 if ( GetType() == wxT("arrstring") )
1704 return ((wxVariantDataArrayString
*)GetData())->GetValue();
1706 return wxArrayString();
1710 // Treat a list variant as an array
1711 wxVariant
wxVariant::operator[] (size_t idx
) const
1713 wxASSERT_MSG( (GetType() == wxT("list") || GetType() == wxT("stringlist")), wxT("Invalid type for array operator") );
1715 if (GetType() == wxT("list"))
1717 wxVariantDataList
* data
= (wxVariantDataList
*) m_data
;
1718 wxASSERT_MSG( (idx
< (size_t) data
->GetValue().GetCount()), wxT("Invalid index for array") );
1719 return * (wxVariant
*) (data
->GetValue().Item(idx
)->GetData());
1721 else if (GetType() == wxT("stringlist"))
1723 wxVariantDataStringList
* data
= (wxVariantDataStringList
*) m_data
;
1724 wxASSERT_MSG( (idx
< (size_t) data
->GetValue().GetCount()), wxT("Invalid index for array") );
1726 wxString
str( (const wxChar
*) (data
->GetValue().Item(idx
)->GetData()) );
1727 wxVariant
variant( str
);
1730 return wxNullVariant
;
1733 wxVariant
& wxVariant::operator[] (size_t idx
)
1735 // We can't return a reference to a variant for a string list, since the string
1736 // is actually stored as a char*, not a variant.
1738 wxASSERT_MSG( (GetType() == wxT("list")), wxT("Invalid type for array operator") );
1740 wxVariantDataList
* data
= (wxVariantDataList
*) m_data
;
1741 wxASSERT_MSG( (idx
< (size_t) data
->GetValue().GetCount()), wxT("Invalid index for array") );
1743 return * (wxVariant
*) (data
->GetValue().Item(idx
)->GetData());
1746 // Return the number of elements in a list
1747 int wxVariant::GetCount() const
1749 wxASSERT_MSG( (GetType() == wxT("list") || GetType() == wxT("stringlist")), wxT("Invalid type for GetCount()") );
1751 if (GetType() == wxT("list"))
1753 wxVariantDataList
* data
= (wxVariantDataList
*) m_data
;
1754 return data
->GetValue().GetCount();
1756 else if (GetType() == wxT("stringlist"))
1758 wxVariantDataStringList
* data
= (wxVariantDataStringList
*) m_data
;
1759 return data
->GetValue().GetCount();
1764 wxString
wxVariant::MakeString() const
1769 if (GetData()->Write(str
))
1772 return wxEmptyString
;
1777 void wxVariant::SetData(wxVariantData
* data
)
1779 if (m_data
) delete m_data
;
1784 // Returns a string representing the type of the variant,
1785 // e.g. "string", "bool", "stringlist", "list", "double", "long"
1786 wxString
wxVariant::GetType() const
1789 return wxString(wxT("null"));
1791 return m_data
->GetType();
1795 bool wxVariant::IsType(const wxString
& type
) const
1797 return (GetType() == type
);
1800 bool wxVariant::IsValueKindOf(const wxClassInfo
* type
) const
1802 wxClassInfo
* info
=m_data
->GetValueClassInfo();
1803 return info
? info
->IsKindOf(type
) : false ;
1808 double wxVariant::GetReal() const
1811 if (Convert(& value
))
1815 wxFAIL_MSG(wxT("Could not convert to a real number"));
1820 long wxVariant::GetInteger() const
1823 if (Convert(& value
))
1827 wxFAIL_MSG(wxT("Could not convert to an integer"));
1832 char wxVariant::GetChar() const
1835 if (Convert(& value
))
1839 wxFAIL_MSG(wxT("Could not convert to a char"));
1844 bool wxVariant::GetBool() const
1847 if (Convert(& value
))
1851 wxFAIL_MSG(wxT("Could not convert to a bool"));
1856 wxString
wxVariant::GetString() const
1859 if (!Convert(& value
))
1861 wxFAIL_MSG(wxT("Could not convert to a string"));
1867 void* wxVariant::GetVoidPtr() const
1869 wxASSERT( (GetType() == wxT("void*")) );
1871 return (void*) ((wxVariantDataVoidPtr
*) m_data
)->GetValue();
1874 wxObject
* wxVariant::GetWxObjectPtr()
1876 wxASSERT(wxIsKindOf(m_data
, wxVariantDataWxObjectPtr
));
1877 return (wxObject
*) ((wxVariantDataWxObjectPtr
*) m_data
)->GetValue();
1881 wxDateTime
wxVariant::GetDateTime() const
1884 if (!Convert(& value
))
1886 wxFAIL_MSG(wxT("Could not convert to a datetime"));
1891 #endif // wxUSE_DATETIME
1893 wxList
& wxVariant::GetList() const
1895 wxASSERT( (GetType() == wxT("list")) );
1897 return (wxList
&) ((wxVariantDataList
*) m_data
)->GetValue();
1900 wxStringList
& wxVariant::GetStringList() const
1902 wxASSERT( (GetType() == wxT("stringlist")) );
1904 return (wxStringList
&) ((wxVariantDataStringList
*) m_data
)->GetValue();
1908 void wxVariant::NullList()
1910 SetData(new wxVariantDataList());
1914 void wxVariant::Append(const wxVariant
& value
)
1916 wxList
& list
= GetList();
1918 list
.Append(new wxVariant(value
));
1921 // Insert at front of list
1922 void wxVariant::Insert(const wxVariant
& value
)
1924 wxList
& list
= GetList();
1926 list
.Insert(new wxVariant(value
));
1929 // Returns true if the variant is a member of the list
1930 bool wxVariant::Member(const wxVariant
& value
) const
1932 wxList
& list
= GetList();
1934 wxList::compatibility_iterator node
= list
.GetFirst();
1937 wxVariant
* other
= (wxVariant
*) node
->GetData();
1938 if (value
== *other
)
1940 node
= node
->GetNext();
1945 // Deletes the nth element of the list
1946 bool wxVariant::Delete(int item
)
1948 wxList
& list
= GetList();
1950 wxASSERT_MSG( (item
< (int) list
.GetCount()), wxT("Invalid index to Delete") );
1951 wxList::compatibility_iterator node
= list
.Item(item
);
1952 wxVariant
* variant
= (wxVariant
*) node
->GetData();
1959 void wxVariant::ClearList()
1961 if (!IsNull() && (GetType() == wxT("list")))
1963 ((wxVariantDataList
*) m_data
)->Clear();
1967 if (GetType() != wxT("list"))
1972 m_data
= new wxVariantDataList
;
1977 bool wxVariant::Convert(long* value
) const
1979 wxString
type(GetType());
1980 if (type
== wxT("double"))
1981 *value
= (long) (((wxVariantDataReal
*)GetData())->GetValue());
1982 else if (type
== wxT("long"))
1983 *value
= ((wxVariantDataLong
*)GetData())->GetValue();
1985 else if (type
== wxT("bool"))
1986 *value
= (long) (((wxVariantDataBool
*)GetData())->GetValue());
1988 else if (type
== wxT("string"))
1989 *value
= wxAtol((const wxChar
*) ((wxVariantDataString
*)GetData())->GetValue());
1996 bool wxVariant::Convert(bool* value
) const
1998 wxString
type(GetType());
1999 if (type
== wxT("double"))
2000 *value
= ((int) (((wxVariantDataReal
*)GetData())->GetValue()) != 0);
2001 else if (type
== wxT("long"))
2002 *value
= (((wxVariantDataLong
*)GetData())->GetValue() != 0);
2004 else if (type
== wxT("bool"))
2005 *value
= ((wxVariantDataBool
*)GetData())->GetValue();
2007 else if (type
== wxT("string"))
2009 wxString
val(((wxVariantDataString
*)GetData())->GetValue());
2011 if (val
== wxT("true") || val
== wxT("yes"))
2013 else if (val
== wxT("false") || val
== wxT("no"))
2024 bool wxVariant::Convert(double* value
) const
2026 wxString
type(GetType());
2027 if (type
== wxT("double"))
2028 *value
= ((wxVariantDataReal
*)GetData())->GetValue();
2029 else if (type
== wxT("long"))
2030 *value
= (double) (((wxVariantDataLong
*)GetData())->GetValue());
2032 else if (type
== wxT("bool"))
2033 *value
= (double) (((wxVariantDataBool
*)GetData())->GetValue());
2035 else if (type
== wxT("string"))
2036 *value
= (double) wxAtof((const wxChar
*) ((wxVariantDataString
*)GetData())->GetValue());
2043 bool wxVariant::Convert(char* value
) const
2045 wxString
type(GetType());
2046 if (type
== wxT("char"))
2047 *value
= ((wxVariantDataChar
*)GetData())->GetValue();
2048 else if (type
== wxT("long"))
2049 *value
= (char) (((wxVariantDataLong
*)GetData())->GetValue());
2051 else if (type
== wxT("bool"))
2052 *value
= (char) (((wxVariantDataBool
*)GetData())->GetValue());
2060 bool wxVariant::Convert(wxString
* value
) const
2062 *value
= MakeString();
2067 bool wxVariant::Convert(wxDateTime
* value
) const
2069 wxString
type(GetType());
2070 if (type
== wxT("datetime"))
2072 *value
= ((wxVariantDataDateTime
*)GetData())->GetValue();
2075 // Fallback to string conversion
2077 return Convert(&val
) &&
2078 (value
->ParseDateTime(val
) || value
->ParseDate(val
));
2080 #endif // wxUSE_DATETIME