1 /////////////////////////////////////////////////////////////////////////////
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 #if wxUSE_STD_IOSTREAM
27 #if defined(__MWERKS__) && __MSL__ >= 0x6000
33 #include "wx/stream.h"
34 #include "wx/txtstrm.h"
37 #include "wx/string.h"
38 #include "wx/tokenzr.h"
40 #include "wx/variant.h"
42 IMPLEMENT_ABSTRACT_CLASS(wxVariantData
, wxObject
)
44 wxVariant WXDLLIMPEXP_BASE wxNullVariant
;
50 class WXDLLIMPEXP_BASE wxVariantDataList
: public wxVariantData
52 DECLARE_DYNAMIC_CLASS(wxVariantDataList
)
54 wxVariantDataList() {}
55 wxVariantDataList(const wxList
& list
);
58 wxList
& GetValue() const { return (wxList
&) m_value
; }
59 void SetValue(const wxList
& value
) ;
61 virtual void Copy(wxVariantData
& data
);
62 virtual bool Eq(wxVariantData
& data
) const;
63 #if wxUSE_STD_IOSTREAM
64 virtual bool Write(wxSTD ostream
& str
) const;
66 virtual bool Write(wxString
& str
) const;
67 #if wxUSE_STD_IOSTREAM
68 virtual bool Read(wxSTD istream
& str
);
70 virtual bool Read(wxString
& str
);
71 virtual wxString
GetType() const { return wxT("list"); };
79 IMPLEMENT_DYNAMIC_CLASS(wxVariantDataList
, wxVariantData
)
81 wxVariantDataList::wxVariantDataList(const wxList
& list
)
86 wxVariantDataList::~wxVariantDataList()
91 void wxVariantDataList::SetValue(const wxList
& value
)
94 wxList::compatibility_iterator node
= value
.GetFirst();
97 wxVariant
* var
= (wxVariant
*) node
->GetData();
98 m_value
.Append(new wxVariant(*var
));
99 node
= node
->GetNext();
103 void wxVariantDataList::Clear()
105 wxList::compatibility_iterator node
= m_value
.GetFirst();
108 wxVariant
* var
= (wxVariant
*) node
->GetData();
110 node
= node
->GetNext();
115 void wxVariantDataList::Copy(wxVariantData
& data
)
117 wxASSERT_MSG( (data
.GetType() == wxT("list")), wxT("wxVariantDataList::Copy: Can't copy to this type of data") );
119 wxVariantDataList
& listData
= (wxVariantDataList
&) data
;
122 wxList::compatibility_iterator node
= m_value
.GetFirst();
125 wxVariant
* var
= (wxVariant
*) node
->GetData();
126 listData
.m_value
.Append(new wxVariant(*var
));
127 node
= node
->GetNext();
131 bool wxVariantDataList::Eq(wxVariantData
& data
) const
133 wxASSERT_MSG( (data
.GetType() == wxT("list")), wxT("wxVariantDataList::Eq: argument mismatch") );
135 wxVariantDataList
& listData
= (wxVariantDataList
&) data
;
136 wxList::compatibility_iterator node1
= m_value
.GetFirst();
137 wxList::compatibility_iterator node2
= listData
.GetValue().GetFirst();
138 while (node1
&& node2
)
140 wxVariant
* var1
= (wxVariant
*) node1
->GetData();
141 wxVariant
* var2
= (wxVariant
*) node2
->GetData();
142 if ((*var1
) != (*var2
))
144 node1
= node1
->GetNext();
145 node2
= node2
->GetNext();
147 if (node1
|| node2
) return false;
151 #if wxUSE_STD_IOSTREAM
152 bool wxVariantDataList::Write(wxSTD ostream
& str
) const
156 str
<< (const char*) s
.mb_str();
161 bool wxVariantDataList::Write(wxString
& str
) const
164 wxList::compatibility_iterator node
= m_value
.GetFirst();
167 wxVariant
* var
= (wxVariant
*) node
->GetData();
168 if (node
!= m_value
.GetFirst())
171 str
+= var
->MakeString();
172 node
= node
->GetNext();
178 #if wxUSE_STD_IOSTREAM
179 bool wxVariantDataList::Read(wxSTD istream
& WXUNUSED(str
))
181 wxFAIL_MSG(wxT("Unimplemented"));
187 bool wxVariantDataList::Read(wxString
& WXUNUSED(str
))
189 wxFAIL_MSG(wxT("Unimplemented"));
193 #if WXWIN_COMPATIBILITY_2_4
196 * wxVariantDataStringList
199 class WXDLLIMPEXP_BASE wxVariantDataStringList
: public wxVariantData
201 DECLARE_DYNAMIC_CLASS(wxVariantDataStringList
)
203 wxVariantDataStringList() {}
204 wxVariantDataStringList(const wxStringList
& list
) { m_value
= list
; }
206 wxStringList
& GetValue() const { return (wxStringList
&) m_value
; }
207 void SetValue(const wxStringList
& value
);
209 virtual void Copy(wxVariantData
& data
);
210 virtual bool Eq(wxVariantData
& data
) const;
211 #if wxUSE_STD_IOSTREAM
212 virtual bool Write(wxSTD ostream
& str
) const;
214 virtual bool Write(wxString
& str
) const;
215 #if wxUSE_STD_IOSTREAM
216 virtual bool Read(wxSTD istream
& str
);
218 virtual bool Read(wxString
& str
);
219 virtual wxString
GetType() const { return wxT("stringlist"); };
222 wxStringList m_value
;
225 IMPLEMENT_DYNAMIC_CLASS(wxVariantDataStringList
, wxVariantData
)
227 void wxVariantDataStringList::SetValue(const wxStringList
& value
)
232 void wxVariantDataStringList::Copy(wxVariantData
& data
)
234 wxASSERT_MSG( (data
.GetType() == wxT("stringlist")), wxT("wxVariantDataStringList::Copy: Can't copy to this type of data") );
236 wxVariantDataStringList
& listData
= (wxVariantDataStringList
&) data
;
238 listData
.m_value
= m_value
;
241 bool wxVariantDataStringList::Eq(wxVariantData
& data
) const
243 wxASSERT_MSG( (data
.GetType() == wxT("stringlist")), wxT("wxVariantDataStringList::Eq: argument mismatch") );
245 wxVariantDataStringList
& listData
= (wxVariantDataStringList
&) data
;
246 wxStringList::compatibility_iterator node1
= m_value
.GetFirst();
247 wxStringList::compatibility_iterator node2
= listData
.GetValue().GetFirst();
248 while (node1
&& node2
)
250 wxString
str1 ( node1
->GetData() );
251 wxString
str2 ( node2
->GetData() );
254 node1
= node1
->GetNext();
255 node2
= node2
->GetNext();
257 if (node1
|| node2
) return false;
261 #if wxUSE_STD_IOSTREAM
262 bool wxVariantDataStringList::Write(wxSTD ostream
& str
) const
266 str
<< (const char*) s
.mb_str();
271 bool wxVariantDataStringList::Write(wxString
& str
) const
274 wxStringList::compatibility_iterator node
= m_value
.GetFirst();
277 const wxChar
* s
= node
->GetData();
278 if (node
!= m_value
.GetFirst())
281 node
= node
->GetNext();
287 #if wxUSE_STD_IOSTREAM
288 bool wxVariantDataStringList::Read(wxSTD istream
& WXUNUSED(str
))
290 wxFAIL_MSG(wxT("Unimplemented"));
296 bool wxVariantDataStringList::Read(wxString
& WXUNUSED(str
))
298 wxFAIL_MSG(wxT("Unimplemented"));
309 class WXDLLIMPEXP_BASE wxVariantDataLong
: public wxVariantData
311 DECLARE_DYNAMIC_CLASS(wxVariantDataLong
)
313 wxVariantDataLong() { m_value
= 0; }
314 wxVariantDataLong(long value
) { m_value
= value
; }
316 inline long GetValue() const { return m_value
; }
317 inline void SetValue(long value
) { m_value
= value
; }
319 virtual void Copy(wxVariantData
& data
);
320 virtual bool Eq(wxVariantData
& data
) const;
322 virtual bool Read(wxString
& str
);
323 virtual bool Write(wxString
& str
) const;
324 #if wxUSE_STD_IOSTREAM
325 virtual bool Read(wxSTD istream
& str
);
326 virtual bool Write(wxSTD ostream
& str
) const;
329 virtual bool Read(wxInputStream
& str
);
330 virtual bool Write(wxOutputStream
&str
) const;
331 #endif // wxUSE_STREAMS
333 virtual wxString
GetType() const { return wxT("long"); };
339 IMPLEMENT_DYNAMIC_CLASS(wxVariantDataLong
, wxVariantData
)
341 void wxVariantDataLong::Copy(wxVariantData
& data
)
343 wxASSERT_MSG( (data
.GetType() == wxT("long")), wxT("wxVariantDataLong::Copy: Can't copy to this type of data") );
345 wxVariantDataLong
& otherData
= (wxVariantDataLong
&) data
;
347 otherData
.m_value
= m_value
;
350 bool wxVariantDataLong::Eq(wxVariantData
& data
) const
352 wxASSERT_MSG( (data
.GetType() == wxT("long")), wxT("wxVariantDataLong::Eq: argument mismatch") );
354 wxVariantDataLong
& otherData
= (wxVariantDataLong
&) data
;
356 return (otherData
.m_value
== m_value
);
359 #if wxUSE_STD_IOSTREAM
360 bool wxVariantDataLong::Write(wxSTD ostream
& str
) const
364 str
<< (const char*) s
.mb_str();
369 bool wxVariantDataLong::Write(wxString
& str
) const
371 str
.Printf(wxT("%ld"), m_value
);
375 #if wxUSE_STD_IOSTREAM
376 bool wxVariantDataLong::Read(wxSTD istream
& str
)
384 bool wxVariantDataLong::Write(wxOutputStream
& str
) const
386 wxTextOutputStream
s(str
);
388 s
.Write32((size_t)m_value
);
392 bool wxVariantDataLong::Read(wxInputStream
& str
)
394 wxTextInputStream
s(str
);
395 m_value
= s
.Read32();
398 #endif // wxUSE_STREAMS
400 bool wxVariantDataLong::Read(wxString
& str
)
402 m_value
= wxAtol((const wxChar
*) str
);
410 class WXDLLIMPEXP_BASE wxVariantDataReal
: public wxVariantData
412 DECLARE_DYNAMIC_CLASS(wxVariantDataReal
)
414 wxVariantDataReal() { m_value
= 0.0; }
415 wxVariantDataReal(double value
) { m_value
= value
; }
417 inline double GetValue() const { return m_value
; }
418 inline void SetValue(double value
) { m_value
= value
; }
420 virtual void Copy(wxVariantData
& data
);
421 virtual bool Eq(wxVariantData
& data
) const;
422 virtual bool Read(wxString
& str
);
423 #if wxUSE_STD_IOSTREAM
424 virtual bool Write(wxSTD ostream
& str
) const;
426 virtual bool Write(wxString
& str
) const;
427 #if wxUSE_STD_IOSTREAM
428 virtual bool Read(wxSTD istream
& str
);
431 virtual bool Read(wxInputStream
& str
);
432 virtual bool Write(wxOutputStream
&str
) const;
433 #endif // wxUSE_STREAMS
434 virtual wxString
GetType() const { return wxT("double"); };
440 IMPLEMENT_DYNAMIC_CLASS(wxVariantDataReal
, wxVariantData
)
442 void wxVariantDataReal::Copy(wxVariantData
& data
)
444 wxASSERT_MSG( (data
.GetType() == wxT("double")), wxT("wxVariantDataReal::Copy: Can't copy to this type of data") );
446 wxVariantDataReal
& otherData
= (wxVariantDataReal
&) data
;
448 otherData
.m_value
= m_value
;
451 bool wxVariantDataReal::Eq(wxVariantData
& data
) const
453 wxASSERT_MSG( (data
.GetType() == wxT("double")), wxT("wxVariantDataReal::Eq: argument mismatch") );
455 wxVariantDataReal
& otherData
= (wxVariantDataReal
&) data
;
457 return (otherData
.m_value
== m_value
);
460 #if wxUSE_STD_IOSTREAM
461 bool wxVariantDataReal::Write(wxSTD ostream
& str
) const
465 str
<< (const char*) s
.mb_str();
470 bool wxVariantDataReal::Write(wxString
& str
) const
472 str
.Printf(wxT("%.4f"), m_value
);
476 #if wxUSE_STD_IOSTREAM
477 bool wxVariantDataReal::Read(wxSTD istream
& str
)
485 bool wxVariantDataReal::Write(wxOutputStream
& str
) const
487 wxTextOutputStream
s(str
);
488 s
.WriteDouble((double)m_value
);
492 bool wxVariantDataReal::Read(wxInputStream
& str
)
494 wxTextInputStream
s(str
);
495 m_value
= (float)s
.ReadDouble();
498 #endif // wxUSE_STREAMS
500 bool wxVariantDataReal::Read(wxString
& str
)
502 m_value
= wxAtof((const wxChar
*) str
);
511 class WXDLLIMPEXP_BASE wxVariantDataBool
: public wxVariantData
513 DECLARE_DYNAMIC_CLASS(wxVariantDataBool
)
515 wxVariantDataBool() { m_value
= 0; }
516 wxVariantDataBool(bool value
) { m_value
= value
; }
518 inline bool GetValue() const { return m_value
; }
519 inline void SetValue(bool value
) { m_value
= value
; }
521 virtual void Copy(wxVariantData
& data
);
522 virtual bool Eq(wxVariantData
& data
) const;
523 #if wxUSE_STD_IOSTREAM
524 virtual bool Write(wxSTD ostream
& str
) const;
526 virtual bool Write(wxString
& str
) const;
527 virtual bool Read(wxString
& str
);
528 #if wxUSE_STD_IOSTREAM
529 virtual bool Read(wxSTD istream
& str
);
532 virtual bool Read(wxInputStream
& str
);
533 virtual bool Write(wxOutputStream
& str
) const;
534 #endif // wxUSE_STREAMS
535 virtual wxString
GetType() const { return wxT("bool"); };
541 IMPLEMENT_DYNAMIC_CLASS(wxVariantDataBool
, wxVariantData
)
543 void wxVariantDataBool::Copy(wxVariantData
& data
)
545 wxASSERT_MSG( (data
.GetType() == wxT("bool")), wxT("wxVariantDataBool::Copy: Can't copy to this type of data") );
547 wxVariantDataBool
& otherData
= (wxVariantDataBool
&) data
;
549 otherData
.m_value
= m_value
;
552 bool wxVariantDataBool::Eq(wxVariantData
& data
) const
554 wxASSERT_MSG( (data
.GetType() == wxT("bool")), wxT("wxVariantDataBool::Eq: argument mismatch") );
556 wxVariantDataBool
& otherData
= (wxVariantDataBool
&) data
;
558 return (otherData
.m_value
== m_value
);
561 #if wxUSE_STD_IOSTREAM
562 bool wxVariantDataBool::Write(wxSTD ostream
& str
) const
566 str
<< (const char*) s
.mb_str();
571 bool wxVariantDataBool::Write(wxString
& str
) const
573 str
.Printf(wxT("%d"), (int) m_value
);
577 #if wxUSE_STD_IOSTREAM
578 bool wxVariantDataBool::Read(wxSTD istream
& WXUNUSED(str
))
580 wxFAIL_MSG(wxT("Unimplemented"));
581 // str >> (long) m_value;
587 bool wxVariantDataBool::Write(wxOutputStream
& str
) const
589 wxTextOutputStream
s(str
);
595 bool wxVariantDataBool::Read(wxInputStream
& str
)
597 wxTextInputStream
s(str
);
599 m_value
= s
.Read8() != 0;
602 #endif // wxUSE_STREAMS
604 bool wxVariantDataBool::Read(wxString
& str
)
606 m_value
= (wxAtol((const wxChar
*) str
) != 0);
615 class WXDLLIMPEXP_BASE wxVariantDataChar
: public wxVariantData
617 DECLARE_DYNAMIC_CLASS(wxVariantDataChar
)
619 wxVariantDataChar() { m_value
= 0; }
620 wxVariantDataChar(char value
) { m_value
= value
; }
622 inline char GetValue() const { return m_value
; }
623 inline void SetValue(char value
) { m_value
= value
; }
625 virtual void Copy(wxVariantData
& data
);
626 virtual bool Eq(wxVariantData
& data
) const;
627 #if wxUSE_STD_IOSTREAM
628 virtual bool Read(wxSTD istream
& str
);
629 virtual bool Write(wxSTD ostream
& str
) const;
631 virtual bool Read(wxString
& str
);
632 virtual bool Write(wxString
& str
) const;
634 virtual bool Read(wxInputStream
& str
);
635 virtual bool Write(wxOutputStream
& str
) const;
636 #endif // wxUSE_STREAMS
637 virtual wxString
GetType() const { return wxT("char"); };
643 IMPLEMENT_DYNAMIC_CLASS(wxVariantDataChar
, wxVariantData
)
645 void wxVariantDataChar::Copy(wxVariantData
& data
)
647 wxASSERT_MSG( (data
.GetType() == wxT("char")), wxT("wxVariantDataChar::Copy: Can't copy to this type of data") );
649 wxVariantDataChar
& otherData
= (wxVariantDataChar
&) data
;
651 otherData
.m_value
= m_value
;
654 bool wxVariantDataChar::Eq(wxVariantData
& data
) const
656 wxASSERT_MSG( (data
.GetType() == wxT("char")), wxT("wxVariantDataChar::Eq: argument mismatch") );
658 wxVariantDataChar
& otherData
= (wxVariantDataChar
&) data
;
660 return (otherData
.m_value
== m_value
);
663 #if wxUSE_STD_IOSTREAM
664 bool wxVariantDataChar::Write(wxSTD ostream
& str
) const
668 str
<< (const char*) s
.mb_str();
673 bool wxVariantDataChar::Write(wxString
& str
) const
675 str
.Printf(wxT("%c"), m_value
);
679 #if wxUSE_STD_IOSTREAM
680 bool wxVariantDataChar::Read(wxSTD istream
& WXUNUSED(str
))
682 wxFAIL_MSG(wxT("Unimplemented"));
689 bool wxVariantDataChar::Write(wxOutputStream
& str
) const
691 wxTextOutputStream
s(str
);
697 bool wxVariantDataChar::Read(wxInputStream
& str
)
699 wxTextInputStream
s(str
);
704 #endif // wxUSE_STREAMS
706 bool wxVariantDataChar::Read(wxString
& str
)
708 m_value
= str
.ToAscii()[0u];
713 * wxVariantDataString
716 class WXDLLIMPEXP_BASE wxVariantDataString
: public wxVariantData
718 DECLARE_DYNAMIC_CLASS(wxVariantDataString
)
720 wxVariantDataString() { }
721 wxVariantDataString(const wxString
& value
) { m_value
= value
; }
723 inline wxString
GetValue() const { return m_value
; }
724 inline void SetValue(const wxString
& value
) { m_value
= value
; }
726 virtual void Copy(wxVariantData
& data
);
727 virtual bool Eq(wxVariantData
& data
) const;
728 #if wxUSE_STD_IOSTREAM
729 virtual bool Write(wxSTD ostream
& str
) const;
731 virtual bool Read(wxString
& str
);
732 virtual bool Write(wxString
& str
) const;
733 #if wxUSE_STD_IOSTREAM
734 virtual bool Read(wxSTD istream
& str
);
737 virtual bool Read(wxInputStream
& str
);
738 virtual bool Write(wxOutputStream
& str
) const;
739 #endif // wxUSE_STREAMS
740 virtual wxString
GetType() const { return wxT("string"); };
746 void wxVariantDataString::Copy(wxVariantData
& data
)
748 wxASSERT_MSG( (data
.GetType() == wxT("string")), wxT("wxVariantDataString::Copy: Can't copy to this type of data") );
750 wxVariantDataString
& otherData
= (wxVariantDataString
&) data
;
752 otherData
.m_value
= m_value
;
755 bool wxVariantDataString::Eq(wxVariantData
& data
) const
757 wxASSERT_MSG( (data
.GetType() == wxT("string")), wxT("wxVariantDataString::Eq: argument mismatch") );
759 wxVariantDataString
& otherData
= (wxVariantDataString
&) data
;
761 return (otherData
.m_value
== m_value
);
764 #if wxUSE_STD_IOSTREAM
765 bool wxVariantDataString::Write(wxSTD ostream
& str
) const
767 str
<< (const char*) m_value
.mb_str();
772 bool wxVariantDataString::Write(wxString
& str
) const
778 #if wxUSE_STD_IOSTREAM
779 bool wxVariantDataString::Read(wxSTD istream
& str
)
787 bool wxVariantDataString::Write(wxOutputStream
& str
) const
789 // why doesn't wxOutputStream::operator<< take "const wxString&"
790 wxTextOutputStream
s(str
);
791 s
.WriteString(m_value
);
795 bool wxVariantDataString::Read(wxInputStream
& str
)
797 wxTextInputStream
s(str
);
799 m_value
= s
.ReadString();
802 #endif // wxUSE_STREAMS
804 bool wxVariantDataString::Read(wxString
& str
)
810 IMPLEMENT_DYNAMIC_CLASS(wxVariantDataString
, wxVariantData
)
813 * wxVariantDataVoidPtr
816 class wxVariantDataVoidPtr
: public wxVariantData
818 DECLARE_DYNAMIC_CLASS(wxVariantDataVoidPtr
)
820 wxVariantDataVoidPtr() { }
821 wxVariantDataVoidPtr(void* value
) { m_value
= value
; }
823 inline void* GetValue() const { return m_value
; }
824 inline void SetValue(void* value
) { m_value
= value
; }
826 virtual void Copy(wxVariantData
& data
);
827 virtual bool Eq(wxVariantData
& data
) const;
828 #if wxUSE_STD_IOSTREAM
829 virtual bool Write(wxSTD ostream
& str
) const;
831 virtual bool Write(wxString
& str
) const;
832 #if wxUSE_STD_IOSTREAM
833 virtual bool Read(wxSTD istream
& str
);
835 virtual bool Read(wxString
& str
);
836 virtual wxString
GetType() const { return wxT("void*"); };
837 virtual wxVariantData
* Clone() { return new wxVariantDataVoidPtr
; }
842 DECLARE_NO_COPY_CLASS(wxVariantDataVoidPtr
)
845 IMPLEMENT_DYNAMIC_CLASS(wxVariantDataVoidPtr
, wxVariantData
)
847 void wxVariantDataVoidPtr::Copy(wxVariantData
& data
)
849 wxASSERT_MSG( (data
.GetType() == wxT("void*")), wxT("wxVariantDataVoidPtr::Copy: Can't copy to this type of data") );
851 wxVariantDataVoidPtr
& otherData
= (wxVariantDataVoidPtr
&) data
;
853 otherData
.m_value
= m_value
;
856 bool wxVariantDataVoidPtr::Eq(wxVariantData
& data
) const
858 wxASSERT_MSG( (data
.GetType() == wxT("void*")), wxT("wxVariantDataVoidPtr::Eq: argument mismatch") );
860 wxVariantDataVoidPtr
& otherData
= (wxVariantDataVoidPtr
&) data
;
862 return (otherData
.m_value
== m_value
);
865 #if wxUSE_STD_IOSTREAM
866 bool wxVariantDataVoidPtr::Write(wxSTD ostream
& str
) const
870 str
<< (const char*) s
.mb_str();
875 bool wxVariantDataVoidPtr::Write(wxString
& str
) const
877 str
.Printf(wxT("%ld"), (long) m_value
);
881 #if wxUSE_STD_IOSTREAM
882 bool wxVariantDataVoidPtr::Read(wxSTD istream
& WXUNUSED(str
))
889 bool wxVariantDataVoidPtr::Read(wxString
& WXUNUSED(str
))
896 * wxVariantDataWxObjectPtr
899 class wxVariantDataWxObjectPtr
: public wxVariantData
901 DECLARE_DYNAMIC_CLASS(wxVariantDataWxObjectPtr
)
903 wxVariantDataWxObjectPtr() { }
904 wxVariantDataWxObjectPtr(wxObject
* value
) { m_value
= value
; }
906 inline wxObject
* GetValue() const { return m_value
; }
907 inline void SetValue(wxObject
* value
) { m_value
= value
; }
909 virtual void Copy(wxVariantData
& data
);
910 virtual bool Eq(wxVariantData
& data
) const;
911 #if wxUSE_STD_IOSTREAM
912 virtual bool Write(wxSTD ostream
& str
) const;
914 virtual bool Write(wxString
& str
) const;
915 #if wxUSE_STD_IOSTREAM
916 virtual bool Read(wxSTD istream
& str
);
918 virtual bool Read(wxString
& str
);
919 virtual wxString
GetType() const ;
920 virtual wxVariantData
* Clone() { return new wxVariantDataWxObjectPtr
; }
922 virtual wxClassInfo
* GetValueClassInfo() ;
926 DECLARE_NO_COPY_CLASS(wxVariantDataWxObjectPtr
)
929 IMPLEMENT_DYNAMIC_CLASS(wxVariantDataWxObjectPtr
, wxVariantData
)
931 void wxVariantDataWxObjectPtr::Copy(wxVariantData
& data
)
933 wxASSERT_MSG( wxIsKindOf((&data
), wxVariantDataWxObjectPtr
) ,\
934 wxT("wxVariantDataWxObjectPtr::Copy: Can't copy to this type of data") \
937 wxVariantDataWxObjectPtr
& otherData
= (wxVariantDataWxObjectPtr
&) data
;
939 otherData
.m_value
= m_value
;
942 bool wxVariantDataWxObjectPtr::Eq(wxVariantData
& data
) const
944 wxASSERT_MSG( wxIsKindOf((&data
), wxVariantDataWxObjectPtr
), wxT("wxVariantDataWxObjectPtr::Eq: argument mismatch") );
946 wxVariantDataWxObjectPtr
& otherData
= (wxVariantDataWxObjectPtr
&) data
;
948 return (otherData
.m_value
== m_value
);
951 wxString
wxVariantDataWxObjectPtr::GetType() const
953 wxString
returnVal(wxT("wxObject"));
955 returnVal
= m_value
->GetClassInfo()->GetClassName();
960 wxClassInfo
* wxVariantDataWxObjectPtr::GetValueClassInfo()
962 wxClassInfo
* returnVal
=NULL
;
964 if (m_value
) returnVal
= m_value
->GetClassInfo();
969 #if wxUSE_STD_IOSTREAM
970 bool wxVariantDataWxObjectPtr::Write(wxSTD ostream
& str
) const
974 str
<< (const char*) s
.mb_str();
979 bool wxVariantDataWxObjectPtr::Write(wxString
& str
) const
981 str
.Printf(wxT("%s(%ld)"), GetType().c_str(), (long) m_value
);
985 #if wxUSE_STD_IOSTREAM
986 bool wxVariantDataWxObjectPtr::Read(wxSTD istream
& WXUNUSED(str
))
993 bool wxVariantDataWxObjectPtr::Read(wxString
& WXUNUSED(str
))
1001 * wxVariantDataDateTime
1006 class wxVariantDataDateTime
: public wxVariantData
1008 DECLARE_DYNAMIC_CLASS(wxVariantDataDateTime
)
1011 wxVariantDataDateTime() { }
1012 wxVariantDataDateTime(const wxDateTime
& value
) { m_value
= value
; }
1014 wxVariantDataDateTime(const TIME_STRUCT
* valptr
)
1015 { m_value
= wxDateTime(valptr
->hour
, valptr
->minute
, valptr
->second
); }
1016 wxVariantDataDateTime(const DATE_STRUCT
* valptr
)
1017 { m_value
= wxDateTime(valptr
->day
, (wxDateTime::Month
) (valptr
->month
- 1),valptr
->year
); }
1018 wxVariantDataDateTime(const TIMESTAMP_STRUCT
* valptr
)
1019 { m_value
= wxDateTime(valptr
->day
, (wxDateTime::Month
) (valptr
->month
- 1), valptr
->year
,
1020 valptr
->hour
, valptr
->minute
, valptr
->second
, (wxDateTime::wxDateTime_t
)valptr
->fraction
); }
1023 inline wxDateTime
GetValue() const { return m_value
; }
1024 inline void SetValue(const wxDateTime
& value
) { m_value
= value
; }
1026 virtual void Copy(wxVariantData
& data
);
1027 virtual bool Eq(wxVariantData
& data
) const;
1028 #if wxUSE_STD_IOSTREAM
1029 virtual bool Write(wxSTD ostream
& str
) const;
1031 virtual bool Write(wxString
& str
) const;
1032 #if wxUSE_STD_IOSTREAM
1033 virtual bool Read(wxSTD istream
& str
);
1035 virtual bool Read(wxString
& str
);
1036 virtual wxString
GetType() const { return wxT("datetime"); };
1037 virtual wxVariantData
* Clone() { return new wxVariantDataDateTime
; }
1044 IMPLEMENT_DYNAMIC_CLASS(wxVariantDataDateTime
, wxVariantData
)
1046 void wxVariantDataDateTime::Copy(wxVariantData
& data
)
1048 wxASSERT_MSG( (data
.GetType() == wxT("datetime")), wxT("wxVariantDataDateTime::Copy: Can't copy to this type of data") );
1050 wxVariantDataDateTime
& otherData
= (wxVariantDataDateTime
&) data
;
1052 otherData
.m_value
= m_value
;
1056 bool wxVariantDataDateTime::Eq(wxVariantData
& data
) const
1058 wxASSERT_MSG( (data
.GetType() == wxT("datetime")), wxT("wxVariantDataDateTime::Eq: argument mismatch") );
1060 wxVariantDataDateTime
& otherData
= (wxVariantDataDateTime
&) data
;
1062 return (otherData
.m_value
== m_value
);
1066 #if wxUSE_STD_IOSTREAM
1067 bool wxVariantDataDateTime::Write(wxSTD ostream
& WXUNUSED(str
)) const
1075 bool wxVariantDataDateTime::Write(wxString
& str
) const
1077 str
= m_value
.Format();
1082 #if wxUSE_STD_IOSTREAM
1083 bool wxVariantDataDateTime::Read(wxSTD istream
& WXUNUSED(str
))
1091 bool wxVariantDataDateTime::Read(wxString
& str
)
1093 if(! m_value
.ParseDateTime(str
))
1098 #endif // wxUSE_DATETIME
1100 // ----------------------------------------------------------------------------
1101 // wxVariantDataArrayString
1102 // ----------------------------------------------------------------------------
1104 class wxVariantDataArrayString
: public wxVariantData
1107 wxVariantDataArrayString() { }
1108 wxVariantDataArrayString(const wxArrayString
& value
) { m_value
= value
; }
1110 wxArrayString
GetValue() const { return m_value
; }
1111 void SetValue(const wxArrayString
& value
) { m_value
= value
; }
1113 virtual void Copy(wxVariantData
& data
);
1114 virtual bool Eq(wxVariantData
& data
) const;
1115 #if wxUSE_STD_IOSTREAM
1116 virtual bool Write(wxSTD ostream
& str
) const;
1118 virtual bool Write(wxString
& str
) const;
1119 #if wxUSE_STD_IOSTREAM
1120 virtual bool Read(wxSTD istream
& str
);
1122 virtual bool Read(wxString
& str
);
1123 virtual wxString
GetType() const { return wxT("arrstring"); };
1124 virtual wxVariantData
* Clone() { return new wxVariantDataArrayString
; }
1127 wxArrayString m_value
;
1129 DECLARE_DYNAMIC_CLASS(wxVariantDataArrayString
)
1132 IMPLEMENT_DYNAMIC_CLASS(wxVariantDataArrayString
, wxVariantData
)
1134 void wxVariantDataArrayString::Copy(wxVariantData
& data
)
1136 wxASSERT_MSG( data
.GetType() == GetType(), wxT("wxVariantDataArrayString::Copy: Can't copy to this type of data") );
1138 wxVariantDataArrayString
& otherData
= (wxVariantDataArrayString
&) data
;
1140 otherData
.m_value
= m_value
;
1144 bool wxVariantDataArrayString::Eq(wxVariantData
& data
) const
1146 wxASSERT_MSG( data
.GetType() == GetType(), wxT("wxVariantDataArrayString::Eq: argument mismatch") );
1148 wxVariantDataArrayString
& otherData
= (wxVariantDataArrayString
&) data
;
1150 return otherData
.m_value
== m_value
;
1154 #if wxUSE_STD_IOSTREAM
1155 bool wxVariantDataArrayString::Write(wxSTD ostream
& WXUNUSED(str
)) const
1163 bool wxVariantDataArrayString::Write(wxString
& str
) const
1165 size_t count
= m_value
.GetCount();
1166 for ( size_t n
= 0; n
< count
; n
++ )
1178 #if wxUSE_STD_IOSTREAM
1179 bool wxVariantDataArrayString::Read(wxSTD istream
& WXUNUSED(str
))
1187 bool wxVariantDataArrayString::Read(wxString
& str
)
1189 wxStringTokenizer
tk(str
, _T(";"));
1190 while ( tk
.HasMoreTokens() )
1192 m_value
.Add(tk
.GetNextToken());
1204 IMPLEMENT_DYNAMIC_CLASS(wxVariant
, wxObject
)
1206 // Construction & destruction
1207 wxVariant::wxVariant()
1209 m_data
= (wxVariantData
*) NULL
;
1212 wxVariant::wxVariant(double val
, const wxString
& name
)
1214 m_data
= new wxVariantDataReal(val
);
1218 wxVariant::wxVariant(long val
, const wxString
& name
)
1220 m_data
= new wxVariantDataLong(val
);
1225 wxVariant::wxVariant(bool val
, const wxString
& name
)
1227 m_data
= new wxVariantDataBool(val
);
1232 wxVariant::wxVariant(char val
, const wxString
& name
)
1234 m_data
= new wxVariantDataChar(val
);
1238 wxVariant::wxVariant(const wxString
& val
, const wxString
& name
)
1240 m_data
= new wxVariantDataString(val
);
1244 wxVariant::wxVariant(const wxChar
* val
, const wxString
& name
)
1246 m_data
= new wxVariantDataString(wxString(val
));
1250 #if WXWIN_COMPATIBILITY_2_4
1252 wxVariant::wxVariant(const wxStringList
& val
, const wxString
& name
)
1254 m_data
= new wxVariantDataStringList(val
);
1260 wxVariant::wxVariant(const wxList
& val
, const wxString
& name
) // List of variants
1262 m_data
= new wxVariantDataList(val
);
1266 wxVariant::wxVariant( void* val
, const wxString
& name
)
1268 m_data
= new wxVariantDataVoidPtr(val
);
1272 wxVariant::wxVariant( wxObject
* val
, const wxString
& name
)
1274 m_data
= new wxVariantDataWxObjectPtr(val
);
1279 wxVariant::wxVariant(const wxDateTime
& val
, const wxString
& name
) // Date
1281 m_data
= new wxVariantDataDateTime(val
);
1284 #endif // wxUSE_DATETIME
1287 wxVariant::wxVariant(const TIME_STRUCT
* valptr
, const wxString
& name
) // Date
1289 m_data
= new wxVariantDataDateTime(valptr
);
1293 wxVariant::wxVariant(const TIMESTAMP_STRUCT
* valptr
, const wxString
& name
) // Date
1295 m_data
= new wxVariantDataDateTime(valptr
);
1299 wxVariant::wxVariant(const DATE_STRUCT
* valptr
, const wxString
& name
) // Date
1301 m_data
= new wxVariantDataDateTime(valptr
);
1304 #endif // wxUSE_ODBC
1306 wxVariant::wxVariant(const wxArrayString
& val
, const wxString
& name
) // Strings
1308 m_data
= new wxVariantDataArrayString(val
);
1312 wxVariant::wxVariant(const wxVariant
& variant
)
1315 if (!variant
.IsNull())
1317 m_data
= (wxVariantData
*) variant
.GetData()->GetClassInfo()->CreateObject();
1318 variant
.m_data
->Copy(*m_data
);
1321 m_data
= (wxVariantData
*) NULL
;
1322 m_name
= variant
.m_name
;
1325 wxVariant::wxVariant(wxVariantData
* data
, const wxString
& name
) // User-defined data
1331 wxVariant::~wxVariant()
1337 // Make NULL (i.e. delete the data)
1338 void wxVariant::MakeNull()
1344 // Generic operators
1346 void wxVariant::operator= (const wxVariant
& variant
)
1348 if (variant
.IsNull())
1354 if (IsNull() || (GetType() != variant
.GetType()))
1358 m_data
= (wxVariantData
*) variant
.GetData()->GetClassInfo()->CreateObject();
1361 variant
.GetData()->Copy(* GetData());
1363 m_name
= variant
.m_name
;
1366 // Assignment using data, e.g.
1367 // myVariant = new wxStringVariantData("hello")
1368 void wxVariant::operator= (wxVariantData
* variantData
)
1371 m_data
= variantData
;
1374 bool wxVariant::operator== (const wxVariant
& variant
) const
1376 if (IsNull() || variant
.IsNull())
1377 return (IsNull() == variant
.IsNull());
1379 return (GetData()->Eq(* variant
.GetData()));
1382 bool wxVariant::operator!= (const wxVariant
& variant
) const
1384 return (!(*this == variant
));
1388 // Specific operators
1389 bool wxVariant::operator== (double value
) const
1392 if (!Convert(&thisValue
))
1395 return (value
== thisValue
);
1398 bool wxVariant::operator!= (double value
) const
1400 return (!((*this) == value
));
1403 void wxVariant::operator= (double value
)
1405 if (GetType() == wxT("double"))
1407 ((wxVariantDataReal
*)GetData())->SetValue(value
);
1413 m_data
= new wxVariantDataReal(value
);
1417 bool wxVariant::operator== (long value
) const
1420 if (!Convert(&thisValue
))
1423 return (value
== thisValue
);
1426 bool wxVariant::operator!= (long value
) const
1428 return (!((*this) == value
));
1431 void wxVariant::operator= (long value
)
1433 if (GetType() == wxT("long"))
1435 ((wxVariantDataLong
*)GetData())->SetValue(value
);
1441 m_data
= new wxVariantDataLong(value
);
1445 bool wxVariant::operator== (char value
) const
1448 if (!Convert(&thisValue
))
1451 return (value
== thisValue
);
1454 bool wxVariant::operator!= (char value
) const
1456 return (!((*this) == value
));
1459 void wxVariant::operator= (char value
)
1461 if (GetType() == wxT("char"))
1463 ((wxVariantDataChar
*)GetData())->SetValue(value
);
1469 m_data
= new wxVariantDataChar(value
);
1474 bool wxVariant::operator== (bool value
) const
1477 if (!Convert(&thisValue
))
1480 return (value
== thisValue
);
1483 bool wxVariant::operator!= (bool value
) const
1485 return (!((*this) == value
));
1488 void wxVariant::operator= (bool value
)
1490 if (GetType() == wxT("bool"))
1492 ((wxVariantDataBool
*)GetData())->SetValue(value
);
1498 m_data
= new wxVariantDataBool(value
);
1503 bool wxVariant::operator== (const wxString
& value
) const
1506 if (!Convert(&thisValue
))
1509 return value
== thisValue
;
1512 bool wxVariant::operator!= (const wxString
& value
) const
1514 return (!((*this) == value
));
1517 void wxVariant::operator= (const wxString
& value
)
1519 if (GetType() == wxT("string"))
1521 ((wxVariantDataString
*)GetData())->SetValue(value
);
1527 m_data
= new wxVariantDataString(value
);
1531 void wxVariant::operator= (const wxChar
* value
)
1533 if (GetType() == wxT("string"))
1535 ((wxVariantDataString
*)GetData())->SetValue(wxString(value
));
1541 m_data
= new wxVariantDataString(wxString(value
));
1545 #if WXWIN_COMPATIBILITY_2_4
1547 bool wxVariant::operator== (const wxStringList
& value
) const
1549 wxASSERT_MSG( (GetType() == wxT("stringlist")), wxT("Invalid type for == operator") );
1551 wxVariantDataStringList
other(value
);
1552 return (m_data
->Eq(other
));
1555 bool wxVariant::operator!= (const wxStringList
& value
) const
1557 wxASSERT_MSG( (GetType() == wxT("stringlist")), wxT("Invalid type for == operator") );
1559 wxVariantDataStringList
other(value
);
1560 return !(m_data
->Eq(other
));
1563 void wxVariant::operator= (const wxStringList
& value
)
1565 if (GetType() == wxT("stringlist"))
1567 ((wxVariantDataStringList
*)GetData())->SetValue(value
);
1573 m_data
= new wxVariantDataStringList(value
);
1579 bool wxVariant::operator== (const wxList
& value
) const
1581 wxASSERT_MSG( (GetType() == wxT("list")), wxT("Invalid type for == operator") );
1583 wxVariantDataList
other(value
);
1584 return (m_data
->Eq(other
));
1587 bool wxVariant::operator!= (const wxList
& value
) const
1589 return (!((*this) == value
));
1592 void wxVariant::operator= (const wxList
& value
)
1594 if (GetType() == wxT("list"))
1596 ((wxVariantDataList
*)GetData())->SetValue(value
);
1602 m_data
= new wxVariantDataList(value
);
1606 bool wxVariant::operator== (void* value
) const
1608 return (value
== ((wxVariantDataVoidPtr
*)GetData())->GetValue());
1611 bool wxVariant::operator!= (void* value
) const
1613 return (!((*this) == (void*) value
));
1616 void wxVariant::operator= (void* value
)
1618 if (GetType() == wxT("void*"))
1620 ((wxVariantDataVoidPtr
*)GetData())->SetValue(value
);
1626 m_data
= new wxVariantDataVoidPtr(value
);
1631 bool wxVariant::operator== (const wxDateTime
& value
) const
1633 wxDateTime thisValue
;
1634 if (!Convert(&thisValue
))
1637 return value
.IsEqualTo(thisValue
);
1640 bool wxVariant::operator!= (const wxDateTime
& value
) const
1642 return (!((*this) == value
));
1645 void wxVariant::operator= (const wxDateTime
& value
)
1647 if (GetType() == wxT("datetime"))
1649 ((wxVariantDataDateTime
*)GetData())->SetValue(value
);
1655 m_data
= new wxVariantDataDateTime(value
);
1658 #endif // wxUSE_DATETIME
1661 void wxVariant::operator= (const DATE_STRUCT
* value
)
1665 m_data
= new wxVariantDataDateTime(value
);
1669 void wxVariant::operator= (const TIME_STRUCT
* value
)
1673 m_data
= new wxVariantDataDateTime(value
);
1677 void wxVariant::operator= (const TIMESTAMP_STRUCT
* value
)
1681 m_data
= new wxVariantDataDateTime(value
);
1684 #endif // wxUSE_ODBC
1686 bool wxVariant::operator==(const wxArrayString
& WXUNUSED(value
)) const
1688 wxFAIL_MSG( _T("TODO") );
1693 bool wxVariant::operator!=(const wxArrayString
& value
) const
1695 return !(*this == value
);
1698 void wxVariant::operator=(const wxArrayString
& value
)
1700 if (GetType() == wxT("arrstring"))
1702 ((wxVariantDataArrayString
*)GetData())->SetValue(value
);
1707 m_data
= new wxVariantDataArrayString(value
);
1711 wxArrayString
wxVariant::GetArrayString() const
1713 if ( GetType() == wxT("arrstring") )
1714 return ((wxVariantDataArrayString
*)GetData())->GetValue();
1716 return wxArrayString();
1720 // Treat a list variant as an array
1721 wxVariant
wxVariant::operator[] (size_t idx
) const
1723 #if WXWIN_COMPATIBILITY_2_4
1724 wxASSERT_MSG( (GetType() == wxT("list") || GetType() == wxT("stringlist")), wxT("Invalid type for array operator") );
1726 wxASSERT_MSG( GetType() == wxT("list"), wxT("Invalid type for array operator") );
1729 if (GetType() == wxT("list"))
1731 wxVariantDataList
* data
= (wxVariantDataList
*) m_data
;
1732 wxASSERT_MSG( (idx
< (size_t) data
->GetValue().GetCount()), wxT("Invalid index for array") );
1733 return * (wxVariant
*) (data
->GetValue().Item(idx
)->GetData());
1735 #if WXWIN_COMPATIBILITY_2_4
1736 else if (GetType() == wxT("stringlist"))
1738 wxVariantDataStringList
* data
= (wxVariantDataStringList
*) m_data
;
1739 wxASSERT_MSG( (idx
< (size_t) data
->GetValue().GetCount()), wxT("Invalid index for array") );
1741 wxString
str( (const wxChar
*) (data
->GetValue().Item(idx
)->GetData()) );
1742 wxVariant
variant( str
);
1746 return wxNullVariant
;
1749 wxVariant
& wxVariant::operator[] (size_t idx
)
1751 // We can't return a reference to a variant for a string list, since the string
1752 // is actually stored as a char*, not a variant.
1754 wxASSERT_MSG( (GetType() == wxT("list")), wxT("Invalid type for array operator") );
1756 wxVariantDataList
* data
= (wxVariantDataList
*) m_data
;
1757 wxASSERT_MSG( (idx
< (size_t) data
->GetValue().GetCount()), wxT("Invalid index for array") );
1759 return * (wxVariant
*) (data
->GetValue().Item(idx
)->GetData());
1762 // Return the number of elements in a list
1763 int wxVariant::GetCount() const
1765 #if WXWIN_COMPATIBILITY_2_4
1766 wxASSERT_MSG( (GetType() == wxT("list") || GetType() == wxT("stringlist")), wxT("Invalid type for GetCount()") );
1768 wxASSERT_MSG( GetType() == wxT("list"), wxT("Invalid type for GetCount()") );
1771 if (GetType() == wxT("list"))
1773 wxVariantDataList
* data
= (wxVariantDataList
*) m_data
;
1774 return data
->GetValue().GetCount();
1776 #if WXWIN_COMPATIBILITY_2_4
1777 else if (GetType() == wxT("stringlist"))
1779 wxVariantDataStringList
* data
= (wxVariantDataStringList
*) m_data
;
1780 return data
->GetValue().GetCount();
1786 wxString
wxVariant::MakeString() const
1791 if (GetData()->Write(str
))
1794 return wxEmptyString
;
1799 void wxVariant::SetData(wxVariantData
* data
)
1801 if (m_data
) delete m_data
;
1806 // Returns a string representing the type of the variant,
1807 // e.g. "string", "bool", "list", "double", "long"
1808 wxString
wxVariant::GetType() const
1811 return wxString(wxT("null"));
1813 return m_data
->GetType();
1817 bool wxVariant::IsType(const wxString
& type
) const
1819 return (GetType() == type
);
1822 bool wxVariant::IsValueKindOf(const wxClassInfo
* type
) const
1824 wxClassInfo
* info
=m_data
->GetValueClassInfo();
1825 return info
? info
->IsKindOf(type
) : false ;
1830 double wxVariant::GetReal() const
1833 if (Convert(& value
))
1837 wxFAIL_MSG(wxT("Could not convert to a real number"));
1842 long wxVariant::GetInteger() const
1845 if (Convert(& value
))
1849 wxFAIL_MSG(wxT("Could not convert to an integer"));
1854 char wxVariant::GetChar() const
1857 if (Convert(& value
))
1861 wxFAIL_MSG(wxT("Could not convert to a char"));
1866 bool wxVariant::GetBool() const
1869 if (Convert(& value
))
1873 wxFAIL_MSG(wxT("Could not convert to a bool"));
1878 wxString
wxVariant::GetString() const
1881 if (!Convert(& value
))
1883 wxFAIL_MSG(wxT("Could not convert to a string"));
1889 void* wxVariant::GetVoidPtr() const
1891 wxASSERT( (GetType() == wxT("void*")) );
1893 return (void*) ((wxVariantDataVoidPtr
*) m_data
)->GetValue();
1896 wxObject
* wxVariant::GetWxObjectPtr()
1898 wxASSERT(wxIsKindOf(m_data
, wxVariantDataWxObjectPtr
));
1899 return (wxObject
*) ((wxVariantDataWxObjectPtr
*) m_data
)->GetValue();
1903 wxDateTime
wxVariant::GetDateTime() const
1906 if (!Convert(& value
))
1908 wxFAIL_MSG(wxT("Could not convert to a datetime"));
1913 #endif // wxUSE_DATETIME
1915 wxList
& wxVariant::GetList() const
1917 wxASSERT( (GetType() == wxT("list")) );
1919 return (wxList
&) ((wxVariantDataList
*) m_data
)->GetValue();
1922 #if WXWIN_COMPATIBILITY_2_4
1924 wxStringList
& wxVariant::GetStringList() const
1926 wxASSERT( (GetType() == wxT("stringlist")) );
1928 return (wxStringList
&) ((wxVariantDataStringList
*) m_data
)->GetValue();
1934 void wxVariant::NullList()
1936 SetData(new wxVariantDataList());
1940 void wxVariant::Append(const wxVariant
& value
)
1942 wxList
& list
= GetList();
1944 list
.Append(new wxVariant(value
));
1947 // Insert at front of list
1948 void wxVariant::Insert(const wxVariant
& value
)
1950 wxList
& list
= GetList();
1952 list
.Insert(new wxVariant(value
));
1955 // Returns true if the variant is a member of the list
1956 bool wxVariant::Member(const wxVariant
& value
) const
1958 wxList
& list
= GetList();
1960 wxList::compatibility_iterator node
= list
.GetFirst();
1963 wxVariant
* other
= (wxVariant
*) node
->GetData();
1964 if (value
== *other
)
1966 node
= node
->GetNext();
1971 // Deletes the nth element of the list
1972 bool wxVariant::Delete(int item
)
1974 wxList
& list
= GetList();
1976 wxASSERT_MSG( (item
< (int) list
.GetCount()), wxT("Invalid index to Delete") );
1977 wxList::compatibility_iterator node
= list
.Item(item
);
1978 wxVariant
* variant
= (wxVariant
*) node
->GetData();
1985 void wxVariant::ClearList()
1987 if (!IsNull() && (GetType() == wxT("list")))
1989 ((wxVariantDataList
*) m_data
)->Clear();
1993 if (!GetType().IsSameAs(wxT("list")))
1998 m_data
= new wxVariantDataList
;
2003 bool wxVariant::Convert(long* value
) const
2005 wxString
type(GetType());
2006 if (type
== wxT("double"))
2007 *value
= (long) (((wxVariantDataReal
*)GetData())->GetValue());
2008 else if (type
== wxT("long"))
2009 *value
= ((wxVariantDataLong
*)GetData())->GetValue();
2011 else if (type
== wxT("bool"))
2012 *value
= (long) (((wxVariantDataBool
*)GetData())->GetValue());
2014 else if (type
== wxT("string"))
2015 *value
= wxAtol((const wxChar
*) ((wxVariantDataString
*)GetData())->GetValue());
2022 bool wxVariant::Convert(bool* value
) const
2024 wxString
type(GetType());
2025 if (type
== wxT("double"))
2026 *value
= ((int) (((wxVariantDataReal
*)GetData())->GetValue()) != 0);
2027 else if (type
== wxT("long"))
2028 *value
= (((wxVariantDataLong
*)GetData())->GetValue() != 0);
2030 else if (type
== wxT("bool"))
2031 *value
= ((wxVariantDataBool
*)GetData())->GetValue();
2033 else if (type
== wxT("string"))
2035 wxString
val(((wxVariantDataString
*)GetData())->GetValue());
2037 if (val
== wxT("true") || val
== wxT("yes") || val
== wxT('1') )
2039 else if (val
== wxT("false") || val
== wxT("no") || val
== wxT('0') )
2050 bool wxVariant::Convert(double* value
) const
2052 wxString
type(GetType());
2053 if (type
== wxT("double"))
2054 *value
= ((wxVariantDataReal
*)GetData())->GetValue();
2055 else if (type
== wxT("long"))
2056 *value
= (double) (((wxVariantDataLong
*)GetData())->GetValue());
2058 else if (type
== wxT("bool"))
2059 *value
= (double) (((wxVariantDataBool
*)GetData())->GetValue());
2061 else if (type
== wxT("string"))
2062 *value
= (double) wxAtof((const wxChar
*) ((wxVariantDataString
*)GetData())->GetValue());
2069 bool wxVariant::Convert(char* value
) const
2071 wxString
type(GetType());
2072 if (type
== wxT("char"))
2073 *value
= ((wxVariantDataChar
*)GetData())->GetValue();
2074 else if (type
== wxT("long"))
2075 *value
= (char) (((wxVariantDataLong
*)GetData())->GetValue());
2077 else if (type
== wxT("bool"))
2078 *value
= (char) (((wxVariantDataBool
*)GetData())->GetValue());
2086 bool wxVariant::Convert(wxString
* value
) const
2088 *value
= MakeString();
2093 bool wxVariant::Convert(wxDateTime
* value
) const
2095 wxString
type(GetType());
2096 if (type
== wxT("datetime"))
2098 *value
= ((wxVariantDataDateTime
*)GetData())->GetValue();
2101 // Fallback to string conversion
2103 return Convert(&val
) &&
2104 (value
->ParseDateTime(val
) || value
->ParseDate(val
));
2106 #endif // wxUSE_DATETIME