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"));
197 #if WXWIN_COMPATIBILITY_2_4
200 * wxVariantDataStringList
203 class WXDLLIMPEXP_BASE wxVariantDataStringList
: public wxVariantData
205 DECLARE_DYNAMIC_CLASS(wxVariantDataStringList
)
207 wxVariantDataStringList() {}
208 wxVariantDataStringList(const wxStringList
& list
) { m_value
= list
; }
210 wxStringList
& GetValue() const { return (wxStringList
&) m_value
; }
211 void SetValue(const wxStringList
& value
);
213 virtual void Copy(wxVariantData
& data
);
214 virtual bool Eq(wxVariantData
& data
) const;
215 #if wxUSE_STD_IOSTREAM
216 virtual bool Write(wxSTD ostream
& str
) const;
218 virtual bool Write(wxString
& str
) const;
219 #if wxUSE_STD_IOSTREAM
220 virtual bool Read(wxSTD istream
& str
);
222 virtual bool Read(wxString
& str
);
223 virtual wxString
GetType() const { return wxT("stringlist"); };
226 wxStringList m_value
;
229 IMPLEMENT_DYNAMIC_CLASS(wxVariantDataStringList
, wxVariantData
)
231 void wxVariantDataStringList::SetValue(const wxStringList
& value
)
236 void wxVariantDataStringList::Copy(wxVariantData
& data
)
238 wxASSERT_MSG( (data
.GetType() == wxT("stringlist")), wxT("wxVariantDataStringList::Copy: Can't copy to this type of data") );
240 wxVariantDataStringList
& listData
= (wxVariantDataStringList
&) data
;
242 listData
.m_value
= m_value
;
245 bool wxVariantDataStringList::Eq(wxVariantData
& data
) const
247 wxASSERT_MSG( (data
.GetType() == wxT("stringlist")), wxT("wxVariantDataStringList::Eq: argument mismatch") );
249 wxVariantDataStringList
& listData
= (wxVariantDataStringList
&) data
;
250 wxStringList::compatibility_iterator node1
= m_value
.GetFirst();
251 wxStringList::compatibility_iterator node2
= listData
.GetValue().GetFirst();
252 while (node1
&& node2
)
254 wxString
str1 ( node1
->GetData() );
255 wxString
str2 ( node2
->GetData() );
258 node1
= node1
->GetNext();
259 node2
= node2
->GetNext();
261 if (node1
|| node2
) return false;
265 #if wxUSE_STD_IOSTREAM
266 bool wxVariantDataStringList::Write(wxSTD ostream
& str
) const
270 str
<< (const char*) s
.mb_str();
275 bool wxVariantDataStringList::Write(wxString
& str
) const
278 wxStringList::compatibility_iterator node
= m_value
.GetFirst();
281 const wxChar
* s
= node
->GetData();
282 if (node
!= m_value
.GetFirst())
285 node
= node
->GetNext();
291 #if wxUSE_STD_IOSTREAM
292 bool wxVariantDataStringList::Read(wxSTD istream
& WXUNUSED(str
))
294 wxFAIL_MSG(wxT("Unimplemented"));
300 bool wxVariantDataStringList::Read(wxString
& WXUNUSED(str
))
302 wxFAIL_MSG(wxT("Unimplemented"));
313 class WXDLLIMPEXP_BASE wxVariantDataLong
: public wxVariantData
315 DECLARE_DYNAMIC_CLASS(wxVariantDataLong
)
317 wxVariantDataLong() { m_value
= 0; }
318 wxVariantDataLong(long value
) { m_value
= value
; }
320 inline long GetValue() const { return m_value
; }
321 inline void SetValue(long value
) { m_value
= value
; }
323 virtual void Copy(wxVariantData
& data
);
324 virtual bool Eq(wxVariantData
& data
) const;
326 virtual bool Read(wxString
& str
);
327 virtual bool Write(wxString
& str
) const;
328 #if wxUSE_STD_IOSTREAM
329 virtual bool Read(wxSTD istream
& str
);
330 virtual bool Write(wxSTD ostream
& str
) const;
333 virtual bool Read(wxInputStream
& str
);
334 virtual bool Write(wxOutputStream
&str
) const;
335 #endif // wxUSE_STREAMS
337 virtual wxString
GetType() const { return wxT("long"); };
343 IMPLEMENT_DYNAMIC_CLASS(wxVariantDataLong
, wxVariantData
)
345 void wxVariantDataLong::Copy(wxVariantData
& data
)
347 wxASSERT_MSG( (data
.GetType() == wxT("long")), wxT("wxVariantDataLong::Copy: Can't copy to this type of data") );
349 wxVariantDataLong
& otherData
= (wxVariantDataLong
&) data
;
351 otherData
.m_value
= m_value
;
354 bool wxVariantDataLong::Eq(wxVariantData
& data
) const
356 wxASSERT_MSG( (data
.GetType() == wxT("long")), wxT("wxVariantDataLong::Eq: argument mismatch") );
358 wxVariantDataLong
& otherData
= (wxVariantDataLong
&) data
;
360 return (otherData
.m_value
== m_value
);
363 #if wxUSE_STD_IOSTREAM
364 bool wxVariantDataLong::Write(wxSTD ostream
& str
) const
368 str
<< (const char*) s
.mb_str();
373 bool wxVariantDataLong::Write(wxString
& str
) const
375 str
.Printf(wxT("%ld"), m_value
);
379 #if wxUSE_STD_IOSTREAM
380 bool wxVariantDataLong::Read(wxSTD istream
& str
)
388 bool wxVariantDataLong::Write(wxOutputStream
& str
) const
390 wxTextOutputStream
s(str
);
392 s
.Write32((size_t)m_value
);
396 bool wxVariantDataLong::Read(wxInputStream
& str
)
398 wxTextInputStream
s(str
);
399 m_value
= s
.Read32();
402 #endif // wxUSE_STREAMS
404 bool wxVariantDataLong::Read(wxString
& str
)
406 m_value
= wxAtol((const wxChar
*) str
);
414 class WXDLLIMPEXP_BASE wxVariantDataReal
: public wxVariantData
416 DECLARE_DYNAMIC_CLASS(wxVariantDataReal
)
418 wxVariantDataReal() { m_value
= 0.0; }
419 wxVariantDataReal(double value
) { m_value
= value
; }
421 inline double GetValue() const { return m_value
; }
422 inline void SetValue(double value
) { m_value
= value
; }
424 virtual void Copy(wxVariantData
& data
);
425 virtual bool Eq(wxVariantData
& data
) const;
426 virtual bool Read(wxString
& str
);
427 #if wxUSE_STD_IOSTREAM
428 virtual bool Write(wxSTD ostream
& str
) const;
430 virtual bool Write(wxString
& str
) const;
431 #if wxUSE_STD_IOSTREAM
432 virtual bool Read(wxSTD istream
& str
);
435 virtual bool Read(wxInputStream
& str
);
436 virtual bool Write(wxOutputStream
&str
) const;
437 #endif // wxUSE_STREAMS
438 virtual wxString
GetType() const { return wxT("double"); };
444 IMPLEMENT_DYNAMIC_CLASS(wxVariantDataReal
, wxVariantData
)
446 void wxVariantDataReal::Copy(wxVariantData
& data
)
448 wxASSERT_MSG( (data
.GetType() == wxT("double")), wxT("wxVariantDataReal::Copy: Can't copy to this type of data") );
450 wxVariantDataReal
& otherData
= (wxVariantDataReal
&) data
;
452 otherData
.m_value
= m_value
;
455 bool wxVariantDataReal::Eq(wxVariantData
& data
) const
457 wxASSERT_MSG( (data
.GetType() == wxT("double")), wxT("wxVariantDataReal::Eq: argument mismatch") );
459 wxVariantDataReal
& otherData
= (wxVariantDataReal
&) data
;
461 return (otherData
.m_value
== m_value
);
464 #if wxUSE_STD_IOSTREAM
465 bool wxVariantDataReal::Write(wxSTD ostream
& str
) const
469 str
<< (const char*) s
.mb_str();
474 bool wxVariantDataReal::Write(wxString
& str
) const
476 str
.Printf(wxT("%.4f"), m_value
);
480 #if wxUSE_STD_IOSTREAM
481 bool wxVariantDataReal::Read(wxSTD istream
& str
)
489 bool wxVariantDataReal::Write(wxOutputStream
& str
) const
491 wxTextOutputStream
s(str
);
492 s
.WriteDouble((double)m_value
);
496 bool wxVariantDataReal::Read(wxInputStream
& str
)
498 wxTextInputStream
s(str
);
499 m_value
= (float)s
.ReadDouble();
502 #endif // wxUSE_STREAMS
504 bool wxVariantDataReal::Read(wxString
& str
)
506 m_value
= wxAtof((const wxChar
*) str
);
515 class WXDLLIMPEXP_BASE wxVariantDataBool
: public wxVariantData
517 DECLARE_DYNAMIC_CLASS(wxVariantDataBool
)
519 wxVariantDataBool() { m_value
= 0; }
520 wxVariantDataBool(bool value
) { m_value
= value
; }
522 inline bool GetValue() const { return m_value
; }
523 inline void SetValue(bool value
) { m_value
= value
; }
525 virtual void Copy(wxVariantData
& data
);
526 virtual bool Eq(wxVariantData
& data
) const;
527 #if wxUSE_STD_IOSTREAM
528 virtual bool Write(wxSTD ostream
& str
) const;
530 virtual bool Write(wxString
& str
) const;
531 virtual bool Read(wxString
& str
);
532 #if wxUSE_STD_IOSTREAM
533 virtual bool Read(wxSTD istream
& str
);
536 virtual bool Read(wxInputStream
& str
);
537 virtual bool Write(wxOutputStream
& str
) const;
538 #endif // wxUSE_STREAMS
539 virtual wxString
GetType() const { return wxT("bool"); };
545 IMPLEMENT_DYNAMIC_CLASS(wxVariantDataBool
, wxVariantData
)
547 void wxVariantDataBool::Copy(wxVariantData
& data
)
549 wxASSERT_MSG( (data
.GetType() == wxT("bool")), wxT("wxVariantDataBool::Copy: Can't copy to this type of data") );
551 wxVariantDataBool
& otherData
= (wxVariantDataBool
&) data
;
553 otherData
.m_value
= m_value
;
556 bool wxVariantDataBool::Eq(wxVariantData
& data
) const
558 wxASSERT_MSG( (data
.GetType() == wxT("bool")), wxT("wxVariantDataBool::Eq: argument mismatch") );
560 wxVariantDataBool
& otherData
= (wxVariantDataBool
&) data
;
562 return (otherData
.m_value
== m_value
);
565 #if wxUSE_STD_IOSTREAM
566 bool wxVariantDataBool::Write(wxSTD ostream
& str
) const
570 str
<< (const char*) s
.mb_str();
575 bool wxVariantDataBool::Write(wxString
& str
) const
577 str
.Printf(wxT("%d"), (int) m_value
);
581 #if wxUSE_STD_IOSTREAM
582 bool wxVariantDataBool::Read(wxSTD istream
& WXUNUSED(str
))
584 wxFAIL_MSG(wxT("Unimplemented"));
585 // str >> (long) m_value;
591 bool wxVariantDataBool::Write(wxOutputStream
& str
) const
593 wxTextOutputStream
s(str
);
599 bool wxVariantDataBool::Read(wxInputStream
& str
)
601 wxTextInputStream
s(str
);
603 m_value
= s
.Read8() != 0;
606 #endif // wxUSE_STREAMS
608 bool wxVariantDataBool::Read(wxString
& str
)
610 m_value
= (wxAtol((const wxChar
*) str
) != 0);
619 class WXDLLIMPEXP_BASE wxVariantDataChar
: public wxVariantData
621 DECLARE_DYNAMIC_CLASS(wxVariantDataChar
)
623 wxVariantDataChar() { m_value
= 0; }
624 wxVariantDataChar(char value
) { m_value
= value
; }
626 inline char GetValue() const { return m_value
; }
627 inline void SetValue(char value
) { m_value
= value
; }
629 virtual void Copy(wxVariantData
& data
);
630 virtual bool Eq(wxVariantData
& data
) const;
631 #if wxUSE_STD_IOSTREAM
632 virtual bool Read(wxSTD istream
& str
);
633 virtual bool Write(wxSTD ostream
& str
) const;
635 virtual bool Read(wxString
& str
);
636 virtual bool Write(wxString
& str
) const;
638 virtual bool Read(wxInputStream
& str
);
639 virtual bool Write(wxOutputStream
& str
) const;
640 #endif // wxUSE_STREAMS
641 virtual wxString
GetType() const { return wxT("char"); };
647 IMPLEMENT_DYNAMIC_CLASS(wxVariantDataChar
, wxVariantData
)
649 void wxVariantDataChar::Copy(wxVariantData
& data
)
651 wxASSERT_MSG( (data
.GetType() == wxT("char")), wxT("wxVariantDataChar::Copy: Can't copy to this type of data") );
653 wxVariantDataChar
& otherData
= (wxVariantDataChar
&) data
;
655 otherData
.m_value
= m_value
;
658 bool wxVariantDataChar::Eq(wxVariantData
& data
) const
660 wxASSERT_MSG( (data
.GetType() == wxT("char")), wxT("wxVariantDataChar::Eq: argument mismatch") );
662 wxVariantDataChar
& otherData
= (wxVariantDataChar
&) data
;
664 return (otherData
.m_value
== m_value
);
667 #if wxUSE_STD_IOSTREAM
668 bool wxVariantDataChar::Write(wxSTD ostream
& str
) const
672 str
<< (const char*) s
.mb_str();
677 bool wxVariantDataChar::Write(wxString
& str
) const
679 str
.Printf(wxT("%c"), m_value
);
683 #if wxUSE_STD_IOSTREAM
684 bool wxVariantDataChar::Read(wxSTD istream
& WXUNUSED(str
))
686 wxFAIL_MSG(wxT("Unimplemented"));
693 bool wxVariantDataChar::Write(wxOutputStream
& str
) const
695 wxTextOutputStream
s(str
);
701 bool wxVariantDataChar::Read(wxInputStream
& str
)
703 wxTextInputStream
s(str
);
708 #endif // wxUSE_STREAMS
710 bool wxVariantDataChar::Read(wxString
& str
)
712 m_value
= str
.ToAscii()[0u];
717 * wxVariantDataString
720 class WXDLLIMPEXP_BASE wxVariantDataString
: public wxVariantData
722 DECLARE_DYNAMIC_CLASS(wxVariantDataString
)
724 wxVariantDataString() { }
725 wxVariantDataString(const wxString
& value
) { m_value
= value
; }
727 inline wxString
GetValue() const { return m_value
; }
728 inline void SetValue(const wxString
& value
) { m_value
= value
; }
730 virtual void Copy(wxVariantData
& data
);
731 virtual bool Eq(wxVariantData
& data
) const;
732 #if wxUSE_STD_IOSTREAM
733 virtual bool Write(wxSTD ostream
& str
) const;
735 virtual bool Read(wxString
& str
);
736 virtual bool Write(wxString
& str
) const;
737 #if wxUSE_STD_IOSTREAM
738 virtual bool Read(wxSTD istream
& str
);
741 virtual bool Read(wxInputStream
& str
);
742 virtual bool Write(wxOutputStream
& str
) const;
743 #endif // wxUSE_STREAMS
744 virtual wxString
GetType() const { return wxT("string"); };
750 void wxVariantDataString::Copy(wxVariantData
& data
)
752 wxASSERT_MSG( (data
.GetType() == wxT("string")), wxT("wxVariantDataString::Copy: Can't copy to this type of data") );
754 wxVariantDataString
& otherData
= (wxVariantDataString
&) data
;
756 otherData
.m_value
= m_value
;
759 bool wxVariantDataString::Eq(wxVariantData
& data
) const
761 wxASSERT_MSG( (data
.GetType() == wxT("string")), wxT("wxVariantDataString::Eq: argument mismatch") );
763 wxVariantDataString
& otherData
= (wxVariantDataString
&) data
;
765 return (otherData
.m_value
== m_value
);
768 #if wxUSE_STD_IOSTREAM
769 bool wxVariantDataString::Write(wxSTD ostream
& str
) const
771 str
<< (const char*) m_value
.mb_str();
776 bool wxVariantDataString::Write(wxString
& str
) const
782 #if wxUSE_STD_IOSTREAM
783 bool wxVariantDataString::Read(wxSTD istream
& str
)
791 bool wxVariantDataString::Write(wxOutputStream
& str
) const
793 // why doesn't wxOutputStream::operator<< take "const wxString&"
794 wxTextOutputStream
s(str
);
795 s
.WriteString(m_value
);
799 bool wxVariantDataString::Read(wxInputStream
& str
)
801 wxTextInputStream
s(str
);
803 m_value
= s
.ReadString();
806 #endif // wxUSE_STREAMS
808 bool wxVariantDataString::Read(wxString
& str
)
814 IMPLEMENT_DYNAMIC_CLASS(wxVariantDataString
, wxVariantData
)
817 * wxVariantDataVoidPtr
820 class wxVariantDataVoidPtr
: public wxVariantData
822 DECLARE_DYNAMIC_CLASS(wxVariantDataVoidPtr
)
824 wxVariantDataVoidPtr() { }
825 wxVariantDataVoidPtr(void* value
) { m_value
= value
; }
827 inline void* GetValue() const { return m_value
; }
828 inline void SetValue(void* value
) { m_value
= value
; }
830 virtual void Copy(wxVariantData
& data
);
831 virtual bool Eq(wxVariantData
& data
) const;
832 #if wxUSE_STD_IOSTREAM
833 virtual bool Write(wxSTD ostream
& str
) const;
835 virtual bool Write(wxString
& str
) const;
836 #if wxUSE_STD_IOSTREAM
837 virtual bool Read(wxSTD istream
& str
);
839 virtual bool Read(wxString
& str
);
840 virtual wxString
GetType() const { return wxT("void*"); };
841 virtual wxVariantData
* Clone() { return new wxVariantDataVoidPtr
; }
846 DECLARE_NO_COPY_CLASS(wxVariantDataVoidPtr
)
849 IMPLEMENT_DYNAMIC_CLASS(wxVariantDataVoidPtr
, wxVariantData
)
851 void wxVariantDataVoidPtr::Copy(wxVariantData
& data
)
853 wxASSERT_MSG( (data
.GetType() == wxT("void*")), wxT("wxVariantDataVoidPtr::Copy: Can't copy to this type of data") );
855 wxVariantDataVoidPtr
& otherData
= (wxVariantDataVoidPtr
&) data
;
857 otherData
.m_value
= m_value
;
860 bool wxVariantDataVoidPtr::Eq(wxVariantData
& data
) const
862 wxASSERT_MSG( (data
.GetType() == wxT("void*")), wxT("wxVariantDataVoidPtr::Eq: argument mismatch") );
864 wxVariantDataVoidPtr
& otherData
= (wxVariantDataVoidPtr
&) data
;
866 return (otherData
.m_value
== m_value
);
869 #if wxUSE_STD_IOSTREAM
870 bool wxVariantDataVoidPtr::Write(wxSTD ostream
& str
) const
874 str
<< (const char*) s
.mb_str();
879 bool wxVariantDataVoidPtr::Write(wxString
& str
) const
881 str
.Printf(wxT("%ld"), (long) m_value
);
885 #if wxUSE_STD_IOSTREAM
886 bool wxVariantDataVoidPtr::Read(wxSTD istream
& WXUNUSED(str
))
893 bool wxVariantDataVoidPtr::Read(wxString
& WXUNUSED(str
))
900 * wxVariantDataWxObjectPtr
903 class wxVariantDataWxObjectPtr
: public wxVariantData
905 DECLARE_DYNAMIC_CLASS(wxVariantDataWxObjectPtr
)
907 wxVariantDataWxObjectPtr() { }
908 wxVariantDataWxObjectPtr(wxObject
* value
) { m_value
= value
; }
910 inline wxObject
* GetValue() const { return m_value
; }
911 inline void SetValue(wxObject
* value
) { m_value
= value
; }
913 virtual void Copy(wxVariantData
& data
);
914 virtual bool Eq(wxVariantData
& data
) const;
915 #if wxUSE_STD_IOSTREAM
916 virtual bool Write(wxSTD ostream
& str
) const;
918 virtual bool Write(wxString
& str
) const;
919 #if wxUSE_STD_IOSTREAM
920 virtual bool Read(wxSTD istream
& str
);
922 virtual bool Read(wxString
& str
);
923 virtual wxString
GetType() const ;
924 virtual wxVariantData
* Clone() { return new wxVariantDataWxObjectPtr
; }
926 virtual wxClassInfo
* GetValueClassInfo() ;
930 DECLARE_NO_COPY_CLASS(wxVariantDataWxObjectPtr
)
933 IMPLEMENT_DYNAMIC_CLASS(wxVariantDataWxObjectPtr
, wxVariantData
)
935 void wxVariantDataWxObjectPtr::Copy(wxVariantData
& data
)
937 wxASSERT_MSG( wxIsKindOf((&data
), wxVariantDataWxObjectPtr
) ,\
938 wxT("wxVariantDataWxObjectPtr::Copy: Can't copy to this type of data") \
941 wxVariantDataWxObjectPtr
& otherData
= (wxVariantDataWxObjectPtr
&) data
;
943 otherData
.m_value
= m_value
;
946 bool wxVariantDataWxObjectPtr::Eq(wxVariantData
& data
) const
948 wxASSERT_MSG( wxIsKindOf((&data
), wxVariantDataWxObjectPtr
), wxT("wxVariantDataWxObjectPtr::Eq: argument mismatch") );
950 wxVariantDataWxObjectPtr
& otherData
= (wxVariantDataWxObjectPtr
&) data
;
952 return (otherData
.m_value
== m_value
);
955 wxString
wxVariantDataWxObjectPtr::GetType() const
957 wxString
returnVal(wxT("wxObject"));
959 returnVal
= m_value
->GetClassInfo()->GetClassName();
964 wxClassInfo
* wxVariantDataWxObjectPtr::GetValueClassInfo()
966 wxClassInfo
* returnVal
=NULL
;
968 if (m_value
) returnVal
= m_value
->GetClassInfo();
973 #if wxUSE_STD_IOSTREAM
974 bool wxVariantDataWxObjectPtr::Write(wxSTD ostream
& str
) const
978 str
<< (const char*) s
.mb_str();
983 bool wxVariantDataWxObjectPtr::Write(wxString
& str
) const
985 str
.Printf(wxT("%s(%ld)"), GetType().c_str(), (long) m_value
);
989 #if wxUSE_STD_IOSTREAM
990 bool wxVariantDataWxObjectPtr::Read(wxSTD istream
& WXUNUSED(str
))
997 bool wxVariantDataWxObjectPtr::Read(wxString
& WXUNUSED(str
))
1005 * wxVariantDataDateTime
1010 class wxVariantDataDateTime
: public wxVariantData
1012 DECLARE_DYNAMIC_CLASS(wxVariantDataDateTime
)
1015 wxVariantDataDateTime() { }
1016 wxVariantDataDateTime(const wxDateTime
& value
) { m_value
= value
; }
1018 wxVariantDataDateTime(const TIME_STRUCT
* valptr
)
1019 { m_value
= wxDateTime(valptr
->hour
, valptr
->minute
, valptr
->second
); }
1020 wxVariantDataDateTime(const DATE_STRUCT
* valptr
)
1021 { m_value
= wxDateTime(valptr
->day
, (wxDateTime::Month
) (valptr
->month
- 1),valptr
->year
); }
1022 wxVariantDataDateTime(const TIMESTAMP_STRUCT
* valptr
)
1023 { m_value
= wxDateTime(valptr
->day
, (wxDateTime::Month
) (valptr
->month
- 1), valptr
->year
,
1024 valptr
->hour
, valptr
->minute
, valptr
->second
, (wxDateTime::wxDateTime_t
)valptr
->fraction
); }
1027 inline wxDateTime
GetValue() const { return m_value
; }
1028 inline void SetValue(const wxDateTime
& value
) { m_value
= value
; }
1030 virtual void Copy(wxVariantData
& data
);
1031 virtual bool Eq(wxVariantData
& data
) const;
1032 #if wxUSE_STD_IOSTREAM
1033 virtual bool Write(wxSTD ostream
& str
) const;
1035 virtual bool Write(wxString
& str
) const;
1036 #if wxUSE_STD_IOSTREAM
1037 virtual bool Read(wxSTD istream
& str
);
1039 virtual bool Read(wxString
& str
);
1040 virtual wxString
GetType() const { return wxT("datetime"); };
1041 virtual wxVariantData
* Clone() { return new wxVariantDataDateTime
; }
1048 IMPLEMENT_DYNAMIC_CLASS(wxVariantDataDateTime
, wxVariantData
)
1050 void wxVariantDataDateTime::Copy(wxVariantData
& data
)
1052 wxASSERT_MSG( (data
.GetType() == wxT("datetime")), wxT("wxVariantDataDateTime::Copy: Can't copy to this type of data") );
1054 wxVariantDataDateTime
& otherData
= (wxVariantDataDateTime
&) data
;
1056 otherData
.m_value
= m_value
;
1060 bool wxVariantDataDateTime::Eq(wxVariantData
& data
) const
1062 wxASSERT_MSG( (data
.GetType() == wxT("datetime")), wxT("wxVariantDataDateTime::Eq: argument mismatch") );
1064 wxVariantDataDateTime
& otherData
= (wxVariantDataDateTime
&) data
;
1066 return (otherData
.m_value
== m_value
);
1070 #if wxUSE_STD_IOSTREAM
1071 bool wxVariantDataDateTime::Write(wxSTD ostream
& str
) const
1079 bool wxVariantDataDateTime::Write(wxString
& str
) const
1081 str
= m_value
.Format();
1086 #if wxUSE_STD_IOSTREAM
1087 bool wxVariantDataDateTime::Read(wxSTD istream
& WXUNUSED(str
))
1095 bool wxVariantDataDateTime::Read(wxString
& str
)
1097 if(! m_value
.ParseDateTime(str
))
1102 #endif // wxUSE_DATETIME
1104 // ----------------------------------------------------------------------------
1105 // wxVariantDataArrayString
1106 // ----------------------------------------------------------------------------
1108 class wxVariantDataArrayString
: public wxVariantData
1111 wxVariantDataArrayString() { }
1112 wxVariantDataArrayString(const wxArrayString
& value
) { m_value
= value
; }
1114 wxArrayString
GetValue() const { return m_value
; }
1115 void SetValue(const wxArrayString
& value
) { m_value
= value
; }
1117 virtual void Copy(wxVariantData
& data
);
1118 virtual bool Eq(wxVariantData
& data
) const;
1119 #if wxUSE_STD_IOSTREAM
1120 virtual bool Write(wxSTD ostream
& str
) const;
1122 virtual bool Write(wxString
& str
) const;
1123 #if wxUSE_STD_IOSTREAM
1124 virtual bool Read(wxSTD istream
& str
);
1126 virtual bool Read(wxString
& str
);
1127 virtual wxString
GetType() const { return wxT("arrstring"); };
1128 virtual wxVariantData
* Clone() { return new wxVariantDataArrayString
; }
1131 wxArrayString m_value
;
1133 DECLARE_DYNAMIC_CLASS(wxVariantDataArrayString
)
1136 IMPLEMENT_DYNAMIC_CLASS(wxVariantDataArrayString
, wxVariantData
)
1138 void wxVariantDataArrayString::Copy(wxVariantData
& data
)
1140 wxASSERT_MSG( data
.GetType() == GetType(), wxT("wxVariantDataArrayString::Copy: Can't copy to this type of data") );
1142 wxVariantDataArrayString
& otherData
= (wxVariantDataArrayString
&) data
;
1144 otherData
.m_value
= m_value
;
1148 bool wxVariantDataArrayString::Eq(wxVariantData
& data
) const
1150 wxASSERT_MSG( data
.GetType() == GetType(), wxT("wxVariantDataArrayString::Eq: argument mismatch") );
1152 wxVariantDataArrayString
& otherData
= (wxVariantDataArrayString
&) data
;
1154 return otherData
.m_value
== m_value
;
1158 #if wxUSE_STD_IOSTREAM
1159 bool wxVariantDataArrayString::Write(wxSTD ostream
& str
) const
1167 bool wxVariantDataArrayString::Write(wxString
& str
) const
1169 size_t count
= m_value
.GetCount();
1170 for ( size_t n
= 0; n
< count
; n
++ )
1182 #if wxUSE_STD_IOSTREAM
1183 bool wxVariantDataArrayString::Read(wxSTD istream
& WXUNUSED(str
))
1191 bool wxVariantDataArrayString::Read(wxString
& str
)
1193 wxStringTokenizer
tk(str
, _T(";"));
1194 while ( tk
.HasMoreTokens() )
1196 m_value
.Add(tk
.GetNextToken());
1208 IMPLEMENT_DYNAMIC_CLASS(wxVariant
, wxObject
)
1210 // Construction & destruction
1211 wxVariant::wxVariant()
1213 m_data
= (wxVariantData
*) NULL
;
1216 wxVariant::wxVariant(double val
, const wxString
& name
)
1218 m_data
= new wxVariantDataReal(val
);
1222 wxVariant::wxVariant(long val
, const wxString
& name
)
1224 m_data
= new wxVariantDataLong(val
);
1229 wxVariant::wxVariant(bool val
, const wxString
& name
)
1231 m_data
= new wxVariantDataBool(val
);
1236 wxVariant::wxVariant(char val
, const wxString
& name
)
1238 m_data
= new wxVariantDataChar(val
);
1242 wxVariant::wxVariant(const wxString
& val
, const wxString
& name
)
1244 m_data
= new wxVariantDataString(val
);
1248 wxVariant::wxVariant(const wxChar
* val
, const wxString
& name
)
1250 m_data
= new wxVariantDataString(wxString(val
));
1254 #if WXWIN_COMPATIBILITY_2_4
1256 wxVariant::wxVariant(const wxStringList
& val
, const wxString
& name
)
1258 m_data
= new wxVariantDataStringList(val
);
1264 wxVariant::wxVariant(const wxList
& val
, const wxString
& name
) // List of variants
1266 m_data
= new wxVariantDataList(val
);
1270 wxVariant::wxVariant( void* val
, const wxString
& name
)
1272 m_data
= new wxVariantDataVoidPtr(val
);
1276 wxVariant::wxVariant( wxObject
* val
, const wxString
& name
)
1278 m_data
= new wxVariantDataWxObjectPtr(val
);
1283 wxVariant::wxVariant(const wxDateTime
& val
, const wxString
& name
) // Date
1285 m_data
= new wxVariantDataDateTime(val
);
1288 #endif // wxUSE_DATETIME
1291 wxVariant::wxVariant(const TIME_STRUCT
* valptr
, const wxString
& name
) // Date
1293 m_data
= new wxVariantDataDateTime(valptr
);
1297 wxVariant::wxVariant(const TIMESTAMP_STRUCT
* valptr
, const wxString
& name
) // Date
1299 m_data
= new wxVariantDataDateTime(valptr
);
1303 wxVariant::wxVariant(const DATE_STRUCT
* valptr
, const wxString
& name
) // Date
1305 m_data
= new wxVariantDataDateTime(valptr
);
1308 #endif // wxUSE_ODBC
1310 wxVariant::wxVariant(const wxArrayString
& val
, const wxString
& name
) // Strings
1312 m_data
= new wxVariantDataArrayString(val
);
1316 wxVariant::wxVariant(const wxVariant
& variant
)
1319 if (!variant
.IsNull())
1321 m_data
= (wxVariantData
*) variant
.GetData()->GetClassInfo()->CreateObject();
1322 variant
.m_data
->Copy(*m_data
);
1325 m_data
= (wxVariantData
*) NULL
;
1326 m_name
= variant
.m_name
;
1329 wxVariant::wxVariant(wxVariantData
* data
, const wxString
& name
) // User-defined data
1335 wxVariant::~wxVariant()
1341 // Make NULL (i.e. delete the data)
1342 void wxVariant::MakeNull()
1348 // Generic operators
1350 void wxVariant::operator= (const wxVariant
& variant
)
1352 if (variant
.IsNull())
1358 if (IsNull() || (GetType() != variant
.GetType()))
1362 m_data
= (wxVariantData
*) variant
.GetData()->GetClassInfo()->CreateObject();
1365 variant
.GetData()->Copy(* GetData());
1367 m_name
= variant
.m_name
;
1370 // Assignment using data, e.g.
1371 // myVariant = new wxStringVariantData("hello")
1372 void wxVariant::operator= (wxVariantData
* variantData
)
1375 m_data
= variantData
;
1378 bool wxVariant::operator== (const wxVariant
& variant
) const
1380 if (IsNull() || variant
.IsNull())
1381 return (IsNull() == variant
.IsNull());
1383 return (GetData()->Eq(* variant
.GetData()));
1386 bool wxVariant::operator!= (const wxVariant
& variant
) const
1388 return (!(*this == variant
));
1392 // Specific operators
1393 bool wxVariant::operator== (double value
) const
1396 if (!Convert(&thisValue
))
1399 return (value
== thisValue
);
1402 bool wxVariant::operator!= (double value
) const
1404 return (!((*this) == value
));
1407 void wxVariant::operator= (double value
)
1409 if (GetType() == wxT("double"))
1411 ((wxVariantDataReal
*)GetData())->SetValue(value
);
1417 m_data
= new wxVariantDataReal(value
);
1421 bool wxVariant::operator== (long value
) const
1424 if (!Convert(&thisValue
))
1427 return (value
== thisValue
);
1430 bool wxVariant::operator!= (long value
) const
1432 return (!((*this) == value
));
1435 void wxVariant::operator= (long value
)
1437 if (GetType() == wxT("long"))
1439 ((wxVariantDataLong
*)GetData())->SetValue(value
);
1445 m_data
= new wxVariantDataLong(value
);
1449 bool wxVariant::operator== (char value
) const
1452 if (!Convert(&thisValue
))
1455 return (value
== thisValue
);
1458 bool wxVariant::operator!= (char value
) const
1460 return (!((*this) == value
));
1463 void wxVariant::operator= (char value
)
1465 if (GetType() == wxT("char"))
1467 ((wxVariantDataChar
*)GetData())->SetValue(value
);
1473 m_data
= new wxVariantDataChar(value
);
1478 bool wxVariant::operator== (bool value
) const
1481 if (!Convert(&thisValue
))
1484 return (value
== thisValue
);
1487 bool wxVariant::operator!= (bool value
) const
1489 return (!((*this) == value
));
1492 void wxVariant::operator= (bool value
)
1494 if (GetType() == wxT("bool"))
1496 ((wxVariantDataBool
*)GetData())->SetValue(value
);
1502 m_data
= new wxVariantDataBool(value
);
1507 bool wxVariant::operator== (const wxString
& value
) const
1510 if (!Convert(&thisValue
))
1513 return value
== thisValue
;
1516 bool wxVariant::operator!= (const wxString
& value
) const
1518 return (!((*this) == value
));
1521 void wxVariant::operator= (const wxString
& value
)
1523 if (GetType() == wxT("string"))
1525 ((wxVariantDataString
*)GetData())->SetValue(value
);
1531 m_data
= new wxVariantDataString(value
);
1535 void wxVariant::operator= (const wxChar
* value
)
1537 if (GetType() == wxT("string"))
1539 ((wxVariantDataString
*)GetData())->SetValue(wxString(value
));
1545 m_data
= new wxVariantDataString(wxString(value
));
1549 #if WXWIN_COMPATIBILITY_2_4
1551 bool wxVariant::operator== (const wxStringList
& value
) const
1553 wxASSERT_MSG( (GetType() == wxT("stringlist")), wxT("Invalid type for == operator") );
1555 wxVariantDataStringList
other(value
);
1556 return (m_data
->Eq(other
));
1559 bool wxVariant::operator!= (const wxStringList
& value
) const
1561 wxASSERT_MSG( (GetType() == wxT("stringlist")), wxT("Invalid type for == operator") );
1563 wxVariantDataStringList
other(value
);
1564 return !(m_data
->Eq(other
));
1567 void wxVariant::operator= (const wxStringList
& value
)
1569 if (GetType() == wxT("stringlist"))
1571 ((wxVariantDataStringList
*)GetData())->SetValue(value
);
1577 m_data
= new wxVariantDataStringList(value
);
1583 bool wxVariant::operator== (const wxList
& value
) const
1585 wxASSERT_MSG( (GetType() == wxT("list")), wxT("Invalid type for == operator") );
1587 wxVariantDataList
other(value
);
1588 return (m_data
->Eq(other
));
1591 bool wxVariant::operator!= (const wxList
& value
) const
1593 return (!((*this) == value
));
1596 void wxVariant::operator= (const wxList
& value
)
1598 if (GetType() == wxT("list"))
1600 ((wxVariantDataList
*)GetData())->SetValue(value
);
1606 m_data
= new wxVariantDataList(value
);
1610 bool wxVariant::operator== (void* value
) const
1612 return (value
== ((wxVariantDataVoidPtr
*)GetData())->GetValue());
1615 bool wxVariant::operator!= (void* value
) const
1617 return (!((*this) == (void*) value
));
1620 void wxVariant::operator= (void* value
)
1622 if (GetType() == wxT("void*"))
1624 ((wxVariantDataVoidPtr
*)GetData())->SetValue(value
);
1630 m_data
= new wxVariantDataVoidPtr(value
);
1635 bool wxVariant::operator== (const wxDateTime
& value
) const
1637 wxDateTime thisValue
;
1638 if (!Convert(&thisValue
))
1641 return value
.IsEqualTo(thisValue
);
1644 bool wxVariant::operator!= (const wxDateTime
& value
) const
1646 return (!((*this) == value
));
1649 void wxVariant::operator= (const wxDateTime
& value
)
1651 if (GetType() == wxT("datetime"))
1653 ((wxVariantDataDateTime
*)GetData())->SetValue(value
);
1659 m_data
= new wxVariantDataDateTime(value
);
1662 #endif // wxUSE_DATETIME
1665 void wxVariant::operator= (const DATE_STRUCT
* value
)
1669 m_data
= new wxVariantDataDateTime(value
);
1673 void wxVariant::operator= (const TIME_STRUCT
* value
)
1677 m_data
= new wxVariantDataDateTime(value
);
1681 void wxVariant::operator= (const TIMESTAMP_STRUCT
* value
)
1685 m_data
= new wxVariantDataDateTime(value
);
1688 #endif // wxUSE_ODBC
1690 bool wxVariant::operator==(const wxArrayString
& WXUNUSED(value
)) const
1692 wxFAIL_MSG( _T("TODO") );
1697 bool wxVariant::operator!=(const wxArrayString
& value
) const
1699 return !(*this == value
);
1702 void wxVariant::operator=(const wxArrayString
& value
)
1704 if (GetType() == wxT("arrstring"))
1706 ((wxVariantDataArrayString
*)GetData())->SetValue(value
);
1711 m_data
= new wxVariantDataArrayString(value
);
1715 wxArrayString
wxVariant::GetArrayString() const
1717 if ( GetType() == wxT("arrstring") )
1718 return ((wxVariantDataArrayString
*)GetData())->GetValue();
1720 return wxArrayString();
1724 // Treat a list variant as an array
1725 wxVariant
wxVariant::operator[] (size_t idx
) const
1727 #if WXWIN_COMPATIBILITY_2_4
1728 wxASSERT_MSG( (GetType() == wxT("list") || GetType() == wxT("stringlist")), wxT("Invalid type for array operator") );
1730 wxASSERT_MSG( GetType() == wxT("list"), wxT("Invalid type for array operator") );
1733 if (GetType() == wxT("list"))
1735 wxVariantDataList
* data
= (wxVariantDataList
*) m_data
;
1736 wxASSERT_MSG( (idx
< (size_t) data
->GetValue().GetCount()), wxT("Invalid index for array") );
1737 return * (wxVariant
*) (data
->GetValue().Item(idx
)->GetData());
1739 #if WXWIN_COMPATIBILITY_2_4
1740 else if (GetType() == wxT("stringlist"))
1742 wxVariantDataStringList
* data
= (wxVariantDataStringList
*) m_data
;
1743 wxASSERT_MSG( (idx
< (size_t) data
->GetValue().GetCount()), wxT("Invalid index for array") );
1745 wxString
str( (const wxChar
*) (data
->GetValue().Item(idx
)->GetData()) );
1746 wxVariant
variant( str
);
1750 return wxNullVariant
;
1753 wxVariant
& wxVariant::operator[] (size_t idx
)
1755 // We can't return a reference to a variant for a string list, since the string
1756 // is actually stored as a char*, not a variant.
1758 wxASSERT_MSG( (GetType() == wxT("list")), wxT("Invalid type for array operator") );
1760 wxVariantDataList
* data
= (wxVariantDataList
*) m_data
;
1761 wxASSERT_MSG( (idx
< (size_t) data
->GetValue().GetCount()), wxT("Invalid index for array") );
1763 return * (wxVariant
*) (data
->GetValue().Item(idx
)->GetData());
1766 // Return the number of elements in a list
1767 int wxVariant::GetCount() const
1769 #if WXWIN_COMPATIBILITY_2_4
1770 wxASSERT_MSG( (GetType() == wxT("list") || GetType() == wxT("stringlist")), wxT("Invalid type for GetCount()") );
1772 wxASSERT_MSG( GetType() == wxT("list"), wxT("Invalid type for GetCount()") );
1775 if (GetType() == wxT("list"))
1777 wxVariantDataList
* data
= (wxVariantDataList
*) m_data
;
1778 return data
->GetValue().GetCount();
1780 #if WXWIN_COMPATIBILITY_2_4
1781 else if (GetType() == wxT("stringlist"))
1783 wxVariantDataStringList
* data
= (wxVariantDataStringList
*) m_data
;
1784 return data
->GetValue().GetCount();
1790 wxString
wxVariant::MakeString() const
1795 if (GetData()->Write(str
))
1798 return wxEmptyString
;
1803 void wxVariant::SetData(wxVariantData
* data
)
1805 if (m_data
) delete m_data
;
1810 // Returns a string representing the type of the variant,
1811 // e.g. "string", "bool", "list", "double", "long"
1812 wxString
wxVariant::GetType() const
1815 return wxString(wxT("null"));
1817 return m_data
->GetType();
1821 bool wxVariant::IsType(const wxString
& type
) const
1823 return (GetType() == type
);
1826 bool wxVariant::IsValueKindOf(const wxClassInfo
* type
) const
1828 wxClassInfo
* info
=m_data
->GetValueClassInfo();
1829 return info
? info
->IsKindOf(type
) : false ;
1834 double wxVariant::GetReal() const
1837 if (Convert(& value
))
1841 wxFAIL_MSG(wxT("Could not convert to a real number"));
1846 long wxVariant::GetInteger() const
1849 if (Convert(& value
))
1853 wxFAIL_MSG(wxT("Could not convert to an integer"));
1858 char wxVariant::GetChar() const
1861 if (Convert(& value
))
1865 wxFAIL_MSG(wxT("Could not convert to a char"));
1870 bool wxVariant::GetBool() const
1873 if (Convert(& value
))
1877 wxFAIL_MSG(wxT("Could not convert to a bool"));
1882 wxString
wxVariant::GetString() const
1885 if (!Convert(& value
))
1887 wxFAIL_MSG(wxT("Could not convert to a string"));
1893 void* wxVariant::GetVoidPtr() const
1895 wxASSERT( (GetType() == wxT("void*")) );
1897 return (void*) ((wxVariantDataVoidPtr
*) m_data
)->GetValue();
1900 wxObject
* wxVariant::GetWxObjectPtr()
1902 wxASSERT(wxIsKindOf(m_data
, wxVariantDataWxObjectPtr
));
1903 return (wxObject
*) ((wxVariantDataWxObjectPtr
*) m_data
)->GetValue();
1907 wxDateTime
wxVariant::GetDateTime() const
1910 if (!Convert(& value
))
1912 wxFAIL_MSG(wxT("Could not convert to a datetime"));
1917 #endif // wxUSE_DATETIME
1919 wxList
& wxVariant::GetList() const
1921 wxASSERT( (GetType() == wxT("list")) );
1923 return (wxList
&) ((wxVariantDataList
*) m_data
)->GetValue();
1926 #if WXWIN_COMPATIBILITY_2_4
1928 wxStringList
& wxVariant::GetStringList() const
1930 wxASSERT( (GetType() == wxT("stringlist")) );
1932 return (wxStringList
&) ((wxVariantDataStringList
*) m_data
)->GetValue();
1938 void wxVariant::NullList()
1940 SetData(new wxVariantDataList());
1944 void wxVariant::Append(const wxVariant
& value
)
1946 wxList
& list
= GetList();
1948 list
.Append(new wxVariant(value
));
1951 // Insert at front of list
1952 void wxVariant::Insert(const wxVariant
& value
)
1954 wxList
& list
= GetList();
1956 list
.Insert(new wxVariant(value
));
1959 // Returns true if the variant is a member of the list
1960 bool wxVariant::Member(const wxVariant
& value
) const
1962 wxList
& list
= GetList();
1964 wxList::compatibility_iterator node
= list
.GetFirst();
1967 wxVariant
* other
= (wxVariant
*) node
->GetData();
1968 if (value
== *other
)
1970 node
= node
->GetNext();
1975 // Deletes the nth element of the list
1976 bool wxVariant::Delete(int item
)
1978 wxList
& list
= GetList();
1980 wxASSERT_MSG( (item
< (int) list
.GetCount()), wxT("Invalid index to Delete") );
1981 wxList::compatibility_iterator node
= list
.Item(item
);
1982 wxVariant
* variant
= (wxVariant
*) node
->GetData();
1989 void wxVariant::ClearList()
1991 if (!IsNull() && (GetType() == wxT("list")))
1993 ((wxVariantDataList
*) m_data
)->Clear();
1997 if (!GetType().IsSameAs(wxT("list")))
2002 m_data
= new wxVariantDataList
;
2007 bool wxVariant::Convert(long* value
) const
2009 wxString
type(GetType());
2010 if (type
== wxT("double"))
2011 *value
= (long) (((wxVariantDataReal
*)GetData())->GetValue());
2012 else if (type
== wxT("long"))
2013 *value
= ((wxVariantDataLong
*)GetData())->GetValue();
2015 else if (type
== wxT("bool"))
2016 *value
= (long) (((wxVariantDataBool
*)GetData())->GetValue());
2018 else if (type
== wxT("string"))
2019 *value
= wxAtol((const wxChar
*) ((wxVariantDataString
*)GetData())->GetValue());
2026 bool wxVariant::Convert(bool* value
) const
2028 wxString
type(GetType());
2029 if (type
== wxT("double"))
2030 *value
= ((int) (((wxVariantDataReal
*)GetData())->GetValue()) != 0);
2031 else if (type
== wxT("long"))
2032 *value
= (((wxVariantDataLong
*)GetData())->GetValue() != 0);
2034 else if (type
== wxT("bool"))
2035 *value
= ((wxVariantDataBool
*)GetData())->GetValue();
2037 else if (type
== wxT("string"))
2039 wxString
val(((wxVariantDataString
*)GetData())->GetValue());
2041 if (val
== wxT("true") || val
== wxT("yes"))
2043 else if (val
== wxT("false") || val
== wxT("no"))
2054 bool wxVariant::Convert(double* value
) const
2056 wxString
type(GetType());
2057 if (type
== wxT("double"))
2058 *value
= ((wxVariantDataReal
*)GetData())->GetValue();
2059 else if (type
== wxT("long"))
2060 *value
= (double) (((wxVariantDataLong
*)GetData())->GetValue());
2062 else if (type
== wxT("bool"))
2063 *value
= (double) (((wxVariantDataBool
*)GetData())->GetValue());
2065 else if (type
== wxT("string"))
2066 *value
= (double) wxAtof((const wxChar
*) ((wxVariantDataString
*)GetData())->GetValue());
2073 bool wxVariant::Convert(char* value
) const
2075 wxString
type(GetType());
2076 if (type
== wxT("char"))
2077 *value
= ((wxVariantDataChar
*)GetData())->GetValue();
2078 else if (type
== wxT("long"))
2079 *value
= (char) (((wxVariantDataLong
*)GetData())->GetValue());
2081 else if (type
== wxT("bool"))
2082 *value
= (char) (((wxVariantDataBool
*)GetData())->GetValue());
2090 bool wxVariant::Convert(wxString
* value
) const
2092 *value
= MakeString();
2097 bool wxVariant::Convert(wxDateTime
* value
) const
2099 wxString
type(GetType());
2100 if (type
== wxT("datetime"))
2102 *value
= ((wxVariantDataDateTime
*)GetData())->GetValue();
2105 // Fallback to string conversion
2107 return Convert(&val
) &&
2108 (value
->ParseDateTime(val
) || value
->ParseDate(val
));
2110 #endif // wxUSE_DATETIME