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
);
63 virtual ~wxVariantDataList();
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
& WXUNUSED(str
)) { return false; };
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
786 bool wxVariantDataString::Write(wxOutputStream
& str
) const
788 // why doesn't wxOutputStream::operator<< take "const wxString&"
789 wxTextOutputStream
s(str
);
790 s
.WriteString(m_value
);
794 bool wxVariantDataString::Read(wxInputStream
& str
)
796 wxTextInputStream
s(str
);
798 m_value
= s
.ReadLine();
801 #endif // wxUSE_STREAMS
803 bool wxVariantDataString::Read(wxString
& str
)
809 IMPLEMENT_DYNAMIC_CLASS(wxVariantDataString
, wxVariantData
)
812 * wxVariantDataVoidPtr
815 class wxVariantDataVoidPtr
: public wxVariantData
817 DECLARE_DYNAMIC_CLASS(wxVariantDataVoidPtr
)
819 wxVariantDataVoidPtr() { }
820 wxVariantDataVoidPtr(void* value
) { m_value
= value
; }
822 inline void* GetValue() const { return m_value
; }
823 inline void SetValue(void* value
) { m_value
= value
; }
825 virtual void Copy(wxVariantData
& data
);
826 virtual bool Eq(wxVariantData
& data
) const;
827 #if wxUSE_STD_IOSTREAM
828 virtual bool Write(wxSTD ostream
& str
) const;
830 virtual bool Write(wxString
& str
) const;
831 #if wxUSE_STD_IOSTREAM
832 virtual bool Read(wxSTD istream
& str
);
834 virtual bool Read(wxString
& str
);
835 virtual wxString
GetType() const { return wxT("void*"); };
836 virtual wxVariantData
* Clone() { return new wxVariantDataVoidPtr
; }
841 DECLARE_NO_COPY_CLASS(wxVariantDataVoidPtr
)
844 IMPLEMENT_DYNAMIC_CLASS(wxVariantDataVoidPtr
, wxVariantData
)
846 void wxVariantDataVoidPtr::Copy(wxVariantData
& data
)
848 wxASSERT_MSG( (data
.GetType() == wxT("void*")), wxT("wxVariantDataVoidPtr::Copy: Can't copy to this type of data") );
850 wxVariantDataVoidPtr
& otherData
= (wxVariantDataVoidPtr
&) data
;
852 otherData
.m_value
= m_value
;
855 bool wxVariantDataVoidPtr::Eq(wxVariantData
& data
) const
857 wxASSERT_MSG( (data
.GetType() == wxT("void*")), wxT("wxVariantDataVoidPtr::Eq: argument mismatch") );
859 wxVariantDataVoidPtr
& otherData
= (wxVariantDataVoidPtr
&) data
;
861 return (otherData
.m_value
== m_value
);
864 #if wxUSE_STD_IOSTREAM
865 bool wxVariantDataVoidPtr::Write(wxSTD ostream
& str
) const
869 str
<< (const char*) s
.mb_str();
874 bool wxVariantDataVoidPtr::Write(wxString
& str
) const
876 str
.Printf(wxT("%p"), m_value
);
880 #if wxUSE_STD_IOSTREAM
881 bool wxVariantDataVoidPtr::Read(wxSTD istream
& WXUNUSED(str
))
888 bool wxVariantDataVoidPtr::Read(wxString
& WXUNUSED(str
))
895 * wxVariantDataWxObjectPtr
898 class wxVariantDataWxObjectPtr
: public wxVariantData
900 DECLARE_DYNAMIC_CLASS(wxVariantDataWxObjectPtr
)
902 wxVariantDataWxObjectPtr() { }
903 wxVariantDataWxObjectPtr(wxObject
* value
) { m_value
= value
; }
905 inline wxObject
* GetValue() const { return m_value
; }
906 inline void SetValue(wxObject
* value
) { m_value
= value
; }
908 virtual void Copy(wxVariantData
& data
);
909 virtual bool Eq(wxVariantData
& data
) const;
910 #if wxUSE_STD_IOSTREAM
911 virtual bool Write(wxSTD ostream
& str
) const;
913 virtual bool Write(wxString
& str
) const;
914 #if wxUSE_STD_IOSTREAM
915 virtual bool Read(wxSTD istream
& str
);
917 virtual bool Read(wxString
& str
);
918 virtual wxString
GetType() const ;
919 virtual wxVariantData
* Clone() { return new wxVariantDataWxObjectPtr
; }
921 virtual wxClassInfo
* GetValueClassInfo() ;
925 DECLARE_NO_COPY_CLASS(wxVariantDataWxObjectPtr
)
928 IMPLEMENT_DYNAMIC_CLASS(wxVariantDataWxObjectPtr
, wxVariantData
)
930 void wxVariantDataWxObjectPtr::Copy(wxVariantData
& data
)
932 wxASSERT_MSG( wxIsKindOf((&data
), wxVariantDataWxObjectPtr
) ,\
933 wxT("wxVariantDataWxObjectPtr::Copy: Can't copy to this type of data") \
936 wxVariantDataWxObjectPtr
& otherData
= (wxVariantDataWxObjectPtr
&) data
;
938 otherData
.m_value
= m_value
;
941 bool wxVariantDataWxObjectPtr::Eq(wxVariantData
& data
) const
943 wxASSERT_MSG( wxIsKindOf((&data
), wxVariantDataWxObjectPtr
), wxT("wxVariantDataWxObjectPtr::Eq: argument mismatch") );
945 wxVariantDataWxObjectPtr
& otherData
= (wxVariantDataWxObjectPtr
&) data
;
947 return (otherData
.m_value
== m_value
);
950 wxString
wxVariantDataWxObjectPtr::GetType() const
952 wxString
returnVal(wxT("wxObject"));
954 returnVal
= m_value
->GetClassInfo()->GetClassName();
959 wxClassInfo
* wxVariantDataWxObjectPtr::GetValueClassInfo()
961 wxClassInfo
* returnVal
=NULL
;
963 if (m_value
) returnVal
= m_value
->GetClassInfo();
968 #if wxUSE_STD_IOSTREAM
969 bool wxVariantDataWxObjectPtr::Write(wxSTD ostream
& str
) const
973 str
<< (const char*) s
.mb_str();
978 bool wxVariantDataWxObjectPtr::Write(wxString
& str
) const
980 str
.Printf(wxT("%s(%p)"), GetType().c_str(), wx_static_cast(void*, m_value
));
984 #if wxUSE_STD_IOSTREAM
985 bool wxVariantDataWxObjectPtr::Read(wxSTD istream
& WXUNUSED(str
))
992 bool wxVariantDataWxObjectPtr::Read(wxString
& WXUNUSED(str
))
1000 * wxVariantDataDateTime
1005 class wxVariantDataDateTime
: public wxVariantData
1007 DECLARE_DYNAMIC_CLASS(wxVariantDataDateTime
)
1010 wxVariantDataDateTime() { }
1011 wxVariantDataDateTime(const wxDateTime
& value
) { m_value
= value
; }
1013 wxVariantDataDateTime(const TIME_STRUCT
* valptr
)
1014 { m_value
= wxDateTime(valptr
->hour
, valptr
->minute
, valptr
->second
); }
1015 wxVariantDataDateTime(const DATE_STRUCT
* valptr
)
1016 { m_value
= wxDateTime(valptr
->day
, (wxDateTime::Month
) (valptr
->month
- 1),valptr
->year
); }
1017 wxVariantDataDateTime(const TIMESTAMP_STRUCT
* valptr
)
1018 { m_value
= wxDateTime(valptr
->day
, (wxDateTime::Month
) (valptr
->month
- 1), valptr
->year
,
1019 valptr
->hour
, valptr
->minute
, valptr
->second
, (wxDateTime::wxDateTime_t
)valptr
->fraction
); }
1022 inline wxDateTime
GetValue() const { return m_value
; }
1023 inline void SetValue(const wxDateTime
& value
) { m_value
= value
; }
1025 virtual void Copy(wxVariantData
& data
);
1026 virtual bool Eq(wxVariantData
& data
) const;
1027 #if wxUSE_STD_IOSTREAM
1028 virtual bool Write(wxSTD ostream
& str
) const;
1030 virtual bool Write(wxString
& str
) const;
1031 #if wxUSE_STD_IOSTREAM
1032 virtual bool Read(wxSTD istream
& str
);
1034 virtual bool Read(wxString
& str
);
1035 virtual wxString
GetType() const { return wxT("datetime"); };
1036 virtual wxVariantData
* Clone() { return new wxVariantDataDateTime
; }
1043 IMPLEMENT_DYNAMIC_CLASS(wxVariantDataDateTime
, wxVariantData
)
1045 void wxVariantDataDateTime::Copy(wxVariantData
& data
)
1047 wxASSERT_MSG( (data
.GetType() == wxT("datetime")), wxT("wxVariantDataDateTime::Copy: Can't copy to this type of data") );
1049 wxVariantDataDateTime
& otherData
= (wxVariantDataDateTime
&) data
;
1051 otherData
.m_value
= m_value
;
1055 bool wxVariantDataDateTime::Eq(wxVariantData
& data
) const
1057 wxASSERT_MSG( (data
.GetType() == wxT("datetime")), wxT("wxVariantDataDateTime::Eq: argument mismatch") );
1059 wxVariantDataDateTime
& otherData
= (wxVariantDataDateTime
&) data
;
1061 return (otherData
.m_value
== m_value
);
1065 #if wxUSE_STD_IOSTREAM
1066 bool wxVariantDataDateTime::Write(wxSTD ostream
& WXUNUSED(str
)) const
1074 bool wxVariantDataDateTime::Write(wxString
& str
) const
1076 str
= m_value
.Format();
1081 #if wxUSE_STD_IOSTREAM
1082 bool wxVariantDataDateTime::Read(wxSTD istream
& WXUNUSED(str
))
1090 bool wxVariantDataDateTime::Read(wxString
& str
)
1092 if(! m_value
.ParseDateTime(str
))
1097 #endif // wxUSE_DATETIME
1099 // ----------------------------------------------------------------------------
1100 // wxVariantDataArrayString
1101 // ----------------------------------------------------------------------------
1103 class wxVariantDataArrayString
: public wxVariantData
1106 wxVariantDataArrayString() { }
1107 wxVariantDataArrayString(const wxArrayString
& value
) { m_value
= value
; }
1109 wxArrayString
GetValue() const { return m_value
; }
1110 void SetValue(const wxArrayString
& value
) { m_value
= value
; }
1112 virtual void Copy(wxVariantData
& data
);
1113 virtual bool Eq(wxVariantData
& data
) const;
1114 #if wxUSE_STD_IOSTREAM
1115 virtual bool Write(wxSTD ostream
& str
) const;
1117 virtual bool Write(wxString
& str
) const;
1118 #if wxUSE_STD_IOSTREAM
1119 virtual bool Read(wxSTD istream
& str
);
1121 virtual bool Read(wxString
& str
);
1122 virtual wxString
GetType() const { return wxT("arrstring"); };
1123 virtual wxVariantData
* Clone() { return new wxVariantDataArrayString
; }
1126 wxArrayString m_value
;
1128 DECLARE_DYNAMIC_CLASS(wxVariantDataArrayString
)
1131 IMPLEMENT_DYNAMIC_CLASS(wxVariantDataArrayString
, wxVariantData
)
1133 void wxVariantDataArrayString::Copy(wxVariantData
& data
)
1135 wxASSERT_MSG( data
.GetType() == GetType(), wxT("wxVariantDataArrayString::Copy: Can't copy to this type of data") );
1137 wxVariantDataArrayString
& otherData
= (wxVariantDataArrayString
&) data
;
1139 otherData
.m_value
= m_value
;
1143 bool wxVariantDataArrayString::Eq(wxVariantData
& data
) const
1145 wxASSERT_MSG( data
.GetType() == GetType(), wxT("wxVariantDataArrayString::Eq: argument mismatch") );
1147 wxVariantDataArrayString
& otherData
= (wxVariantDataArrayString
&) data
;
1149 return otherData
.m_value
== m_value
;
1153 #if wxUSE_STD_IOSTREAM
1154 bool wxVariantDataArrayString::Write(wxSTD ostream
& WXUNUSED(str
)) const
1162 bool wxVariantDataArrayString::Write(wxString
& str
) const
1164 size_t count
= m_value
.GetCount();
1165 for ( size_t n
= 0; n
< count
; n
++ )
1177 #if wxUSE_STD_IOSTREAM
1178 bool wxVariantDataArrayString::Read(wxSTD istream
& WXUNUSED(str
))
1186 bool wxVariantDataArrayString::Read(wxString
& str
)
1188 wxStringTokenizer
tk(str
, _T(";"));
1189 while ( tk
.HasMoreTokens() )
1191 m_value
.Add(tk
.GetNextToken());
1203 IMPLEMENT_DYNAMIC_CLASS(wxVariant
, wxObject
)
1205 // Construction & destruction
1206 wxVariant::wxVariant()
1208 m_data
= (wxVariantData
*) NULL
;
1211 wxVariant::wxVariant(double val
, const wxString
& name
)
1213 m_data
= new wxVariantDataReal(val
);
1217 wxVariant::wxVariant(long val
, const wxString
& name
)
1219 m_data
= new wxVariantDataLong(val
);
1224 wxVariant::wxVariant(bool val
, const wxString
& name
)
1226 m_data
= new wxVariantDataBool(val
);
1231 wxVariant::wxVariant(char val
, const wxString
& name
)
1233 m_data
= new wxVariantDataChar(val
);
1237 wxVariant::wxVariant(const wxString
& val
, const wxString
& name
)
1239 m_data
= new wxVariantDataString(val
);
1243 wxVariant::wxVariant(const wxChar
* val
, const wxString
& name
)
1245 m_data
= new wxVariantDataString(wxString(val
));
1249 #if WXWIN_COMPATIBILITY_2_4
1251 wxVariant::wxVariant(const wxStringList
& val
, const wxString
& name
)
1253 m_data
= new wxVariantDataStringList(val
);
1259 wxVariant::wxVariant(const wxList
& val
, const wxString
& name
) // List of variants
1261 m_data
= new wxVariantDataList(val
);
1265 wxVariant::wxVariant( void* val
, const wxString
& name
)
1267 m_data
= new wxVariantDataVoidPtr(val
);
1271 wxVariant::wxVariant( wxObject
* val
, const wxString
& name
)
1273 m_data
= new wxVariantDataWxObjectPtr(val
);
1278 wxVariant::wxVariant(const wxDateTime
& val
, const wxString
& name
) // Date
1280 m_data
= new wxVariantDataDateTime(val
);
1283 #endif // wxUSE_DATETIME
1286 wxVariant::wxVariant(const TIME_STRUCT
* valptr
, const wxString
& name
) // Date
1288 m_data
= new wxVariantDataDateTime(valptr
);
1292 wxVariant::wxVariant(const TIMESTAMP_STRUCT
* valptr
, const wxString
& name
) // Date
1294 m_data
= new wxVariantDataDateTime(valptr
);
1298 wxVariant::wxVariant(const DATE_STRUCT
* valptr
, const wxString
& name
) // Date
1300 m_data
= new wxVariantDataDateTime(valptr
);
1303 #endif // wxUSE_ODBC
1305 wxVariant::wxVariant(const wxArrayString
& val
, const wxString
& name
) // Strings
1307 m_data
= new wxVariantDataArrayString(val
);
1311 wxVariant::wxVariant(const wxVariant
& variant
)
1314 if (!variant
.IsNull())
1316 m_data
= (wxVariantData
*) variant
.GetData()->GetClassInfo()->CreateObject();
1317 variant
.m_data
->Copy(*m_data
);
1320 m_data
= (wxVariantData
*) NULL
;
1321 m_name
= variant
.m_name
;
1324 wxVariant::wxVariant(wxVariantData
* data
, const wxString
& name
) // User-defined data
1330 wxVariant::~wxVariant()
1336 // Make NULL (i.e. delete the data)
1337 void wxVariant::MakeNull()
1343 // Generic operators
1345 void wxVariant::operator= (const wxVariant
& variant
)
1347 if (variant
.IsNull())
1353 if (IsNull() || (GetType() != variant
.GetType()))
1357 m_data
= (wxVariantData
*) variant
.GetData()->GetClassInfo()->CreateObject();
1360 variant
.GetData()->Copy(* GetData());
1362 m_name
= variant
.m_name
;
1365 // Assignment using data, e.g.
1366 // myVariant = new wxStringVariantData("hello")
1367 void wxVariant::operator= (wxVariantData
* variantData
)
1370 m_data
= variantData
;
1373 bool wxVariant::operator== (const wxVariant
& variant
) const
1375 if (IsNull() || variant
.IsNull())
1376 return (IsNull() == variant
.IsNull());
1378 return (GetData()->Eq(* variant
.GetData()));
1381 bool wxVariant::operator!= (const wxVariant
& variant
) const
1383 return (!(*this == variant
));
1387 // Specific operators
1388 bool wxVariant::operator== (double value
) const
1391 if (!Convert(&thisValue
))
1394 return wxIsSameDouble(value
, thisValue
);
1397 bool wxVariant::operator!= (double value
) const
1399 return (!((*this) == value
));
1402 void wxVariant::operator= (double value
)
1404 if (GetType() == wxT("double"))
1406 ((wxVariantDataReal
*)GetData())->SetValue(value
);
1412 m_data
= new wxVariantDataReal(value
);
1416 bool wxVariant::operator== (long value
) const
1419 if (!Convert(&thisValue
))
1422 return (value
== thisValue
);
1425 bool wxVariant::operator!= (long value
) const
1427 return (!((*this) == value
));
1430 void wxVariant::operator= (long value
)
1432 if (GetType() == wxT("long"))
1434 ((wxVariantDataLong
*)GetData())->SetValue(value
);
1440 m_data
= new wxVariantDataLong(value
);
1444 bool wxVariant::operator== (char value
) const
1447 if (!Convert(&thisValue
))
1450 return (value
== thisValue
);
1453 bool wxVariant::operator!= (char value
) const
1455 return (!((*this) == value
));
1458 void wxVariant::operator= (char value
)
1460 if (GetType() == wxT("char"))
1462 ((wxVariantDataChar
*)GetData())->SetValue(value
);
1468 m_data
= new wxVariantDataChar(value
);
1473 bool wxVariant::operator== (bool value
) const
1476 if (!Convert(&thisValue
))
1479 return (value
== thisValue
);
1482 bool wxVariant::operator!= (bool value
) const
1484 return (!((*this) == value
));
1487 void wxVariant::operator= (bool value
)
1489 if (GetType() == wxT("bool"))
1491 ((wxVariantDataBool
*)GetData())->SetValue(value
);
1497 m_data
= new wxVariantDataBool(value
);
1502 bool wxVariant::operator== (const wxString
& value
) const
1505 if (!Convert(&thisValue
))
1508 return value
== thisValue
;
1511 bool wxVariant::operator!= (const wxString
& value
) const
1513 return (!((*this) == value
));
1516 void wxVariant::operator= (const wxString
& value
)
1518 if (GetType() == wxT("string"))
1520 ((wxVariantDataString
*)GetData())->SetValue(value
);
1526 m_data
= new wxVariantDataString(value
);
1530 void wxVariant::operator= (const wxChar
* value
)
1532 if (GetType() == wxT("string"))
1534 ((wxVariantDataString
*)GetData())->SetValue(wxString(value
));
1540 m_data
= new wxVariantDataString(wxString(value
));
1544 #if WXWIN_COMPATIBILITY_2_4
1546 bool wxVariant::operator== (const wxStringList
& value
) const
1548 wxASSERT_MSG( (GetType() == wxT("stringlist")), wxT("Invalid type for == operator") );
1550 wxVariantDataStringList
other(value
);
1551 return (m_data
->Eq(other
));
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 void wxVariant::operator= (const wxStringList
& value
)
1564 if (GetType() == wxT("stringlist"))
1566 ((wxVariantDataStringList
*)GetData())->SetValue(value
);
1572 m_data
= new wxVariantDataStringList(value
);
1578 bool wxVariant::operator== (const wxList
& value
) const
1580 wxASSERT_MSG( (GetType() == wxT("list")), wxT("Invalid type for == operator") );
1582 wxVariantDataList
other(value
);
1583 return (m_data
->Eq(other
));
1586 bool wxVariant::operator!= (const wxList
& value
) const
1588 return (!((*this) == value
));
1591 void wxVariant::operator= (const wxList
& value
)
1593 if (GetType() == wxT("list"))
1595 ((wxVariantDataList
*)GetData())->SetValue(value
);
1601 m_data
= new wxVariantDataList(value
);
1605 bool wxVariant::operator== (void* value
) const
1607 return (value
== ((wxVariantDataVoidPtr
*)GetData())->GetValue());
1610 bool wxVariant::operator!= (void* value
) const
1612 return (!((*this) == (void*) value
));
1615 void wxVariant::operator= (void* value
)
1617 if (GetType() == wxT("void*"))
1619 ((wxVariantDataVoidPtr
*)GetData())->SetValue(value
);
1625 m_data
= new wxVariantDataVoidPtr(value
);
1630 bool wxVariant::operator== (const wxDateTime
& value
) const
1632 wxDateTime thisValue
;
1633 if (!Convert(&thisValue
))
1636 return value
.IsEqualTo(thisValue
);
1639 bool wxVariant::operator!= (const wxDateTime
& value
) const
1641 return (!((*this) == value
));
1644 void wxVariant::operator= (const wxDateTime
& value
)
1646 if (GetType() == wxT("datetime"))
1648 ((wxVariantDataDateTime
*)GetData())->SetValue(value
);
1654 m_data
= new wxVariantDataDateTime(value
);
1657 #endif // wxUSE_DATETIME
1660 void wxVariant::operator= (const DATE_STRUCT
* value
)
1664 m_data
= new wxVariantDataDateTime(value
);
1668 void wxVariant::operator= (const TIME_STRUCT
* value
)
1672 m_data
= new wxVariantDataDateTime(value
);
1676 void wxVariant::operator= (const TIMESTAMP_STRUCT
* value
)
1680 m_data
= new wxVariantDataDateTime(value
);
1683 #endif // wxUSE_ODBC
1685 bool wxVariant::operator==(const wxArrayString
& WXUNUSED(value
)) const
1687 wxFAIL_MSG( _T("TODO") );
1692 bool wxVariant::operator!=(const wxArrayString
& value
) const
1694 return !(*this == value
);
1697 void wxVariant::operator=(const wxArrayString
& value
)
1699 if (GetType() == wxT("arrstring"))
1701 ((wxVariantDataArrayString
*)GetData())->SetValue(value
);
1706 m_data
= new wxVariantDataArrayString(value
);
1710 wxArrayString
wxVariant::GetArrayString() const
1712 if ( GetType() == wxT("arrstring") )
1713 return ((wxVariantDataArrayString
*)GetData())->GetValue();
1715 return wxArrayString();
1719 // Treat a list variant as an array
1720 wxVariant
wxVariant::operator[] (size_t idx
) const
1722 #if WXWIN_COMPATIBILITY_2_4
1723 wxASSERT_MSG( (GetType() == wxT("list") || GetType() == wxT("stringlist")), wxT("Invalid type for array operator") );
1725 wxASSERT_MSG( GetType() == wxT("list"), wxT("Invalid type for array operator") );
1728 if (GetType() == wxT("list"))
1730 wxVariantDataList
* data
= (wxVariantDataList
*) m_data
;
1731 wxASSERT_MSG( (idx
< data
->GetValue().GetCount()), wxT("Invalid index for array") );
1732 return * (wxVariant
*) (data
->GetValue().Item(idx
)->GetData());
1734 #if WXWIN_COMPATIBILITY_2_4
1735 else if (GetType() == wxT("stringlist"))
1737 wxVariantDataStringList
* data
= (wxVariantDataStringList
*) m_data
;
1738 wxASSERT_MSG( (idx
< data
->GetValue().GetCount()), wxT("Invalid index for array") );
1740 wxString
str( (const wxChar
*) (data
->GetValue().Item(idx
)->GetData()) );
1741 wxVariant
variant( str
);
1745 return wxNullVariant
;
1748 wxVariant
& wxVariant::operator[] (size_t idx
)
1750 // We can't return a reference to a variant for a string list, since the string
1751 // is actually stored as a char*, not a variant.
1753 wxASSERT_MSG( (GetType() == wxT("list")), wxT("Invalid type for array operator") );
1755 wxVariantDataList
* data
= (wxVariantDataList
*) m_data
;
1756 wxASSERT_MSG( (idx
< data
->GetValue().GetCount()), wxT("Invalid index for array") );
1758 return * (wxVariant
*) (data
->GetValue().Item(idx
)->GetData());
1761 // Return the number of elements in a list
1762 size_t wxVariant::GetCount() const
1764 #if WXWIN_COMPATIBILITY_2_4
1765 wxASSERT_MSG( (GetType() == wxT("list") || GetType() == wxT("stringlist")), wxT("Invalid type for GetCount()") );
1767 wxASSERT_MSG( GetType() == wxT("list"), wxT("Invalid type for GetCount()") );
1770 if (GetType() == wxT("list"))
1772 wxVariantDataList
* data
= (wxVariantDataList
*) m_data
;
1773 return data
->GetValue().GetCount();
1775 #if WXWIN_COMPATIBILITY_2_4
1776 else if (GetType() == wxT("stringlist"))
1778 wxVariantDataStringList
* data
= (wxVariantDataStringList
*) m_data
;
1779 return data
->GetValue().GetCount();
1785 wxString
wxVariant::MakeString() const
1790 if (GetData()->Write(str
))
1793 return wxEmptyString
;
1798 void wxVariant::SetData(wxVariantData
* data
)
1800 if (m_data
) delete m_data
;
1805 // Returns a string representing the type of the variant,
1806 // e.g. "string", "bool", "list", "double", "long"
1807 wxString
wxVariant::GetType() const
1810 return wxString(wxT("null"));
1812 return m_data
->GetType();
1816 bool wxVariant::IsType(const wxString
& type
) const
1818 return (GetType() == type
);
1821 bool wxVariant::IsValueKindOf(const wxClassInfo
* type
) const
1823 wxClassInfo
* info
=m_data
->GetValueClassInfo();
1824 return info
? info
->IsKindOf(type
) : false ;
1829 double wxVariant::GetReal() const
1832 if (Convert(& value
))
1836 wxFAIL_MSG(wxT("Could not convert to a real number"));
1841 long wxVariant::GetInteger() const
1844 if (Convert(& value
))
1848 wxFAIL_MSG(wxT("Could not convert to an integer"));
1853 char wxVariant::GetChar() const
1856 if (Convert(& value
))
1860 wxFAIL_MSG(wxT("Could not convert to a char"));
1865 bool wxVariant::GetBool() const
1868 if (Convert(& value
))
1872 wxFAIL_MSG(wxT("Could not convert to a bool"));
1877 wxString
wxVariant::GetString() const
1880 if (!Convert(& value
))
1882 wxFAIL_MSG(wxT("Could not convert to a string"));
1888 void* wxVariant::GetVoidPtr() const
1890 wxASSERT( (GetType() == wxT("void*")) );
1892 return (void*) ((wxVariantDataVoidPtr
*) m_data
)->GetValue();
1895 wxObject
* wxVariant::GetWxObjectPtr()
1897 wxASSERT(wxIsKindOf(m_data
, wxVariantDataWxObjectPtr
));
1898 return (wxObject
*) ((wxVariantDataWxObjectPtr
*) m_data
)->GetValue();
1902 wxDateTime
wxVariant::GetDateTime() const
1905 if (!Convert(& value
))
1907 wxFAIL_MSG(wxT("Could not convert to a datetime"));
1912 #endif // wxUSE_DATETIME
1914 wxList
& wxVariant::GetList() const
1916 wxASSERT( (GetType() == wxT("list")) );
1918 return (wxList
&) ((wxVariantDataList
*) m_data
)->GetValue();
1921 #if WXWIN_COMPATIBILITY_2_4
1923 wxStringList
& wxVariant::GetStringList() const
1925 wxASSERT( (GetType() == wxT("stringlist")) );
1927 return (wxStringList
&) ((wxVariantDataStringList
*) m_data
)->GetValue();
1933 void wxVariant::NullList()
1935 SetData(new wxVariantDataList());
1939 void wxVariant::Append(const wxVariant
& value
)
1941 wxList
& list
= GetList();
1943 list
.Append(new wxVariant(value
));
1946 // Insert at front of list
1947 void wxVariant::Insert(const wxVariant
& value
)
1949 wxList
& list
= GetList();
1951 list
.Insert(new wxVariant(value
));
1954 // Returns true if the variant is a member of the list
1955 bool wxVariant::Member(const wxVariant
& value
) const
1957 wxList
& list
= GetList();
1959 wxList::compatibility_iterator node
= list
.GetFirst();
1962 wxVariant
* other
= (wxVariant
*) node
->GetData();
1963 if (value
== *other
)
1965 node
= node
->GetNext();
1970 // Deletes the nth element of the list
1971 bool wxVariant::Delete(size_t item
)
1973 wxList
& list
= GetList();
1975 wxASSERT_MSG( (item
< list
.GetCount()), wxT("Invalid index to Delete") );
1976 wxList::compatibility_iterator node
= list
.Item(item
);
1977 wxVariant
* variant
= (wxVariant
*) node
->GetData();
1984 void wxVariant::ClearList()
1986 if (!IsNull() && (GetType() == wxT("list")))
1988 ((wxVariantDataList
*) m_data
)->Clear();
1992 if (!GetType().IsSameAs(wxT("list")))
1997 m_data
= new wxVariantDataList
;
2002 bool wxVariant::Convert(long* value
) const
2004 wxString
type(GetType());
2005 if (type
== wxT("double"))
2006 *value
= (long) (((wxVariantDataReal
*)GetData())->GetValue());
2007 else if (type
== wxT("long"))
2008 *value
= ((wxVariantDataLong
*)GetData())->GetValue();
2010 else if (type
== wxT("bool"))
2011 *value
= (long) (((wxVariantDataBool
*)GetData())->GetValue());
2013 else if (type
== wxT("string"))
2014 *value
= wxAtol((const wxChar
*) ((wxVariantDataString
*)GetData())->GetValue());
2021 bool wxVariant::Convert(bool* value
) const
2023 wxString
type(GetType());
2024 if (type
== wxT("double"))
2025 *value
= ((int) (((wxVariantDataReal
*)GetData())->GetValue()) != 0);
2026 else if (type
== wxT("long"))
2027 *value
= (((wxVariantDataLong
*)GetData())->GetValue() != 0);
2029 else if (type
== wxT("bool"))
2030 *value
= ((wxVariantDataBool
*)GetData())->GetValue();
2032 else if (type
== wxT("string"))
2034 wxString
val(((wxVariantDataString
*)GetData())->GetValue());
2036 if (val
== wxT("true") || val
== wxT("yes") || val
== wxT('1') )
2038 else if (val
== wxT("false") || val
== wxT("no") || val
== wxT('0') )
2049 bool wxVariant::Convert(double* value
) const
2051 wxString
type(GetType());
2052 if (type
== wxT("double"))
2053 *value
= ((wxVariantDataReal
*)GetData())->GetValue();
2054 else if (type
== wxT("long"))
2055 *value
= (double) (((wxVariantDataLong
*)GetData())->GetValue());
2057 else if (type
== wxT("bool"))
2058 *value
= (double) (((wxVariantDataBool
*)GetData())->GetValue());
2060 else if (type
== wxT("string"))
2061 *value
= (double) wxAtof((const wxChar
*) ((wxVariantDataString
*)GetData())->GetValue());
2068 bool wxVariant::Convert(char* value
) const
2070 wxString
type(GetType());
2071 if (type
== wxT("char"))
2072 *value
= ((wxVariantDataChar
*)GetData())->GetValue();
2073 else if (type
== wxT("long"))
2074 *value
= (char) (((wxVariantDataLong
*)GetData())->GetValue());
2076 else if (type
== wxT("bool"))
2077 *value
= (char) (((wxVariantDataBool
*)GetData())->GetValue());
2085 bool wxVariant::Convert(wxString
* value
) const
2087 *value
= MakeString();
2092 bool wxVariant::Convert(wxDateTime
* value
) const
2094 wxString
type(GetType());
2095 if (type
== wxT("datetime"))
2097 *value
= ((wxVariantDataDateTime
*)GetData())->GetValue();
2100 // Fallback to string conversion
2102 return Convert(&val
) &&
2103 (value
->ParseDateTime(val
) || value
->ParseDate(val
) || value
->ParseTime(val
));
2105 #endif // wxUSE_DATETIME