1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/common/variant.cpp
3 // Purpose: wxVariant class, container for any type
4 // Author: Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // For compilers that support precompilation, includes "wx/wx.h".
13 #include "wx/wxprec.h"
19 #include "wx/variant.h"
22 #include "wx/string.h"
25 #include "wx/stream.h"
29 #if wxUSE_STD_IOSTREAM
37 #if defined(__MWERKS__) && __MSL__ >= 0x6000
43 #include "wx/txtstrm.h"
46 #include "wx/string.h"
47 #include "wx/tokenzr.h"
49 IMPLEMENT_ABSTRACT_CLASS(wxVariantData
, wxObject
)
51 wxVariant WXDLLIMPEXP_BASE wxNullVariant
;
57 class WXDLLIMPEXP_BASE wxVariantDataList
: public wxVariantData
59 DECLARE_DYNAMIC_CLASS(wxVariantDataList
)
61 wxVariantDataList() {}
62 wxVariantDataList(const wxList
& list
);
65 wxList
& GetValue() { return m_value
; }
66 void SetValue(const wxList
& value
) ;
68 virtual void Copy(wxVariantData
& data
);
69 virtual bool Eq(wxVariantData
& data
) const;
70 #if wxUSE_STD_IOSTREAM
71 virtual bool Write(wxSTD ostream
& str
) const;
73 virtual bool Write(wxString
& str
) const;
74 #if wxUSE_STD_IOSTREAM
75 virtual bool Read(wxSTD istream
& str
);
77 virtual bool Read(wxString
& str
);
78 virtual wxString
GetType() const { return wxT("list"); };
86 IMPLEMENT_DYNAMIC_CLASS(wxVariantDataList
, wxVariantData
)
88 wxVariantDataList::wxVariantDataList(const wxList
& list
)
93 wxVariantDataList::~wxVariantDataList()
98 void wxVariantDataList::SetValue(const wxList
& value
)
101 wxList::compatibility_iterator node
= value
.GetFirst();
104 wxVariant
* var
= (wxVariant
*) node
->GetData();
105 m_value
.Append(new wxVariant(*var
));
106 node
= node
->GetNext();
110 void wxVariantDataList::Clear()
112 wxList::compatibility_iterator node
= m_value
.GetFirst();
115 wxVariant
* var
= (wxVariant
*) node
->GetData();
117 node
= node
->GetNext();
122 void wxVariantDataList::Copy(wxVariantData
& data
)
124 wxASSERT_MSG( (data
.GetType() == wxT("list")), wxT("wxVariantDataList::Copy: Can't copy to this type of data") );
126 wxVariantDataList
& listData
= (wxVariantDataList
&) data
;
129 wxList::compatibility_iterator node
= m_value
.GetFirst();
132 wxVariant
* var
= (wxVariant
*) node
->GetData();
133 listData
.m_value
.Append(new wxVariant(*var
));
134 node
= node
->GetNext();
138 bool wxVariantDataList::Eq(wxVariantData
& data
) const
140 wxASSERT_MSG( (data
.GetType() == wxT("list")), wxT("wxVariantDataList::Eq: argument mismatch") );
142 wxVariantDataList
& listData
= (wxVariantDataList
&) data
;
143 wxList::compatibility_iterator node1
= m_value
.GetFirst();
144 wxList::compatibility_iterator node2
= listData
.GetValue().GetFirst();
145 while (node1
&& node2
)
147 wxVariant
* var1
= (wxVariant
*) node1
->GetData();
148 wxVariant
* var2
= (wxVariant
*) node2
->GetData();
149 if ((*var1
) != (*var2
))
151 node1
= node1
->GetNext();
152 node2
= node2
->GetNext();
154 if (node1
|| node2
) return false;
158 #if wxUSE_STD_IOSTREAM
159 bool wxVariantDataList::Write(wxSTD ostream
& str
) const
163 str
<< (const char*) s
.mb_str();
168 bool wxVariantDataList::Write(wxString
& str
) const
171 wxList::compatibility_iterator node
= m_value
.GetFirst();
174 wxVariant
* var
= (wxVariant
*) node
->GetData();
175 if (node
!= m_value
.GetFirst())
178 str
+= var
->MakeString();
179 node
= node
->GetNext();
185 #if wxUSE_STD_IOSTREAM
186 bool wxVariantDataList::Read(wxSTD istream
& WXUNUSED(str
))
188 wxFAIL_MSG(wxT("Unimplemented"));
194 bool wxVariantDataList::Read(wxString
& WXUNUSED(str
))
196 wxFAIL_MSG(wxT("Unimplemented"));
200 #if WXWIN_COMPATIBILITY_2_4
203 * wxVariantDataStringList
206 class WXDLLIMPEXP_BASE wxVariantDataStringList
: public wxVariantData
208 DECLARE_DYNAMIC_CLASS(wxVariantDataStringList
)
210 wxVariantDataStringList() {}
211 wxVariantDataStringList(const wxStringList
& list
) { m_value
= list
; }
213 wxStringList
& GetValue() const { return (wxStringList
&) m_value
; }
214 void SetValue(const wxStringList
& value
);
216 virtual void Copy(wxVariantData
& data
);
217 virtual bool Eq(wxVariantData
& data
) const;
218 #if wxUSE_STD_IOSTREAM
219 virtual bool Write(wxSTD ostream
& str
) const;
221 virtual bool Write(wxString
& str
) const;
222 #if wxUSE_STD_IOSTREAM
223 virtual bool Read(wxSTD istream
& str
);
225 virtual bool Read(wxString
& str
);
226 virtual wxString
GetType() const { return wxT("stringlist"); };
229 wxStringList m_value
;
232 IMPLEMENT_DYNAMIC_CLASS(wxVariantDataStringList
, wxVariantData
)
234 void wxVariantDataStringList::SetValue(const wxStringList
& value
)
239 void wxVariantDataStringList::Copy(wxVariantData
& data
)
241 wxASSERT_MSG( (data
.GetType() == wxT("stringlist")), wxT("wxVariantDataStringList::Copy: Can't copy to this type of data") );
243 wxVariantDataStringList
& listData
= (wxVariantDataStringList
&) data
;
245 listData
.m_value
= m_value
;
248 bool wxVariantDataStringList::Eq(wxVariantData
& data
) const
250 wxASSERT_MSG( (data
.GetType() == wxT("stringlist")), wxT("wxVariantDataStringList::Eq: argument mismatch") );
252 wxVariantDataStringList
& listData
= (wxVariantDataStringList
&) data
;
253 wxStringList::compatibility_iterator node1
= m_value
.GetFirst();
254 wxStringList::compatibility_iterator node2
= listData
.GetValue().GetFirst();
255 while (node1
&& node2
)
257 wxString
str1 ( node1
->GetData() );
258 wxString
str2 ( node2
->GetData() );
261 node1
= node1
->GetNext();
262 node2
= node2
->GetNext();
264 if (node1
|| node2
) return false;
268 #if wxUSE_STD_IOSTREAM
269 bool wxVariantDataStringList::Write(wxSTD ostream
& str
) const
273 str
<< (const char*) s
.mb_str();
278 bool wxVariantDataStringList::Write(wxString
& str
) const
281 wxStringList::compatibility_iterator node
= m_value
.GetFirst();
284 const wxChar
* s
= node
->GetData();
285 if (node
!= m_value
.GetFirst())
288 node
= node
->GetNext();
294 #if wxUSE_STD_IOSTREAM
295 bool wxVariantDataStringList::Read(wxSTD istream
& WXUNUSED(str
))
297 wxFAIL_MSG(wxT("Unimplemented"));
303 bool wxVariantDataStringList::Read(wxString
& WXUNUSED(str
))
305 wxFAIL_MSG(wxT("Unimplemented"));
316 class WXDLLIMPEXP_BASE wxVariantDataLong
: public wxVariantData
318 DECLARE_DYNAMIC_CLASS(wxVariantDataLong
)
320 wxVariantDataLong() { m_value
= 0; }
321 wxVariantDataLong(long value
) { m_value
= value
; }
323 inline long GetValue() const { return m_value
; }
324 inline void SetValue(long value
) { m_value
= value
; }
326 virtual void Copy(wxVariantData
& data
);
327 virtual bool Eq(wxVariantData
& data
) const;
329 virtual bool Read(wxString
& str
);
330 virtual bool Write(wxString
& str
) const;
331 #if wxUSE_STD_IOSTREAM
332 virtual bool Read(wxSTD istream
& str
);
333 virtual bool Write(wxSTD ostream
& str
) const;
336 virtual bool Read(wxInputStream
& str
);
337 virtual bool Write(wxOutputStream
&str
) const;
338 #endif // wxUSE_STREAMS
340 virtual wxString
GetType() const { return wxT("long"); };
346 IMPLEMENT_DYNAMIC_CLASS(wxVariantDataLong
, wxVariantData
)
348 void wxVariantDataLong::Copy(wxVariantData
& data
)
350 wxASSERT_MSG( (data
.GetType() == wxT("long")), wxT("wxVariantDataLong::Copy: Can't copy to this type of data") );
352 wxVariantDataLong
& otherData
= (wxVariantDataLong
&) data
;
354 otherData
.m_value
= m_value
;
357 bool wxVariantDataLong::Eq(wxVariantData
& data
) const
359 wxASSERT_MSG( (data
.GetType() == wxT("long")), wxT("wxVariantDataLong::Eq: argument mismatch") );
361 wxVariantDataLong
& otherData
= (wxVariantDataLong
&) data
;
363 return (otherData
.m_value
== m_value
);
366 #if wxUSE_STD_IOSTREAM
367 bool wxVariantDataLong::Write(wxSTD ostream
& str
) const
371 str
<< (const char*) s
.mb_str();
376 bool wxVariantDataLong::Write(wxString
& str
) const
378 str
.Printf(wxT("%ld"), m_value
);
382 #if wxUSE_STD_IOSTREAM
383 bool wxVariantDataLong::Read(wxSTD istream
& str
)
391 bool wxVariantDataLong::Write(wxOutputStream
& str
) const
393 wxTextOutputStream
s(str
);
395 s
.Write32((size_t)m_value
);
399 bool wxVariantDataLong::Read(wxInputStream
& str
)
401 wxTextInputStream
s(str
);
402 m_value
= s
.Read32();
405 #endif // wxUSE_STREAMS
407 bool wxVariantDataLong::Read(wxString
& str
)
409 m_value
= wxAtol((const wxChar
*) str
);
417 class WXDLLIMPEXP_BASE wxVariantDataReal
: public wxVariantData
419 DECLARE_DYNAMIC_CLASS(wxVariantDataReal
)
421 wxVariantDataReal() { m_value
= 0.0; }
422 wxVariantDataReal(double value
) { m_value
= value
; }
424 inline double GetValue() const { return m_value
; }
425 inline void SetValue(double value
) { m_value
= value
; }
427 virtual void Copy(wxVariantData
& data
);
428 virtual bool Eq(wxVariantData
& data
) const;
429 virtual bool Read(wxString
& str
);
430 #if wxUSE_STD_IOSTREAM
431 virtual bool Write(wxSTD ostream
& str
) const;
433 virtual bool Write(wxString
& str
) const;
434 #if wxUSE_STD_IOSTREAM
435 virtual bool Read(wxSTD istream
& str
);
438 virtual bool Read(wxInputStream
& str
);
439 virtual bool Write(wxOutputStream
&str
) const;
440 #endif // wxUSE_STREAMS
441 virtual wxString
GetType() const { return wxT("double"); };
447 IMPLEMENT_DYNAMIC_CLASS(wxVariantDataReal
, wxVariantData
)
449 void wxVariantDataReal::Copy(wxVariantData
& data
)
451 wxASSERT_MSG( (data
.GetType() == wxT("double")), wxT("wxVariantDataReal::Copy: Can't copy to this type of data") );
453 wxVariantDataReal
& otherData
= (wxVariantDataReal
&) data
;
455 otherData
.m_value
= m_value
;
458 bool wxVariantDataReal::Eq(wxVariantData
& data
) const
460 wxASSERT_MSG( (data
.GetType() == wxT("double")), wxT("wxVariantDataReal::Eq: argument mismatch") );
462 wxVariantDataReal
& otherData
= (wxVariantDataReal
&) data
;
464 return wxIsSameDouble(otherData
.m_value
, m_value
);
467 #if wxUSE_STD_IOSTREAM
468 bool wxVariantDataReal::Write(wxSTD ostream
& str
) const
472 str
<< (const char*) s
.mb_str();
477 bool wxVariantDataReal::Write(wxString
& str
) const
479 str
.Printf(wxT("%.14g"), m_value
);
483 #if wxUSE_STD_IOSTREAM
484 bool wxVariantDataReal::Read(wxSTD istream
& str
)
492 bool wxVariantDataReal::Write(wxOutputStream
& str
) const
494 wxTextOutputStream
s(str
);
495 s
.WriteDouble((double)m_value
);
499 bool wxVariantDataReal::Read(wxInputStream
& str
)
501 wxTextInputStream
s(str
);
502 m_value
= (float)s
.ReadDouble();
505 #endif // wxUSE_STREAMS
507 bool wxVariantDataReal::Read(wxString
& str
)
509 m_value
= wxAtof((const wxChar
*) str
);
518 class WXDLLIMPEXP_BASE wxVariantDataBool
: public wxVariantData
520 DECLARE_DYNAMIC_CLASS(wxVariantDataBool
)
522 wxVariantDataBool() { m_value
= 0; }
523 wxVariantDataBool(bool value
) { m_value
= value
; }
525 inline bool GetValue() const { return m_value
; }
526 inline void SetValue(bool value
) { m_value
= value
; }
528 virtual void Copy(wxVariantData
& data
);
529 virtual bool Eq(wxVariantData
& data
) const;
530 #if wxUSE_STD_IOSTREAM
531 virtual bool Write(wxSTD ostream
& str
) const;
533 virtual bool Write(wxString
& str
) const;
534 virtual bool Read(wxString
& str
);
535 #if wxUSE_STD_IOSTREAM
536 virtual bool Read(wxSTD istream
& str
);
539 virtual bool Read(wxInputStream
& str
);
540 virtual bool Write(wxOutputStream
& str
) const;
541 #endif // wxUSE_STREAMS
542 virtual wxString
GetType() const { return wxT("bool"); };
548 IMPLEMENT_DYNAMIC_CLASS(wxVariantDataBool
, wxVariantData
)
550 void wxVariantDataBool::Copy(wxVariantData
& data
)
552 wxASSERT_MSG( (data
.GetType() == wxT("bool")), wxT("wxVariantDataBool::Copy: Can't copy to this type of data") );
554 wxVariantDataBool
& otherData
= (wxVariantDataBool
&) data
;
556 otherData
.m_value
= m_value
;
559 bool wxVariantDataBool::Eq(wxVariantData
& data
) const
561 wxASSERT_MSG( (data
.GetType() == wxT("bool")), wxT("wxVariantDataBool::Eq: argument mismatch") );
563 wxVariantDataBool
& otherData
= (wxVariantDataBool
&) data
;
565 return (otherData
.m_value
== m_value
);
568 #if wxUSE_STD_IOSTREAM
569 bool wxVariantDataBool::Write(wxSTD ostream
& str
) const
573 str
<< (const char*) s
.mb_str();
578 bool wxVariantDataBool::Write(wxString
& str
) const
580 str
.Printf(wxT("%d"), (int) m_value
);
584 #if wxUSE_STD_IOSTREAM
585 bool wxVariantDataBool::Read(wxSTD istream
& WXUNUSED(str
))
587 wxFAIL_MSG(wxT("Unimplemented"));
588 // str >> (long) m_value;
594 bool wxVariantDataBool::Write(wxOutputStream
& str
) const
596 wxTextOutputStream
s(str
);
602 bool wxVariantDataBool::Read(wxInputStream
& str
)
604 wxTextInputStream
s(str
);
606 m_value
= s
.Read8() != 0;
609 #endif // wxUSE_STREAMS
611 bool wxVariantDataBool::Read(wxString
& str
)
613 m_value
= (wxAtol((const wxChar
*) str
) != 0);
622 class WXDLLIMPEXP_BASE wxVariantDataChar
: public wxVariantData
624 DECLARE_DYNAMIC_CLASS(wxVariantDataChar
)
626 wxVariantDataChar() { m_value
= 0; }
627 wxVariantDataChar(char value
) { m_value
= value
; }
629 inline char GetValue() const { return m_value
; }
630 inline void SetValue(char value
) { m_value
= value
; }
632 virtual void Copy(wxVariantData
& data
);
633 virtual bool Eq(wxVariantData
& data
) const;
634 #if wxUSE_STD_IOSTREAM
635 virtual bool Read(wxSTD istream
& str
);
636 virtual bool Write(wxSTD ostream
& str
) const;
638 virtual bool Read(wxString
& str
);
639 virtual bool Write(wxString
& str
) const;
641 virtual bool Read(wxInputStream
& str
);
642 virtual bool Write(wxOutputStream
& str
) const;
643 #endif // wxUSE_STREAMS
644 virtual wxString
GetType() const { return wxT("char"); };
650 IMPLEMENT_DYNAMIC_CLASS(wxVariantDataChar
, wxVariantData
)
652 void wxVariantDataChar::Copy(wxVariantData
& data
)
654 wxASSERT_MSG( (data
.GetType() == wxT("char")), wxT("wxVariantDataChar::Copy: Can't copy to this type of data") );
656 wxVariantDataChar
& otherData
= (wxVariantDataChar
&) data
;
658 otherData
.m_value
= m_value
;
661 bool wxVariantDataChar::Eq(wxVariantData
& data
) const
663 wxASSERT_MSG( (data
.GetType() == wxT("char")), wxT("wxVariantDataChar::Eq: argument mismatch") );
665 wxVariantDataChar
& otherData
= (wxVariantDataChar
&) data
;
667 return (otherData
.m_value
== m_value
);
670 #if wxUSE_STD_IOSTREAM
671 bool wxVariantDataChar::Write(wxSTD ostream
& str
) const
675 str
<< (const char*) s
.mb_str();
680 bool wxVariantDataChar::Write(wxString
& str
) const
682 str
.Printf(wxT("%c"), m_value
);
686 #if wxUSE_STD_IOSTREAM
687 bool wxVariantDataChar::Read(wxSTD istream
& WXUNUSED(str
))
689 wxFAIL_MSG(wxT("Unimplemented"));
696 bool wxVariantDataChar::Write(wxOutputStream
& str
) const
698 wxTextOutputStream
s(str
);
704 bool wxVariantDataChar::Read(wxInputStream
& str
)
706 wxTextInputStream
s(str
);
711 #endif // wxUSE_STREAMS
713 bool wxVariantDataChar::Read(wxString
& str
)
715 m_value
= str
.ToAscii()[size_t(0)];
720 * wxVariantDataString
723 class WXDLLIMPEXP_BASE wxVariantDataString
: public wxVariantData
725 DECLARE_DYNAMIC_CLASS(wxVariantDataString
)
727 wxVariantDataString() { }
728 wxVariantDataString(const wxString
& value
) { m_value
= value
; }
730 inline wxString
GetValue() const { return m_value
; }
731 inline void SetValue(const wxString
& value
) { m_value
= value
; }
733 virtual void Copy(wxVariantData
& data
);
734 virtual bool Eq(wxVariantData
& data
) const;
735 #if wxUSE_STD_IOSTREAM
736 virtual bool Write(wxSTD ostream
& str
) const;
738 virtual bool Read(wxString
& str
);
739 virtual bool Write(wxString
& str
) const;
740 #if wxUSE_STD_IOSTREAM
741 virtual bool Read(wxSTD istream
& str
);
744 virtual bool Read(wxInputStream
& str
);
745 virtual bool Write(wxOutputStream
& str
) const;
746 #endif // wxUSE_STREAMS
747 virtual wxString
GetType() const { return wxT("string"); };
753 void wxVariantDataString::Copy(wxVariantData
& data
)
755 wxASSERT_MSG( (data
.GetType() == wxT("string")), wxT("wxVariantDataString::Copy: Can't copy to this type of data") );
757 wxVariantDataString
& otherData
= (wxVariantDataString
&) data
;
759 otherData
.m_value
= m_value
;
762 bool wxVariantDataString::Eq(wxVariantData
& data
) const
764 wxASSERT_MSG( (data
.GetType() == wxT("string")), wxT("wxVariantDataString::Eq: argument mismatch") );
766 wxVariantDataString
& otherData
= (wxVariantDataString
&) data
;
768 return (otherData
.m_value
== m_value
);
771 #if wxUSE_STD_IOSTREAM
772 bool wxVariantDataString::Write(wxSTD ostream
& str
) const
774 str
<< (const char*) m_value
.mb_str();
779 bool wxVariantDataString::Write(wxString
& str
) const
785 #if wxUSE_STD_IOSTREAM
786 bool wxVariantDataString::Read(wxSTD istream
& str
)
794 bool wxVariantDataString::Write(wxOutputStream
& str
) const
796 // why doesn't wxOutputStream::operator<< take "const wxString&"
797 wxTextOutputStream
s(str
);
798 s
.WriteString(m_value
);
802 bool wxVariantDataString::Read(wxInputStream
& str
)
804 wxTextInputStream
s(str
);
806 m_value
= s
.ReadLine();
809 #endif // wxUSE_STREAMS
811 bool wxVariantDataString::Read(wxString
& str
)
817 IMPLEMENT_DYNAMIC_CLASS(wxVariantDataString
, wxVariantData
)
820 * wxVariantDataVoidPtr
823 class wxVariantDataVoidPtr
: public wxVariantData
825 DECLARE_DYNAMIC_CLASS(wxVariantDataVoidPtr
)
827 wxVariantDataVoidPtr() { }
828 wxVariantDataVoidPtr(void* value
) { m_value
= value
; }
830 inline void* GetValue() const { return m_value
; }
831 inline void SetValue(void* value
) { m_value
= value
; }
833 virtual void Copy(wxVariantData
& data
);
834 virtual bool Eq(wxVariantData
& data
) const;
835 #if wxUSE_STD_IOSTREAM
836 virtual bool Write(wxSTD ostream
& str
) const;
838 virtual bool Write(wxString
& str
) const;
839 #if wxUSE_STD_IOSTREAM
840 virtual bool Read(wxSTD istream
& str
);
842 virtual bool Read(wxString
& str
);
843 virtual wxString
GetType() const { return wxT("void*"); };
844 virtual wxVariantData
* Clone() { return new wxVariantDataVoidPtr
; }
849 DECLARE_NO_COPY_CLASS(wxVariantDataVoidPtr
)
852 IMPLEMENT_DYNAMIC_CLASS(wxVariantDataVoidPtr
, wxVariantData
)
854 void wxVariantDataVoidPtr::Copy(wxVariantData
& data
)
856 wxASSERT_MSG( (data
.GetType() == wxT("void*")), wxT("wxVariantDataVoidPtr::Copy: Can't copy to this type of data") );
858 wxVariantDataVoidPtr
& otherData
= (wxVariantDataVoidPtr
&) data
;
860 otherData
.m_value
= m_value
;
863 bool wxVariantDataVoidPtr::Eq(wxVariantData
& data
) const
865 wxASSERT_MSG( (data
.GetType() == wxT("void*")), wxT("wxVariantDataVoidPtr::Eq: argument mismatch") );
867 wxVariantDataVoidPtr
& otherData
= (wxVariantDataVoidPtr
&) data
;
869 return (otherData
.m_value
== m_value
);
872 #if wxUSE_STD_IOSTREAM
873 bool wxVariantDataVoidPtr::Write(wxSTD ostream
& str
) const
877 str
<< (const char*) s
.mb_str();
882 bool wxVariantDataVoidPtr::Write(wxString
& str
) const
884 str
.Printf(wxT("%p"), m_value
);
888 #if wxUSE_STD_IOSTREAM
889 bool wxVariantDataVoidPtr::Read(wxSTD istream
& WXUNUSED(str
))
896 bool wxVariantDataVoidPtr::Read(wxString
& WXUNUSED(str
))
903 * wxVariantDataWxObjectPtr
906 class wxVariantDataWxObjectPtr
: public wxVariantData
908 DECLARE_DYNAMIC_CLASS(wxVariantDataWxObjectPtr
)
910 wxVariantDataWxObjectPtr() { }
911 wxVariantDataWxObjectPtr(wxObject
* value
) { m_value
= value
; }
913 inline wxObject
* GetValue() const { return m_value
; }
914 inline void SetValue(wxObject
* value
) { m_value
= value
; }
916 virtual void Copy(wxVariantData
& data
);
917 virtual bool Eq(wxVariantData
& data
) const;
918 #if wxUSE_STD_IOSTREAM
919 virtual bool Write(wxSTD ostream
& str
) const;
921 virtual bool Write(wxString
& str
) const;
922 #if wxUSE_STD_IOSTREAM
923 virtual bool Read(wxSTD istream
& str
);
925 virtual bool Read(wxString
& str
);
926 virtual wxString
GetType() const ;
927 virtual wxVariantData
* Clone() { return new wxVariantDataWxObjectPtr
; }
929 virtual wxClassInfo
* GetValueClassInfo() ;
933 DECLARE_NO_COPY_CLASS(wxVariantDataWxObjectPtr
)
936 IMPLEMENT_DYNAMIC_CLASS(wxVariantDataWxObjectPtr
, wxVariantData
)
938 void wxVariantDataWxObjectPtr::Copy(wxVariantData
& data
)
940 wxASSERT_MSG( wxIsKindOf((&data
), wxVariantDataWxObjectPtr
) ,\
941 wxT("wxVariantDataWxObjectPtr::Copy: Can't copy to this type of data") \
944 wxVariantDataWxObjectPtr
& otherData
= (wxVariantDataWxObjectPtr
&) data
;
946 otherData
.m_value
= m_value
;
949 bool wxVariantDataWxObjectPtr::Eq(wxVariantData
& data
) const
951 wxASSERT_MSG( wxIsKindOf((&data
), wxVariantDataWxObjectPtr
), wxT("wxVariantDataWxObjectPtr::Eq: argument mismatch") );
953 wxVariantDataWxObjectPtr
& otherData
= (wxVariantDataWxObjectPtr
&) data
;
955 return (otherData
.m_value
== m_value
);
958 wxString
wxVariantDataWxObjectPtr::GetType() const
960 wxString
returnVal(wxT("wxObject"));
962 returnVal
= m_value
->GetClassInfo()->GetClassName();
967 wxClassInfo
* wxVariantDataWxObjectPtr::GetValueClassInfo()
969 wxClassInfo
* returnVal
=NULL
;
971 if (m_value
) returnVal
= m_value
->GetClassInfo();
976 #if wxUSE_STD_IOSTREAM
977 bool wxVariantDataWxObjectPtr::Write(wxSTD ostream
& str
) const
981 str
<< (const char*) s
.mb_str();
986 bool wxVariantDataWxObjectPtr::Write(wxString
& str
) const
988 str
.Printf(wxT("%s(%p)"), GetType().c_str(), wx_static_cast(void*, m_value
));
992 #if wxUSE_STD_IOSTREAM
993 bool wxVariantDataWxObjectPtr::Read(wxSTD istream
& WXUNUSED(str
))
1000 bool wxVariantDataWxObjectPtr::Read(wxString
& WXUNUSED(str
))
1008 * wxVariantDataDateTime
1013 class wxVariantDataDateTime
: public wxVariantData
1015 DECLARE_DYNAMIC_CLASS(wxVariantDataDateTime
)
1018 wxVariantDataDateTime() { }
1019 wxVariantDataDateTime(const wxDateTime
& value
) { m_value
= value
; }
1021 wxVariantDataDateTime(const TIME_STRUCT
* valptr
)
1022 { m_value
= wxDateTime(valptr
->hour
, valptr
->minute
, valptr
->second
); }
1023 wxVariantDataDateTime(const DATE_STRUCT
* valptr
)
1024 { m_value
= wxDateTime(valptr
->day
, (wxDateTime::Month
) (valptr
->month
- 1),valptr
->year
); }
1025 wxVariantDataDateTime(const TIMESTAMP_STRUCT
* valptr
)
1026 { m_value
= wxDateTime(valptr
->day
, (wxDateTime::Month
) (valptr
->month
- 1), valptr
->year
,
1027 valptr
->hour
, valptr
->minute
, valptr
->second
, (wxDateTime::wxDateTime_t
)valptr
->fraction
); }
1030 inline wxDateTime
GetValue() const { return m_value
; }
1031 inline void SetValue(const wxDateTime
& value
) { m_value
= value
; }
1033 virtual void Copy(wxVariantData
& data
);
1034 virtual bool Eq(wxVariantData
& data
) const;
1035 #if wxUSE_STD_IOSTREAM
1036 virtual bool Write(wxSTD ostream
& str
) const;
1038 virtual bool Write(wxString
& str
) const;
1039 #if wxUSE_STD_IOSTREAM
1040 virtual bool Read(wxSTD istream
& str
);
1042 virtual bool Read(wxString
& str
);
1043 virtual wxString
GetType() const { return wxT("datetime"); };
1044 virtual wxVariantData
* Clone() { return new wxVariantDataDateTime
; }
1051 IMPLEMENT_DYNAMIC_CLASS(wxVariantDataDateTime
, wxVariantData
)
1053 void wxVariantDataDateTime::Copy(wxVariantData
& data
)
1055 wxASSERT_MSG( (data
.GetType() == wxT("datetime")), wxT("wxVariantDataDateTime::Copy: Can't copy to this type of data") );
1057 wxVariantDataDateTime
& otherData
= (wxVariantDataDateTime
&) data
;
1059 otherData
.m_value
= m_value
;
1063 bool wxVariantDataDateTime::Eq(wxVariantData
& data
) const
1065 wxASSERT_MSG( (data
.GetType() == wxT("datetime")), wxT("wxVariantDataDateTime::Eq: argument mismatch") );
1067 wxVariantDataDateTime
& otherData
= (wxVariantDataDateTime
&) data
;
1069 return (otherData
.m_value
== m_value
);
1073 #if wxUSE_STD_IOSTREAM
1074 bool wxVariantDataDateTime::Write(wxSTD ostream
& WXUNUSED(str
)) const
1082 bool wxVariantDataDateTime::Write(wxString
& str
) const
1084 str
= m_value
.Format();
1089 #if wxUSE_STD_IOSTREAM
1090 bool wxVariantDataDateTime::Read(wxSTD istream
& WXUNUSED(str
))
1098 bool wxVariantDataDateTime::Read(wxString
& str
)
1100 if(! m_value
.ParseDateTime(str
))
1105 #endif // wxUSE_DATETIME
1107 // ----------------------------------------------------------------------------
1108 // wxVariantDataArrayString
1109 // ----------------------------------------------------------------------------
1111 class wxVariantDataArrayString
: public wxVariantData
1114 wxVariantDataArrayString() { }
1115 wxVariantDataArrayString(const wxArrayString
& value
) { m_value
= value
; }
1117 wxArrayString
GetValue() const { return m_value
; }
1118 void SetValue(const wxArrayString
& value
) { m_value
= value
; }
1120 virtual void Copy(wxVariantData
& data
);
1121 virtual bool Eq(wxVariantData
& data
) const;
1122 #if wxUSE_STD_IOSTREAM
1123 virtual bool Write(wxSTD ostream
& str
) const;
1125 virtual bool Write(wxString
& str
) const;
1126 #if wxUSE_STD_IOSTREAM
1127 virtual bool Read(wxSTD istream
& str
);
1129 virtual bool Read(wxString
& str
);
1130 virtual wxString
GetType() const { return wxT("arrstring"); };
1131 virtual wxVariantData
* Clone() { return new wxVariantDataArrayString
; }
1134 wxArrayString m_value
;
1136 DECLARE_DYNAMIC_CLASS(wxVariantDataArrayString
)
1139 IMPLEMENT_DYNAMIC_CLASS(wxVariantDataArrayString
, wxVariantData
)
1141 void wxVariantDataArrayString::Copy(wxVariantData
& data
)
1143 wxASSERT_MSG( data
.GetType() == GetType(), wxT("wxVariantDataArrayString::Copy: Can't copy to this type of data") );
1145 wxVariantDataArrayString
& otherData
= (wxVariantDataArrayString
&) data
;
1147 otherData
.m_value
= m_value
;
1151 bool wxVariantDataArrayString::Eq(wxVariantData
& data
) const
1153 wxASSERT_MSG( data
.GetType() == GetType(), wxT("wxVariantDataArrayString::Eq: argument mismatch") );
1155 wxVariantDataArrayString
& otherData
= (wxVariantDataArrayString
&) data
;
1157 return otherData
.m_value
== m_value
;
1161 #if wxUSE_STD_IOSTREAM
1162 bool wxVariantDataArrayString::Write(wxSTD ostream
& WXUNUSED(str
)) const
1170 bool wxVariantDataArrayString::Write(wxString
& str
) const
1172 size_t count
= m_value
.GetCount();
1173 for ( size_t n
= 0; n
< count
; n
++ )
1185 #if wxUSE_STD_IOSTREAM
1186 bool wxVariantDataArrayString::Read(wxSTD istream
& WXUNUSED(str
))
1194 bool wxVariantDataArrayString::Read(wxString
& str
)
1196 wxStringTokenizer
tk(str
, _T(";"));
1197 while ( tk
.HasMoreTokens() )
1199 m_value
.Add(tk
.GetNextToken());
1211 IMPLEMENT_DYNAMIC_CLASS(wxVariant
, wxObject
)
1213 // Construction & destruction
1214 wxVariant::wxVariant()
1216 m_data
= (wxVariantData
*) NULL
;
1219 wxVariant::wxVariant(double val
, const wxString
& name
)
1221 m_data
= new wxVariantDataReal(val
);
1225 wxVariant::wxVariant(long val
, const wxString
& name
)
1227 m_data
= new wxVariantDataLong(val
);
1232 wxVariant::wxVariant(bool val
, const wxString
& name
)
1234 m_data
= new wxVariantDataBool(val
);
1239 wxVariant::wxVariant(char val
, const wxString
& name
)
1241 m_data
= new wxVariantDataChar(val
);
1245 wxVariant::wxVariant(const wxString
& val
, const wxString
& name
)
1247 m_data
= new wxVariantDataString(val
);
1251 wxVariant::wxVariant(const wxChar
* val
, const wxString
& name
)
1253 m_data
= new wxVariantDataString(wxString(val
));
1257 #if WXWIN_COMPATIBILITY_2_4
1259 wxVariant::wxVariant(const wxStringList
& val
, const wxString
& name
)
1261 m_data
= new wxVariantDataStringList(val
);
1267 wxVariant::wxVariant(const wxList
& val
, const wxString
& name
) // List of variants
1269 m_data
= new wxVariantDataList(val
);
1273 wxVariant::wxVariant( void* val
, const wxString
& name
)
1275 m_data
= new wxVariantDataVoidPtr(val
);
1279 wxVariant::wxVariant( wxObject
* val
, const wxString
& name
)
1281 m_data
= new wxVariantDataWxObjectPtr(val
);
1286 wxVariant::wxVariant(const wxDateTime
& val
, const wxString
& name
) // Date
1288 m_data
= new wxVariantDataDateTime(val
);
1291 #endif // wxUSE_DATETIME
1294 wxVariant::wxVariant(const TIME_STRUCT
* valptr
, const wxString
& name
) // Date
1296 m_data
= new wxVariantDataDateTime(valptr
);
1300 wxVariant::wxVariant(const TIMESTAMP_STRUCT
* valptr
, const wxString
& name
) // Date
1302 m_data
= new wxVariantDataDateTime(valptr
);
1306 wxVariant::wxVariant(const DATE_STRUCT
* valptr
, const wxString
& name
) // Date
1308 m_data
= new wxVariantDataDateTime(valptr
);
1311 #endif // wxUSE_ODBC
1313 wxVariant::wxVariant(const wxArrayString
& val
, const wxString
& name
) // Strings
1315 m_data
= new wxVariantDataArrayString(val
);
1319 wxVariant::wxVariant(const wxVariant
& variant
)
1322 if (!variant
.IsNull())
1324 m_data
= (wxVariantData
*) variant
.GetData()->GetClassInfo()->CreateObject();
1325 variant
.m_data
->Copy(*m_data
);
1328 m_data
= (wxVariantData
*) NULL
;
1329 m_name
= variant
.m_name
;
1332 wxVariant::wxVariant(wxVariantData
* data
, const wxString
& name
) // User-defined data
1338 wxVariant::~wxVariant()
1344 // Make NULL (i.e. delete the data)
1345 void wxVariant::MakeNull()
1351 // Generic operators
1353 void wxVariant::operator= (const wxVariant
& variant
)
1355 if (variant
.IsNull())
1361 if (IsNull() || (GetType() != variant
.GetType()))
1365 m_data
= (wxVariantData
*) variant
.GetData()->GetClassInfo()->CreateObject();
1368 variant
.GetData()->Copy(* GetData());
1370 m_name
= variant
.m_name
;
1373 // Assignment using data, e.g.
1374 // myVariant = new wxStringVariantData("hello")
1375 void wxVariant::operator= (wxVariantData
* variantData
)
1378 m_data
= variantData
;
1381 bool wxVariant::operator== (const wxVariant
& variant
) const
1383 if (IsNull() || variant
.IsNull())
1384 return (IsNull() == variant
.IsNull());
1386 return (GetData()->Eq(* variant
.GetData()));
1389 bool wxVariant::operator!= (const wxVariant
& variant
) const
1391 return (!(*this == variant
));
1395 // Specific operators
1396 bool wxVariant::operator== (double value
) const
1399 if (!Convert(&thisValue
))
1402 return wxIsSameDouble(value
, thisValue
);
1405 bool wxVariant::operator!= (double value
) const
1407 return (!((*this) == value
));
1410 void wxVariant::operator= (double value
)
1412 if (GetType() == wxT("double"))
1414 ((wxVariantDataReal
*)GetData())->SetValue(value
);
1420 m_data
= new wxVariantDataReal(value
);
1424 bool wxVariant::operator== (long value
) const
1427 if (!Convert(&thisValue
))
1430 return (value
== thisValue
);
1433 bool wxVariant::operator!= (long value
) const
1435 return (!((*this) == value
));
1438 void wxVariant::operator= (long value
)
1440 if (GetType() == wxT("long"))
1442 ((wxVariantDataLong
*)GetData())->SetValue(value
);
1448 m_data
= new wxVariantDataLong(value
);
1452 bool wxVariant::operator== (char value
) const
1455 if (!Convert(&thisValue
))
1458 return (value
== thisValue
);
1461 bool wxVariant::operator!= (char value
) const
1463 return (!((*this) == value
));
1466 void wxVariant::operator= (char value
)
1468 if (GetType() == wxT("char"))
1470 ((wxVariantDataChar
*)GetData())->SetValue(value
);
1476 m_data
= new wxVariantDataChar(value
);
1481 bool wxVariant::operator== (bool value
) const
1484 if (!Convert(&thisValue
))
1487 return (value
== thisValue
);
1490 bool wxVariant::operator!= (bool value
) const
1492 return (!((*this) == value
));
1495 void wxVariant::operator= (bool value
)
1497 if (GetType() == wxT("bool"))
1499 ((wxVariantDataBool
*)GetData())->SetValue(value
);
1505 m_data
= new wxVariantDataBool(value
);
1510 bool wxVariant::operator== (const wxString
& value
) const
1513 if (!Convert(&thisValue
))
1516 return value
== thisValue
;
1519 bool wxVariant::operator!= (const wxString
& value
) const
1521 return (!((*this) == value
));
1524 void wxVariant::operator= (const wxString
& value
)
1526 if (GetType() == wxT("string"))
1528 ((wxVariantDataString
*)GetData())->SetValue(value
);
1534 m_data
= new wxVariantDataString(value
);
1538 void wxVariant::operator= (const wxChar
* value
)
1540 if (GetType() == wxT("string"))
1542 ((wxVariantDataString
*)GetData())->SetValue(wxString(value
));
1548 m_data
= new wxVariantDataString(wxString(value
));
1552 #if WXWIN_COMPATIBILITY_2_4
1554 bool wxVariant::operator== (const wxStringList
& value
) const
1556 wxASSERT_MSG( (GetType() == wxT("stringlist")), wxT("Invalid type for == operator") );
1558 wxVariantDataStringList
other(value
);
1559 return (m_data
->Eq(other
));
1562 bool wxVariant::operator!= (const wxStringList
& value
) const
1564 wxASSERT_MSG( (GetType() == wxT("stringlist")), wxT("Invalid type for == operator") );
1566 wxVariantDataStringList
other(value
);
1567 return !(m_data
->Eq(other
));
1570 void wxVariant::operator= (const wxStringList
& value
)
1572 if (GetType() == wxT("stringlist"))
1574 ((wxVariantDataStringList
*)GetData())->SetValue(value
);
1580 m_data
= new wxVariantDataStringList(value
);
1586 bool wxVariant::operator== (const wxList
& value
) const
1588 wxASSERT_MSG( (GetType() == wxT("list")), wxT("Invalid type for == operator") );
1590 wxVariantDataList
other(value
);
1591 return (m_data
->Eq(other
));
1594 bool wxVariant::operator!= (const wxList
& value
) const
1596 return (!((*this) == value
));
1599 void wxVariant::operator= (const wxList
& value
)
1601 if (GetType() == wxT("list"))
1603 ((wxVariantDataList
*)GetData())->SetValue(value
);
1609 m_data
= new wxVariantDataList(value
);
1613 bool wxVariant::operator== (void* value
) const
1615 return (value
== ((wxVariantDataVoidPtr
*)GetData())->GetValue());
1618 bool wxVariant::operator!= (void* value
) const
1620 return (!((*this) == (void*) value
));
1623 void wxVariant::operator= (void* value
)
1625 if (GetType() == wxT("void*"))
1627 ((wxVariantDataVoidPtr
*)GetData())->SetValue(value
);
1633 m_data
= new wxVariantDataVoidPtr(value
);
1638 bool wxVariant::operator== (const wxDateTime
& value
) const
1640 wxDateTime thisValue
;
1641 if (!Convert(&thisValue
))
1644 return value
.IsEqualTo(thisValue
);
1647 bool wxVariant::operator!= (const wxDateTime
& value
) const
1649 return (!((*this) == value
));
1652 void wxVariant::operator= (const wxDateTime
& value
)
1654 if (GetType() == wxT("datetime"))
1656 ((wxVariantDataDateTime
*)GetData())->SetValue(value
);
1662 m_data
= new wxVariantDataDateTime(value
);
1665 #endif // wxUSE_DATETIME
1668 void wxVariant::operator= (const DATE_STRUCT
* value
)
1672 m_data
= new wxVariantDataDateTime(value
);
1676 void wxVariant::operator= (const TIME_STRUCT
* value
)
1680 m_data
= new wxVariantDataDateTime(value
);
1684 void wxVariant::operator= (const TIMESTAMP_STRUCT
* value
)
1688 m_data
= new wxVariantDataDateTime(value
);
1691 #endif // wxUSE_ODBC
1693 bool wxVariant::operator==(const wxArrayString
& WXUNUSED(value
)) const
1695 wxFAIL_MSG( _T("TODO") );
1700 bool wxVariant::operator!=(const wxArrayString
& value
) const
1702 return !(*this == value
);
1705 void wxVariant::operator=(const wxArrayString
& value
)
1707 if (GetType() == wxT("arrstring"))
1709 ((wxVariantDataArrayString
*)GetData())->SetValue(value
);
1714 m_data
= new wxVariantDataArrayString(value
);
1718 wxArrayString
wxVariant::GetArrayString() const
1720 if ( GetType() == wxT("arrstring") )
1721 return ((wxVariantDataArrayString
*)GetData())->GetValue();
1723 return wxArrayString();
1727 // Treat a list variant as an array
1728 wxVariant
wxVariant::operator[] (size_t idx
) const
1730 #if WXWIN_COMPATIBILITY_2_4
1731 wxASSERT_MSG( (GetType() == wxT("list") || GetType() == wxT("stringlist")), wxT("Invalid type for array operator") );
1733 wxASSERT_MSG( GetType() == wxT("list"), wxT("Invalid type for array operator") );
1736 if (GetType() == wxT("list"))
1738 wxVariantDataList
* data
= (wxVariantDataList
*) m_data
;
1739 wxASSERT_MSG( (idx
< data
->GetValue().GetCount()), wxT("Invalid index for array") );
1740 return * (wxVariant
*) (data
->GetValue().Item(idx
)->GetData());
1742 #if WXWIN_COMPATIBILITY_2_4
1743 else if (GetType() == wxT("stringlist"))
1745 wxVariantDataStringList
* data
= (wxVariantDataStringList
*) m_data
;
1746 wxASSERT_MSG( (idx
< data
->GetValue().GetCount()), wxT("Invalid index for array") );
1748 wxString
str( (const wxChar
*) (data
->GetValue().Item(idx
)->GetData()) );
1749 wxVariant
variant( str
);
1753 return wxNullVariant
;
1756 wxVariant
& wxVariant::operator[] (size_t idx
)
1758 // We can't return a reference to a variant for a string list, since the string
1759 // is actually stored as a char*, not a variant.
1761 wxASSERT_MSG( (GetType() == wxT("list")), wxT("Invalid type for array operator") );
1763 wxVariantDataList
* data
= (wxVariantDataList
*) m_data
;
1764 wxASSERT_MSG( (idx
< data
->GetValue().GetCount()), wxT("Invalid index for array") );
1766 return * (wxVariant
*) (data
->GetValue().Item(idx
)->GetData());
1769 // Return the number of elements in a list
1770 size_t wxVariant::GetCount() const
1772 #if WXWIN_COMPATIBILITY_2_4
1773 wxASSERT_MSG( (GetType() == wxT("list") || GetType() == wxT("stringlist")), wxT("Invalid type for GetCount()") );
1775 wxASSERT_MSG( GetType() == wxT("list"), wxT("Invalid type for GetCount()") );
1778 if (GetType() == wxT("list"))
1780 wxVariantDataList
* data
= (wxVariantDataList
*) m_data
;
1781 return data
->GetValue().GetCount();
1783 #if WXWIN_COMPATIBILITY_2_4
1784 else if (GetType() == wxT("stringlist"))
1786 wxVariantDataStringList
* data
= (wxVariantDataStringList
*) m_data
;
1787 return data
->GetValue().GetCount();
1793 wxString
wxVariant::MakeString() const
1798 if (GetData()->Write(str
))
1801 return wxEmptyString
;
1806 void wxVariant::SetData(wxVariantData
* data
)
1808 if (m_data
) delete m_data
;
1813 // Returns a string representing the type of the variant,
1814 // e.g. "string", "bool", "list", "double", "long"
1815 wxString
wxVariant::GetType() const
1818 return wxString(wxT("null"));
1820 return m_data
->GetType();
1824 bool wxVariant::IsType(const wxString
& type
) const
1826 return (GetType() == type
);
1829 bool wxVariant::IsValueKindOf(const wxClassInfo
* type
) const
1831 wxClassInfo
* info
=m_data
->GetValueClassInfo();
1832 return info
? info
->IsKindOf(type
) : false ;
1837 double wxVariant::GetReal() const
1840 if (Convert(& value
))
1844 wxFAIL_MSG(wxT("Could not convert to a real number"));
1849 long wxVariant::GetInteger() const
1852 if (Convert(& value
))
1856 wxFAIL_MSG(wxT("Could not convert to an integer"));
1861 char wxVariant::GetChar() const
1864 if (Convert(& value
))
1868 wxFAIL_MSG(wxT("Could not convert to a char"));
1873 bool wxVariant::GetBool() const
1876 if (Convert(& value
))
1880 wxFAIL_MSG(wxT("Could not convert to a bool"));
1885 wxString
wxVariant::GetString() const
1888 if (!Convert(& value
))
1890 wxFAIL_MSG(wxT("Could not convert to a string"));
1896 void* wxVariant::GetVoidPtr() const
1898 wxASSERT( (GetType() == wxT("void*")) );
1900 return (void*) ((wxVariantDataVoidPtr
*) m_data
)->GetValue();
1903 wxObject
* wxVariant::GetWxObjectPtr()
1905 wxASSERT(wxIsKindOf(m_data
, wxVariantDataWxObjectPtr
));
1906 return (wxObject
*) ((wxVariantDataWxObjectPtr
*) m_data
)->GetValue();
1910 wxDateTime
wxVariant::GetDateTime() const
1913 if (!Convert(& value
))
1915 wxFAIL_MSG(wxT("Could not convert to a datetime"));
1920 #endif // wxUSE_DATETIME
1922 wxList
& wxVariant::GetList() const
1924 wxASSERT( (GetType() == wxT("list")) );
1926 return (wxList
&) ((wxVariantDataList
*) m_data
)->GetValue();
1929 #if WXWIN_COMPATIBILITY_2_4
1931 wxStringList
& wxVariant::GetStringList() const
1933 wxASSERT( (GetType() == wxT("stringlist")) );
1935 return (wxStringList
&) ((wxVariantDataStringList
*) m_data
)->GetValue();
1941 void wxVariant::NullList()
1943 SetData(new wxVariantDataList());
1947 void wxVariant::Append(const wxVariant
& value
)
1949 wxList
& list
= GetList();
1951 list
.Append(new wxVariant(value
));
1954 // Insert at front of list
1955 void wxVariant::Insert(const wxVariant
& value
)
1957 wxList
& list
= GetList();
1959 list
.Insert(new wxVariant(value
));
1962 // Returns true if the variant is a member of the list
1963 bool wxVariant::Member(const wxVariant
& value
) const
1965 wxList
& list
= GetList();
1967 wxList::compatibility_iterator node
= list
.GetFirst();
1970 wxVariant
* other
= (wxVariant
*) node
->GetData();
1971 if (value
== *other
)
1973 node
= node
->GetNext();
1978 // Deletes the nth element of the list
1979 bool wxVariant::Delete(size_t item
)
1981 wxList
& list
= GetList();
1983 wxASSERT_MSG( (item
< list
.GetCount()), wxT("Invalid index to Delete") );
1984 wxList::compatibility_iterator node
= list
.Item(item
);
1985 wxVariant
* variant
= (wxVariant
*) node
->GetData();
1992 void wxVariant::ClearList()
1994 if (!IsNull() && (GetType() == wxT("list")))
1996 ((wxVariantDataList
*) m_data
)->Clear();
2000 if (!GetType().IsSameAs(wxT("list")))
2005 m_data
= new wxVariantDataList
;
2010 bool wxVariant::Convert(long* value
) const
2012 wxString
type(GetType());
2013 if (type
== wxT("double"))
2014 *value
= (long) (((wxVariantDataReal
*)GetData())->GetValue());
2015 else if (type
== wxT("long"))
2016 *value
= ((wxVariantDataLong
*)GetData())->GetValue();
2018 else if (type
== wxT("bool"))
2019 *value
= (long) (((wxVariantDataBool
*)GetData())->GetValue());
2021 else if (type
== wxT("string"))
2022 *value
= wxAtol((const wxChar
*) ((wxVariantDataString
*)GetData())->GetValue());
2029 bool wxVariant::Convert(bool* value
) const
2031 wxString
type(GetType());
2032 if (type
== wxT("double"))
2033 *value
= ((int) (((wxVariantDataReal
*)GetData())->GetValue()) != 0);
2034 else if (type
== wxT("long"))
2035 *value
= (((wxVariantDataLong
*)GetData())->GetValue() != 0);
2037 else if (type
== wxT("bool"))
2038 *value
= ((wxVariantDataBool
*)GetData())->GetValue();
2040 else if (type
== wxT("string"))
2042 wxString
val(((wxVariantDataString
*)GetData())->GetValue());
2044 if (val
== wxT("true") || val
== wxT("yes") || val
== wxT('1') )
2046 else if (val
== wxT("false") || val
== wxT("no") || val
== wxT('0') )
2057 bool wxVariant::Convert(double* value
) const
2059 wxString
type(GetType());
2060 if (type
== wxT("double"))
2061 *value
= ((wxVariantDataReal
*)GetData())->GetValue();
2062 else if (type
== wxT("long"))
2063 *value
= (double) (((wxVariantDataLong
*)GetData())->GetValue());
2065 else if (type
== wxT("bool"))
2066 *value
= (double) (((wxVariantDataBool
*)GetData())->GetValue());
2068 else if (type
== wxT("string"))
2069 *value
= (double) wxAtof((const wxChar
*) ((wxVariantDataString
*)GetData())->GetValue());
2076 bool wxVariant::Convert(char* value
) const
2078 wxString
type(GetType());
2079 if (type
== wxT("char"))
2080 *value
= ((wxVariantDataChar
*)GetData())->GetValue();
2081 else if (type
== wxT("long"))
2082 *value
= (char) (((wxVariantDataLong
*)GetData())->GetValue());
2084 else if (type
== wxT("bool"))
2085 *value
= (char) (((wxVariantDataBool
*)GetData())->GetValue());
2093 bool wxVariant::Convert(wxString
* value
) const
2095 *value
= MakeString();
2100 bool wxVariant::Convert(wxDateTime
* value
) const
2102 wxString
type(GetType());
2103 if (type
== wxT("datetime"))
2105 *value
= ((wxVariantDataDateTime
*)GetData())->GetValue();
2108 // Fallback to string conversion
2110 return Convert(&val
) &&
2111 (value
->ParseDateTime(val
) || value
->ParseDate(val
));
2113 #endif // wxUSE_DATETIME