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"
24 #include "wx/string.h"
28 #include "wx/stream.h"
32 #if wxUSE_STD_IOSTREAM
40 #if defined(__MWERKS__) && __MSL__ >= 0x6000
46 #include "wx/txtstrm.h"
49 #include "wx/string.h"
50 #include "wx/tokenzr.h"
52 wxVariant WXDLLIMPEXP_BASE wxNullVariant
;
55 #include "wx/listimpl.cpp"
56 WX_DEFINE_LIST(wxVariantList
)
62 IMPLEMENT_DYNAMIC_CLASS(wxVariant
, wxObject
)
64 wxVariant::wxVariant()
69 bool wxVariant::IsNull() const
71 return (m_refData
== NULL
);
74 void wxVariant::MakeNull()
79 void wxVariant::Clear()
81 m_name
= wxEmptyString
;
84 wxVariant::wxVariant(const wxVariant
& variant
)
87 if (!variant
.IsNull())
90 m_name
= variant
.m_name
;
93 wxVariant::wxVariant(wxVariantData
* data
, const wxString
& name
) // User-defined data
100 wxVariant::~wxVariant()
104 wxObjectRefData
*wxVariant::CreateRefData() const
106 // We cannot create any particular wxVariantData.
107 wxFAIL_MSG("wxVariant::CreateRefData() cannot be implemented");
111 wxObjectRefData
*wxVariant::CloneRefData(const wxObjectRefData
*data
) const
113 return ((wxVariantData
*) data
)->Clone();
117 void wxVariant::operator= (const wxVariant
& variant
)
120 m_name
= variant
.m_name
;
123 // myVariant = new wxStringVariantData("hello")
124 void wxVariant::operator= (wxVariantData
* variantData
)
127 m_refData
= variantData
;
130 bool wxVariant::operator== (const wxVariant
& variant
) const
132 if (IsNull() || variant
.IsNull())
133 return (IsNull() == variant
.IsNull());
135 if (GetType() != variant
.GetType())
138 return (GetData()->Eq(* variant
.GetData()));
141 bool wxVariant::operator!= (const wxVariant
& variant
) const
143 return (!(*this == variant
));
146 wxString
wxVariant::MakeString() const
151 if (GetData()->Write(str
))
154 return wxEmptyString
;
157 void wxVariant::SetData(wxVariantData
* data
)
163 bool wxVariant::Unshare()
165 if ( !m_refData
|| m_refData
->GetRefCount() == 1 )
170 return (m_refData
&& m_refData
->GetRefCount() == 1);
174 // Returns a string representing the type of the variant,
175 // e.g. "string", "bool", "list", "double", "long"
176 wxString
wxVariant::GetType() const
179 return wxString(wxT("null"));
181 return GetData()->GetType();
185 bool wxVariant::IsType(const wxString
& type
) const
187 return (GetType() == type
);
190 bool wxVariant::IsValueKindOf(const wxClassInfo
* type
) const
192 wxClassInfo
* info
=GetData()->GetValueClassInfo();
193 return info
? info
->IsKindOf(type
) : false ;
197 // -----------------------------------------------------------------
199 // -----------------------------------------------------------------
201 class WXDLLIMPEXP_BASE wxVariantDataLong
: public wxVariantData
204 wxVariantDataLong() { m_value
= 0; }
205 wxVariantDataLong(long value
) { m_value
= value
; }
207 inline long GetValue() const { return m_value
; }
208 inline void SetValue(long value
) { m_value
= value
; }
210 virtual bool Eq(wxVariantData
& data
) const;
212 virtual bool Read(wxString
& str
);
213 virtual bool Write(wxString
& str
) const;
214 #if wxUSE_STD_IOSTREAM
215 virtual bool Read(wxSTD istream
& str
);
216 virtual bool Write(wxSTD ostream
& str
) const;
219 virtual bool Read(wxInputStream
& str
);
220 virtual bool Write(wxOutputStream
&str
) const;
221 #endif // wxUSE_STREAMS
223 wxVariantData
* Clone() const { return new wxVariantDataLong(m_value
); }
225 virtual wxString
GetType() const { return wxT("long"); }
231 bool wxVariantDataLong::Eq(wxVariantData
& data
) const
233 wxASSERT_MSG( (data
.GetType() == wxT("long")), wxT("wxVariantDataLong::Eq: argument mismatch") );
235 wxVariantDataLong
& otherData
= (wxVariantDataLong
&) data
;
237 return (otherData
.m_value
== m_value
);
240 #if wxUSE_STD_IOSTREAM
241 bool wxVariantDataLong::Write(wxSTD ostream
& str
) const
245 str
<< (const char*) s
.mb_str();
250 bool wxVariantDataLong::Write(wxString
& str
) const
252 str
.Printf(wxT("%ld"), m_value
);
256 #if wxUSE_STD_IOSTREAM
257 bool wxVariantDataLong::Read(wxSTD istream
& str
)
265 bool wxVariantDataLong::Write(wxOutputStream
& str
) const
267 wxTextOutputStream
s(str
);
269 s
.Write32((size_t)m_value
);
273 bool wxVariantDataLong::Read(wxInputStream
& str
)
275 wxTextInputStream
s(str
);
276 m_value
= s
.Read32();
279 #endif // wxUSE_STREAMS
281 bool wxVariantDataLong::Read(wxString
& str
)
283 m_value
= wxAtol(str
);
289 wxVariant::wxVariant(long val
, const wxString
& name
)
291 m_refData
= new wxVariantDataLong(val
);
295 wxVariant::wxVariant(int val
, const wxString
& name
)
297 m_refData
= new wxVariantDataLong((long)val
);
301 wxVariant::wxVariant(short val
, const wxString
& name
)
303 m_refData
= new wxVariantDataLong((long)val
);
307 bool wxVariant::operator== (long value
) const
310 if (!Convert(&thisValue
))
313 return (value
== thisValue
);
316 bool wxVariant::operator!= (long value
) const
318 return (!((*this) == value
));
321 void wxVariant::operator= (long value
)
323 if (GetType() == wxT("long") &&
324 m_refData
->GetRefCount() == 1)
326 ((wxVariantDataLong
*)GetData())->SetValue(value
);
331 m_refData
= new wxVariantDataLong(value
);
335 long wxVariant::GetLong() const
338 if (Convert(& value
))
342 wxFAIL_MSG(wxT("Could not convert to a long"));
347 // -----------------------------------------------------------------
348 // wxVariantDoubleData
349 // -----------------------------------------------------------------
351 class WXDLLIMPEXP_BASE wxVariantDoubleData
: public wxVariantData
354 wxVariantDoubleData() { m_value
= 0.0; }
355 wxVariantDoubleData(double value
) { m_value
= value
; }
357 inline double GetValue() const { return m_value
; }
358 inline void SetValue(double value
) { m_value
= value
; }
360 virtual bool Eq(wxVariantData
& data
) const;
361 virtual bool Read(wxString
& str
);
362 #if wxUSE_STD_IOSTREAM
363 virtual bool Write(wxSTD ostream
& str
) const;
365 virtual bool Write(wxString
& str
) const;
366 #if wxUSE_STD_IOSTREAM
367 virtual bool Read(wxSTD istream
& str
);
370 virtual bool Read(wxInputStream
& str
);
371 virtual bool Write(wxOutputStream
&str
) const;
372 #endif // wxUSE_STREAMS
373 virtual wxString
GetType() const { return wxT("double"); }
375 wxVariantData
* Clone() const { return new wxVariantDoubleData(m_value
); }
380 bool wxVariantDoubleData::Eq(wxVariantData
& data
) const
382 wxASSERT_MSG( (data
.GetType() == wxT("double")), wxT("wxVariantDoubleData::Eq: argument mismatch") );
384 wxVariantDoubleData
& otherData
= (wxVariantDoubleData
&) data
;
386 return wxIsSameDouble(otherData
.m_value
, m_value
);
389 #if wxUSE_STD_IOSTREAM
390 bool wxVariantDoubleData::Write(wxSTD ostream
& str
) const
394 str
<< (const char*) s
.mb_str();
399 bool wxVariantDoubleData::Write(wxString
& str
) const
401 str
.Printf(wxT("%.14g"), m_value
);
405 #if wxUSE_STD_IOSTREAM
406 bool wxVariantDoubleData::Read(wxSTD istream
& str
)
414 bool wxVariantDoubleData::Write(wxOutputStream
& str
) const
416 wxTextOutputStream
s(str
);
417 s
.WriteDouble((double)m_value
);
421 bool wxVariantDoubleData::Read(wxInputStream
& str
)
423 wxTextInputStream
s(str
);
424 m_value
= (float)s
.ReadDouble();
427 #endif // wxUSE_STREAMS
429 bool wxVariantDoubleData::Read(wxString
& str
)
431 m_value
= wxAtof(str
);
435 // wxVariant double code
437 wxVariant::wxVariant(double val
, const wxString
& name
)
439 m_refData
= new wxVariantDoubleData(val
);
443 bool wxVariant::operator== (double value
) const
446 if (!Convert(&thisValue
))
449 return wxIsSameDouble(value
, thisValue
);
452 bool wxVariant::operator!= (double value
) const
454 return (!((*this) == value
));
457 void wxVariant::operator= (double value
)
459 if (GetType() == wxT("double") &&
460 m_refData
->GetRefCount() == 1)
462 ((wxVariantDoubleData
*)GetData())->SetValue(value
);
467 m_refData
= new wxVariantDoubleData(value
);
471 double wxVariant::GetDouble() const
474 if (Convert(& value
))
478 wxFAIL_MSG(wxT("Could not convert to a double number"));
483 // -----------------------------------------------------------------
485 // -----------------------------------------------------------------
487 class WXDLLIMPEXP_BASE wxVariantDataBool
: public wxVariantData
490 wxVariantDataBool() { m_value
= 0; }
491 wxVariantDataBool(bool value
) { m_value
= value
; }
493 inline bool GetValue() const { return m_value
; }
494 inline void SetValue(bool value
) { m_value
= value
; }
496 virtual bool Eq(wxVariantData
& data
) const;
497 #if wxUSE_STD_IOSTREAM
498 virtual bool Write(wxSTD ostream
& str
) const;
500 virtual bool Write(wxString
& str
) const;
501 virtual bool Read(wxString
& str
);
502 #if wxUSE_STD_IOSTREAM
503 virtual bool Read(wxSTD istream
& str
);
506 virtual bool Read(wxInputStream
& str
);
507 virtual bool Write(wxOutputStream
& str
) const;
508 #endif // wxUSE_STREAMS
509 virtual wxString
GetType() const { return wxT("bool"); }
511 wxVariantData
* Clone() const { return new wxVariantDataBool(m_value
); }
516 bool wxVariantDataBool::Eq(wxVariantData
& data
) const
518 wxASSERT_MSG( (data
.GetType() == wxT("bool")), wxT("wxVariantDataBool::Eq: argument mismatch") );
520 wxVariantDataBool
& otherData
= (wxVariantDataBool
&) data
;
522 return (otherData
.m_value
== m_value
);
525 #if wxUSE_STD_IOSTREAM
526 bool wxVariantDataBool::Write(wxSTD ostream
& str
) const
530 str
<< (const char*) s
.mb_str();
535 bool wxVariantDataBool::Write(wxString
& str
) const
537 str
.Printf(wxT("%d"), (int) m_value
);
541 #if wxUSE_STD_IOSTREAM
542 bool wxVariantDataBool::Read(wxSTD istream
& WXUNUSED(str
))
544 wxFAIL_MSG(wxT("Unimplemented"));
545 // str >> (long) m_value;
551 bool wxVariantDataBool::Write(wxOutputStream
& str
) const
553 wxTextOutputStream
s(str
);
559 bool wxVariantDataBool::Read(wxInputStream
& str
)
561 wxTextInputStream
s(str
);
563 m_value
= s
.Read8() != 0;
566 #endif // wxUSE_STREAMS
568 bool wxVariantDataBool::Read(wxString
& str
)
570 m_value
= (wxAtol(str
) != 0);
576 wxVariant::wxVariant(bool val
, const wxString
& name
)
578 m_refData
= new wxVariantDataBool(val
);
582 bool wxVariant::operator== (bool value
) const
585 if (!Convert(&thisValue
))
588 return (value
== thisValue
);
591 bool wxVariant::operator!= (bool value
) const
593 return (!((*this) == value
));
596 void wxVariant::operator= (bool value
)
598 if (GetType() == wxT("bool") &&
599 m_refData
->GetRefCount() == 1)
601 ((wxVariantDataBool
*)GetData())->SetValue(value
);
606 m_refData
= new wxVariantDataBool(value
);
610 bool wxVariant::GetBool() const
613 if (Convert(& value
))
617 wxFAIL_MSG(wxT("Could not convert to a bool"));
622 // -----------------------------------------------------------------
624 // -----------------------------------------------------------------
626 class WXDLLIMPEXP_BASE wxVariantDataChar
: public wxVariantData
629 wxVariantDataChar() { m_value
= 0; }
630 wxVariantDataChar(const wxUniChar
& value
) { m_value
= value
; }
632 inline wxUniChar
GetValue() const { return m_value
; }
633 inline void SetValue(const wxUniChar
& value
) { m_value
= value
; }
635 virtual bool Eq(wxVariantData
& data
) const;
636 #if wxUSE_STD_IOSTREAM
637 virtual bool Read(wxSTD istream
& str
);
638 virtual bool Write(wxSTD ostream
& str
) const;
640 virtual bool Read(wxString
& str
);
641 virtual bool Write(wxString
& str
) const;
643 virtual bool Read(wxInputStream
& str
);
644 virtual bool Write(wxOutputStream
& str
) const;
645 #endif // wxUSE_STREAMS
646 virtual wxString
GetType() const { return wxT("char"); }
647 wxVariantData
* Clone() const { return new wxVariantDataChar(m_value
); }
653 bool wxVariantDataChar::Eq(wxVariantData
& data
) const
655 wxASSERT_MSG( (data
.GetType() == wxT("char")), wxT("wxVariantDataChar::Eq: argument mismatch") );
657 wxVariantDataChar
& otherData
= (wxVariantDataChar
&) data
;
659 return (otherData
.m_value
== m_value
);
662 #if wxUSE_STD_IOSTREAM
663 bool wxVariantDataChar::Write(wxSTD ostream
& str
) const
665 str
<< wxString(m_value
);
670 bool wxVariantDataChar::Write(wxString
& str
) const
676 #if wxUSE_STD_IOSTREAM
677 bool wxVariantDataChar::Read(wxSTD istream
& WXUNUSED(str
))
679 wxFAIL_MSG(wxT("Unimplemented"));
686 bool wxVariantDataChar::Write(wxOutputStream
& str
) const
688 wxTextOutputStream
s(str
);
690 // FIXME-UTF8: this should be just "s << m_value;" after removal of
691 // ANSI build and addition of wxUniChar to wxTextOutputStream:
692 s
<< (wxChar
)m_value
;
697 bool wxVariantDataChar::Read(wxInputStream
& str
)
699 wxTextInputStream
s(str
);
701 // FIXME-UTF8: this should be just "s >> m_value;" after removal of
702 // ANSI build and addition of wxUniChar to wxTextInputStream:
709 #endif // wxUSE_STREAMS
711 bool wxVariantDataChar::Read(wxString
& str
)
717 wxVariant::wxVariant(const wxUniChar
& val
, const wxString
& name
)
719 m_refData
= new wxVariantDataChar(val
);
723 wxVariant::wxVariant(char val
, const wxString
& name
)
725 m_refData
= new wxVariantDataChar(val
);
729 wxVariant::wxVariant(wchar_t val
, const wxString
& name
)
731 m_refData
= new wxVariantDataChar(val
);
735 bool wxVariant::operator==(const wxUniChar
& value
) const
738 if (!Convert(&thisValue
))
741 return (value
== thisValue
);
744 wxVariant
& wxVariant::operator=(const wxUniChar
& value
)
746 if (GetType() == wxT("char") &&
747 m_refData
->GetRefCount() == 1)
749 ((wxVariantDataChar
*)GetData())->SetValue(value
);
754 m_refData
= new wxVariantDataChar(value
);
760 wxUniChar
wxVariant::GetChar() const
763 if (Convert(& value
))
767 wxFAIL_MSG(wxT("Could not convert to a char"));
772 // ----------------------------------------------------------------------------
773 // wxVariantDataString
774 // ----------------------------------------------------------------------------
776 class WXDLLIMPEXP_BASE wxVariantDataString
: public wxVariantData
779 wxVariantDataString() { }
780 wxVariantDataString(const wxString
& value
) { m_value
= value
; }
782 inline wxString
GetValue() const { return m_value
; }
783 inline void SetValue(const wxString
& value
) { m_value
= value
; }
785 virtual bool Eq(wxVariantData
& data
) const;
786 #if wxUSE_STD_IOSTREAM
787 virtual bool Write(wxSTD ostream
& str
) const;
789 virtual bool Read(wxString
& str
);
790 virtual bool Write(wxString
& str
) const;
791 #if wxUSE_STD_IOSTREAM
792 virtual bool Read(wxSTD istream
& WXUNUSED(str
)) { return false; }
795 virtual bool Read(wxInputStream
& str
);
796 virtual bool Write(wxOutputStream
& str
) const;
797 #endif // wxUSE_STREAMS
798 virtual wxString
GetType() const { return wxT("string"); }
799 wxVariantData
* Clone() const { return new wxVariantDataString(m_value
); }
805 bool wxVariantDataString::Eq(wxVariantData
& data
) const
807 wxASSERT_MSG( (data
.GetType() == wxT("string")), wxT("wxVariantDataString::Eq: argument mismatch") );
809 wxVariantDataString
& otherData
= (wxVariantDataString
&) data
;
811 return (otherData
.m_value
== m_value
);
814 #if wxUSE_STD_IOSTREAM
815 bool wxVariantDataString::Write(wxSTD ostream
& str
) const
817 str
<< (const char*) m_value
.mb_str();
822 bool wxVariantDataString::Write(wxString
& str
) const
829 bool wxVariantDataString::Write(wxOutputStream
& str
) const
831 // why doesn't wxOutputStream::operator<< take "const wxString&"
832 wxTextOutputStream
s(str
);
833 s
.WriteString(m_value
);
837 bool wxVariantDataString::Read(wxInputStream
& str
)
839 wxTextInputStream
s(str
);
841 m_value
= s
.ReadLine();
844 #endif // wxUSE_STREAMS
846 bool wxVariantDataString::Read(wxString
& str
)
854 wxVariant::wxVariant(const wxString
& val
, const wxString
& name
)
856 m_refData
= new wxVariantDataString(val
);
860 wxVariant::wxVariant(const char* val
, const wxString
& name
)
862 m_refData
= new wxVariantDataString(wxString(val
));
866 wxVariant::wxVariant(const wchar_t* val
, const wxString
& name
)
868 m_refData
= new wxVariantDataString(wxString(val
));
872 wxVariant::wxVariant(const wxCStrData
& val
, const wxString
& name
)
874 m_refData
= new wxVariantDataString(val
.AsString());
878 wxVariant::wxVariant(const wxScopedCharBuffer
& val
, const wxString
& name
)
880 m_refData
= new wxVariantDataString(wxString(val
));
884 wxVariant::wxVariant(const wxScopedWCharBuffer
& val
, const wxString
& name
)
886 m_refData
= new wxVariantDataString(wxString(val
));
890 bool wxVariant::operator== (const wxString
& value
) const
893 if (!Convert(&thisValue
))
896 return value
== thisValue
;
899 bool wxVariant::operator!= (const wxString
& value
) const
901 return (!((*this) == value
));
904 wxVariant
& wxVariant::operator= (const wxString
& value
)
906 if (GetType() == wxT("string") &&
907 m_refData
->GetRefCount() == 1)
909 ((wxVariantDataString
*)GetData())->SetValue(value
);
914 m_refData
= new wxVariantDataString(value
);
919 wxString
wxVariant::GetString() const
922 if (!Convert(& value
))
924 wxFAIL_MSG(wxT("Could not convert to a string"));
930 // ----------------------------------------------------------------------------
931 // wxVariantDataWxObjectPtr
932 // ----------------------------------------------------------------------------
934 class wxVariantDataWxObjectPtr
: public wxVariantData
937 wxVariantDataWxObjectPtr() { }
938 wxVariantDataWxObjectPtr(wxObject
* value
) { m_value
= value
; }
940 inline wxObject
* GetValue() const { return m_value
; }
941 inline void SetValue(wxObject
* value
) { m_value
= value
; }
943 virtual bool Eq(wxVariantData
& data
) const;
944 #if wxUSE_STD_IOSTREAM
945 virtual bool Write(wxSTD ostream
& str
) const;
947 virtual bool Write(wxString
& str
) const;
948 #if wxUSE_STD_IOSTREAM
949 virtual bool Read(wxSTD istream
& str
);
951 virtual bool Read(wxString
& str
);
952 virtual wxString
GetType() const ;
953 virtual wxVariantData
* Clone() const { return new wxVariantDataWxObjectPtr(m_value
); }
955 virtual wxClassInfo
* GetValueClassInfo();
961 bool wxVariantDataWxObjectPtr::Eq(wxVariantData
& data
) const
963 wxASSERT_MSG( data
.GetType() == GetType(), wxT("wxVariantDataWxObjectPtr::Eq: argument mismatch") );
965 wxVariantDataWxObjectPtr
& otherData
= (wxVariantDataWxObjectPtr
&) data
;
967 return (otherData
.m_value
== m_value
);
970 wxString
wxVariantDataWxObjectPtr::GetType() const
972 wxString
returnVal(wxT("wxObject*"));
976 returnVal
= m_value
->GetClassInfo()->GetClassName();
977 returnVal
+= wxT("*");
983 wxClassInfo
* wxVariantDataWxObjectPtr::GetValueClassInfo()
985 wxClassInfo
* returnVal
=NULL
;
987 if (m_value
) returnVal
= m_value
->GetClassInfo();
992 #if wxUSE_STD_IOSTREAM
993 bool wxVariantDataWxObjectPtr::Write(wxSTD ostream
& str
) const
997 str
<< (const char*) s
.mb_str();
1002 bool wxVariantDataWxObjectPtr::Write(wxString
& str
) const
1004 str
.Printf(wxT("%s(%p)"), GetType().c_str(), static_cast<void*>(m_value
));
1008 #if wxUSE_STD_IOSTREAM
1009 bool wxVariantDataWxObjectPtr::Read(wxSTD istream
& WXUNUSED(str
))
1016 bool wxVariantDataWxObjectPtr::Read(wxString
& WXUNUSED(str
))
1024 wxVariant::wxVariant( wxObject
* val
, const wxString
& name
)
1026 m_refData
= new wxVariantDataWxObjectPtr(val
);
1030 bool wxVariant::operator== (wxObject
* value
) const
1032 return (value
== ((wxVariantDataWxObjectPtr
*)GetData())->GetValue());
1035 bool wxVariant::operator!= (wxObject
* value
) const
1037 return (!((*this) == (wxObject
*) value
));
1040 void wxVariant::operator= (wxObject
* value
)
1043 m_refData
= new wxVariantDataWxObjectPtr(value
);
1046 wxObject
* wxVariant::GetWxObjectPtr() const
1048 return (wxObject
*) ((wxVariantDataWxObjectPtr
*) m_refData
)->GetValue();
1051 // ----------------------------------------------------------------------------
1052 // wxVariantDataVoidPtr
1053 // ----------------------------------------------------------------------------
1055 class wxVariantDataVoidPtr
: public wxVariantData
1058 wxVariantDataVoidPtr() { }
1059 wxVariantDataVoidPtr(void* value
) { m_value
= value
; }
1061 inline void* GetValue() const { return m_value
; }
1062 inline void SetValue(void* value
) { m_value
= value
; }
1064 virtual bool Eq(wxVariantData
& data
) const;
1065 #if wxUSE_STD_IOSTREAM
1066 virtual bool Write(wxSTD ostream
& str
) const;
1068 virtual bool Write(wxString
& str
) const;
1069 #if wxUSE_STD_IOSTREAM
1070 virtual bool Read(wxSTD istream
& str
);
1072 virtual bool Read(wxString
& str
);
1073 virtual wxString
GetType() const { return wxT("void*"); }
1074 virtual wxVariantData
* Clone() const { return new wxVariantDataVoidPtr(m_value
); }
1080 bool wxVariantDataVoidPtr::Eq(wxVariantData
& data
) const
1082 wxASSERT_MSG( data
.GetType() == wxT("void*"), wxT("wxVariantDataVoidPtr::Eq: argument mismatch") );
1084 wxVariantDataVoidPtr
& otherData
= (wxVariantDataVoidPtr
&) data
;
1086 return (otherData
.m_value
== m_value
);
1089 #if wxUSE_STD_IOSTREAM
1090 bool wxVariantDataVoidPtr::Write(wxSTD ostream
& str
) const
1094 str
<< (const char*) s
.mb_str();
1099 bool wxVariantDataVoidPtr::Write(wxString
& str
) const
1101 str
.Printf(wxT("%p"), m_value
);
1105 #if wxUSE_STD_IOSTREAM
1106 bool wxVariantDataVoidPtr::Read(wxSTD istream
& WXUNUSED(str
))
1113 bool wxVariantDataVoidPtr::Read(wxString
& WXUNUSED(str
))
1121 wxVariant::wxVariant( void* val
, const wxString
& name
)
1123 m_refData
= new wxVariantDataVoidPtr(val
);
1127 bool wxVariant::operator== (void* value
) const
1129 return (value
== ((wxVariantDataVoidPtr
*)GetData())->GetValue());
1132 bool wxVariant::operator!= (void* value
) const
1134 return (!((*this) == (void*) value
));
1137 void wxVariant::operator= (void* value
)
1139 if (GetType() == wxT("void*") && (m_refData
->GetRefCount() == 1))
1141 ((wxVariantDataVoidPtr
*)GetData())->SetValue(value
);
1146 m_refData
= new wxVariantDataVoidPtr(value
);
1150 void* wxVariant::GetVoidPtr() const
1152 // handling this specially is convenient when working with COM, see #9873
1156 wxASSERT( GetType() == wxT("void*") );
1158 return (void*) ((wxVariantDataVoidPtr
*) m_refData
)->GetValue();
1161 // ----------------------------------------------------------------------------
1162 // wxVariantDataDateTime
1163 // ----------------------------------------------------------------------------
1167 class wxVariantDataDateTime
: public wxVariantData
1170 wxVariantDataDateTime() { }
1171 wxVariantDataDateTime(const wxDateTime
& value
) { m_value
= value
; }
1173 inline wxDateTime
GetValue() const { return m_value
; }
1174 inline void SetValue(const wxDateTime
& value
) { m_value
= value
; }
1176 virtual bool Eq(wxVariantData
& data
) const;
1177 #if wxUSE_STD_IOSTREAM
1178 virtual bool Write(wxSTD ostream
& str
) const;
1180 virtual bool Write(wxString
& str
) const;
1181 #if wxUSE_STD_IOSTREAM
1182 virtual bool Read(wxSTD istream
& str
);
1184 virtual bool Read(wxString
& str
);
1185 virtual wxString
GetType() const { return wxT("datetime"); }
1186 virtual wxVariantData
* Clone() const { return new wxVariantDataDateTime(m_value
); }
1193 bool wxVariantDataDateTime::Eq(wxVariantData
& data
) const
1195 wxASSERT_MSG( (data
.GetType() == wxT("datetime")), wxT("wxVariantDataDateTime::Eq: argument mismatch") );
1197 wxVariantDataDateTime
& otherData
= (wxVariantDataDateTime
&) data
;
1199 return (otherData
.m_value
== m_value
);
1203 #if wxUSE_STD_IOSTREAM
1204 bool wxVariantDataDateTime::Write(wxSTD ostream
& str
) const
1208 str
<< value
.c_str();
1214 bool wxVariantDataDateTime::Write(wxString
& str
) const
1216 if ( m_value
.IsValid() )
1217 str
= m_value
.Format();
1219 str
= wxS("Invalid");
1224 #if wxUSE_STD_IOSTREAM
1225 bool wxVariantDataDateTime::Read(wxSTD istream
& WXUNUSED(str
))
1233 bool wxVariantDataDateTime::Read(wxString
& str
)
1235 if ( str
== wxS("Invalid") )
1237 m_value
= wxInvalidDateTime
;
1241 wxString::const_iterator end
;
1242 return m_value
.ParseDateTime(str
, &end
) && end
== str
.end();
1247 wxVariant::wxVariant(const wxDateTime
& val
, const wxString
& name
) // Date
1249 m_refData
= new wxVariantDataDateTime(val
);
1253 bool wxVariant::operator== (const wxDateTime
& value
) const
1255 wxDateTime thisValue
;
1256 if (!Convert(&thisValue
))
1259 return value
.IsEqualTo(thisValue
);
1262 bool wxVariant::operator!= (const wxDateTime
& value
) const
1264 return (!((*this) == value
));
1267 void wxVariant::operator= (const wxDateTime
& value
)
1269 if (GetType() == wxT("datetime") &&
1270 m_refData
->GetRefCount() == 1)
1272 ((wxVariantDataDateTime
*)GetData())->SetValue(value
);
1277 m_refData
= new wxVariantDataDateTime(value
);
1281 wxDateTime
wxVariant::GetDateTime() const
1284 if (!Convert(& value
))
1286 wxFAIL_MSG(wxT("Could not convert to a datetime"));
1292 #endif // wxUSE_DATETIME
1294 // ----------------------------------------------------------------------------
1295 // wxVariantDataArrayString
1296 // ----------------------------------------------------------------------------
1298 class wxVariantDataArrayString
: public wxVariantData
1301 wxVariantDataArrayString() { }
1302 wxVariantDataArrayString(const wxArrayString
& value
) { m_value
= value
; }
1304 wxArrayString
GetValue() const { return m_value
; }
1305 void SetValue(const wxArrayString
& value
) { m_value
= value
; }
1307 virtual bool Eq(wxVariantData
& data
) const;
1308 #if wxUSE_STD_IOSTREAM
1309 virtual bool Write(wxSTD ostream
& str
) const;
1311 virtual bool Write(wxString
& str
) const;
1312 #if wxUSE_STD_IOSTREAM
1313 virtual bool Read(wxSTD istream
& str
);
1315 virtual bool Read(wxString
& str
);
1316 virtual wxString
GetType() const { return wxT("arrstring"); }
1317 virtual wxVariantData
* Clone() const { return new wxVariantDataArrayString(m_value
); }
1320 wxArrayString m_value
;
1323 bool wxVariantDataArrayString::Eq(wxVariantData
& data
) const
1325 wxASSERT_MSG( data
.GetType() == GetType(), wxT("wxVariantDataArrayString::Eq: argument mismatch") );
1327 wxVariantDataArrayString
& otherData
= (wxVariantDataArrayString
&) data
;
1329 return otherData
.m_value
== m_value
;
1332 #if wxUSE_STD_IOSTREAM
1333 bool wxVariantDataArrayString::Write(wxSTD ostream
& WXUNUSED(str
)) const
1340 bool wxVariantDataArrayString::Write(wxString
& str
) const
1342 size_t count
= m_value
.GetCount();
1343 for ( size_t n
= 0; n
< count
; n
++ )
1355 #if wxUSE_STD_IOSTREAM
1356 bool wxVariantDataArrayString::Read(wxSTD istream
& WXUNUSED(str
))
1364 bool wxVariantDataArrayString::Read(wxString
& str
)
1366 wxStringTokenizer
tk(str
, wxT(";"));
1367 while ( tk
.HasMoreTokens() )
1369 m_value
.Add(tk
.GetNextToken());
1377 wxVariant::wxVariant(const wxArrayString
& val
, const wxString
& name
) // Strings
1379 m_refData
= new wxVariantDataArrayString(val
);
1383 bool wxVariant::operator==(const wxArrayString
& WXUNUSED(value
)) const
1385 wxFAIL_MSG( wxT("TODO") );
1390 bool wxVariant::operator!=(const wxArrayString
& value
) const
1392 return !(*this == value
);
1395 void wxVariant::operator=(const wxArrayString
& value
)
1397 if (GetType() == wxT("arrstring") &&
1398 m_refData
->GetRefCount() == 1)
1400 ((wxVariantDataArrayString
*)GetData())->SetValue(value
);
1405 m_refData
= new wxVariantDataArrayString(value
);
1409 wxArrayString
wxVariant::GetArrayString() const
1411 if ( GetType() == wxT("arrstring") )
1412 return ((wxVariantDataArrayString
*)GetData())->GetValue();
1414 return wxArrayString();
1417 // ----------------------------------------------------------------------------
1418 // wxVariantDataLongLong
1419 // ----------------------------------------------------------------------------
1423 class WXDLLIMPEXP_BASE wxVariantDataLongLong
: public wxVariantData
1426 wxVariantDataLongLong() { m_value
= 0; }
1427 wxVariantDataLongLong(wxLongLong value
) { m_value
= value
; }
1429 wxLongLong
GetValue() const { return m_value
; }
1430 void SetValue(wxLongLong value
) { m_value
= value
; }
1432 virtual bool Eq(wxVariantData
& data
) const;
1434 virtual bool Read(wxString
& str
);
1435 virtual bool Write(wxString
& str
) const;
1436 #if wxUSE_STD_IOSTREAM
1437 virtual bool Read(wxSTD istream
& str
);
1438 virtual bool Write(wxSTD ostream
& str
) const;
1441 virtual bool Read(wxInputStream
& str
);
1442 virtual bool Write(wxOutputStream
&str
) const;
1443 #endif // wxUSE_STREAMS
1445 wxVariantData
* Clone() const
1447 return new wxVariantDataLongLong(m_value
);
1450 virtual wxString
GetType() const { return wxS("longlong"); }
1456 bool wxVariantDataLongLong::Eq(wxVariantData
& data
) const
1458 wxASSERT_MSG( (data
.GetType() == wxS("longlong")),
1459 "wxVariantDataLongLong::Eq: argument mismatch" );
1461 wxVariantDataLongLong
& otherData
= (wxVariantDataLongLong
&) data
;
1463 return (otherData
.m_value
== m_value
);
1466 #if wxUSE_STD_IOSTREAM
1467 bool wxVariantDataLongLong::Write(wxSTD ostream
& str
) const
1471 str
<< (const char*) s
.mb_str();
1476 bool wxVariantDataLongLong::Write(wxString
& str
) const
1479 str
.Printf(wxS("%lld"), m_value
.GetValue());
1486 #if wxUSE_STD_IOSTREAM
1487 bool wxVariantDataLongLong::Read(wxSTD istream
& WXUNUSED(str
))
1489 wxFAIL_MSG(wxS("Unimplemented"));
1495 bool wxVariantDataLongLong::Write(wxOutputStream
& str
) const
1497 wxTextOutputStream
s(str
);
1498 s
.Write32(m_value
.GetLo());
1499 s
.Write32(m_value
.GetHi());
1503 bool wxVariantDataLongLong::Read(wxInputStream
& str
)
1505 wxTextInputStream
s(str
);
1506 unsigned long lo
= s
.Read32();
1507 long hi
= s
.Read32();
1508 m_value
= wxLongLong(hi
, lo
);
1511 #endif // wxUSE_STREAMS
1513 bool wxVariantDataLongLong::Read(wxString
& str
)
1516 wxLongLong_t value_t
;
1517 if ( !str
.ToLongLong(&value_t
) )
1528 wxVariant::wxVariant(wxLongLong val
, const wxString
& name
)
1530 m_refData
= new wxVariantDataLongLong(val
);
1534 bool wxVariant::operator==(wxLongLong value
) const
1536 wxLongLong thisValue
;
1537 if ( !Convert(&thisValue
) )
1540 return (value
== thisValue
);
1543 bool wxVariant::operator!=(wxLongLong value
) const
1545 return (!((*this) == value
));
1548 void wxVariant::operator=(wxLongLong value
)
1550 if ( GetType() == wxS("longlong") &&
1551 m_refData
->GetRefCount() == 1 )
1553 ((wxVariantDataLongLong
*)GetData())->SetValue(value
);
1558 m_refData
= new wxVariantDataLongLong(value
);
1562 wxLongLong
wxVariant::GetLongLong() const
1565 if ( Convert(&value
) )
1571 wxFAIL_MSG(wxT("Could not convert to a long long"));
1576 #endif // wxUSE_LONGLONG
1578 // ----------------------------------------------------------------------------
1579 // wxVariantDataULongLong
1580 // ----------------------------------------------------------------------------
1584 class WXDLLIMPEXP_BASE wxVariantDataULongLong
: public wxVariantData
1587 wxVariantDataULongLong() { m_value
= 0; }
1588 wxVariantDataULongLong(wxULongLong value
) { m_value
= value
; }
1590 wxULongLong
GetValue() const { return m_value
; }
1591 void SetValue(wxULongLong value
) { m_value
= value
; }
1593 virtual bool Eq(wxVariantData
& data
) const;
1595 virtual bool Read(wxString
& str
);
1596 virtual bool Write(wxString
& str
) const;
1597 #if wxUSE_STD_IOSTREAM
1598 virtual bool Read(wxSTD istream
& str
);
1599 virtual bool Write(wxSTD ostream
& str
) const;
1602 virtual bool Read(wxInputStream
& str
);
1603 virtual bool Write(wxOutputStream
&str
) const;
1604 #endif // wxUSE_STREAMS
1606 wxVariantData
* Clone() const
1608 return new wxVariantDataULongLong(m_value
);
1611 virtual wxString
GetType() const { return wxS("ulonglong"); }
1614 wxULongLong m_value
;
1617 bool wxVariantDataULongLong::Eq(wxVariantData
& data
) const
1619 wxASSERT_MSG( (data
.GetType() == wxS("ulonglong")),
1620 "wxVariantDataULongLong::Eq: argument mismatch" );
1622 wxVariantDataULongLong
& otherData
= (wxVariantDataULongLong
&) data
;
1624 return (otherData
.m_value
== m_value
);
1627 #if wxUSE_STD_IOSTREAM
1628 bool wxVariantDataULongLong::Write(wxSTD ostream
& str
) const
1632 str
<< (const char*) s
.mb_str();
1637 bool wxVariantDataULongLong::Write(wxString
& str
) const
1640 str
.Printf(wxS("%llu"), m_value
.GetValue());
1647 #if wxUSE_STD_IOSTREAM
1648 bool wxVariantDataULongLong::Read(wxSTD istream
& WXUNUSED(str
))
1650 wxFAIL_MSG(wxS("Unimplemented"));
1656 bool wxVariantDataULongLong::Write(wxOutputStream
& str
) const
1658 wxTextOutputStream
s(str
);
1659 s
.Write32(m_value
.GetLo());
1660 s
.Write32(m_value
.GetHi());
1664 bool wxVariantDataULongLong::Read(wxInputStream
& str
)
1666 wxTextInputStream
s(str
);
1667 unsigned long lo
= s
.Read32();
1668 long hi
= s
.Read32();
1669 m_value
= wxULongLong(hi
, lo
);
1672 #endif // wxUSE_STREAMS
1674 bool wxVariantDataULongLong::Read(wxString
& str
)
1677 wxULongLong_t value_t
;
1678 if ( !str
.ToULongLong(&value_t
) )
1689 wxVariant::wxVariant(wxULongLong val
, const wxString
& name
)
1691 m_refData
= new wxVariantDataULongLong(val
);
1695 bool wxVariant::operator==(wxULongLong value
) const
1697 wxULongLong thisValue
;
1698 if ( !Convert(&thisValue
) )
1701 return (value
== thisValue
);
1704 bool wxVariant::operator!=(wxULongLong value
) const
1706 return (!((*this) == value
));
1709 void wxVariant::operator=(wxULongLong value
)
1711 if ( GetType() == wxS("ulonglong") &&
1712 m_refData
->GetRefCount() == 1 )
1714 ((wxVariantDataULongLong
*)GetData())->SetValue(value
);
1719 m_refData
= new wxVariantDataULongLong(value
);
1723 wxULongLong
wxVariant::GetULongLong() const
1726 if ( Convert(&value
) )
1732 wxFAIL_MSG(wxT("Could not convert to a long long"));
1737 #endif // wxUSE_LONGLONG
1739 // ----------------------------------------------------------------------------
1740 // wxVariantDataList
1741 // ----------------------------------------------------------------------------
1743 class WXDLLIMPEXP_BASE wxVariantDataList
: public wxVariantData
1746 wxVariantDataList() {}
1747 wxVariantDataList(const wxVariantList
& list
);
1748 virtual ~wxVariantDataList();
1750 wxVariantList
& GetValue() { return m_value
; }
1751 void SetValue(const wxVariantList
& value
) ;
1753 virtual bool Eq(wxVariantData
& data
) const;
1754 #if wxUSE_STD_IOSTREAM
1755 virtual bool Write(wxSTD ostream
& str
) const;
1757 virtual bool Write(wxString
& str
) const;
1758 #if wxUSE_STD_IOSTREAM
1759 virtual bool Read(wxSTD istream
& str
);
1761 virtual bool Read(wxString
& str
);
1762 virtual wxString
GetType() const { return wxT("list"); }
1766 wxVariantData
* Clone() const { return new wxVariantDataList(m_value
); }
1768 wxVariantList m_value
;
1771 wxVariantDataList::wxVariantDataList(const wxVariantList
& list
)
1776 wxVariantDataList::~wxVariantDataList()
1781 void wxVariantDataList::SetValue(const wxVariantList
& value
)
1784 wxVariantList::compatibility_iterator node
= value
.GetFirst();
1787 wxVariant
* var
= node
->GetData();
1788 m_value
.Append(new wxVariant(*var
));
1789 node
= node
->GetNext();
1793 void wxVariantDataList::Clear()
1795 wxVariantList::compatibility_iterator node
= m_value
.GetFirst();
1798 wxVariant
* var
= node
->GetData();
1800 node
= node
->GetNext();
1805 bool wxVariantDataList::Eq(wxVariantData
& data
) const
1807 wxASSERT_MSG( (data
.GetType() == wxT("list")), wxT("wxVariantDataList::Eq: argument mismatch") );
1809 wxVariantDataList
& listData
= (wxVariantDataList
&) data
;
1810 wxVariantList::compatibility_iterator node1
= m_value
.GetFirst();
1811 wxVariantList::compatibility_iterator node2
= listData
.GetValue().GetFirst();
1812 while (node1
&& node2
)
1814 wxVariant
* var1
= node1
->GetData();
1815 wxVariant
* var2
= node2
->GetData();
1816 if ((*var1
) != (*var2
))
1818 node1
= node1
->GetNext();
1819 node2
= node2
->GetNext();
1821 if (node1
|| node2
) return false;
1825 #if wxUSE_STD_IOSTREAM
1826 bool wxVariantDataList::Write(wxSTD ostream
& str
) const
1830 str
<< (const char*) s
.mb_str();
1835 bool wxVariantDataList::Write(wxString
& str
) const
1837 str
= wxEmptyString
;
1838 wxVariantList::compatibility_iterator node
= m_value
.GetFirst();
1841 wxVariant
* var
= node
->GetData();
1842 if (node
!= m_value
.GetFirst())
1845 str
+= var
->MakeString();
1846 node
= node
->GetNext();
1852 #if wxUSE_STD_IOSTREAM
1853 bool wxVariantDataList::Read(wxSTD istream
& WXUNUSED(str
))
1855 wxFAIL_MSG(wxT("Unimplemented"));
1861 bool wxVariantDataList::Read(wxString
& WXUNUSED(str
))
1863 wxFAIL_MSG(wxT("Unimplemented"));
1870 wxVariant::wxVariant(const wxVariantList
& val
, const wxString
& name
) // List of variants
1872 m_refData
= new wxVariantDataList(val
);
1876 bool wxVariant::operator== (const wxVariantList
& value
) const
1878 wxASSERT_MSG( (GetType() == wxT("list")), wxT("Invalid type for == operator") );
1880 wxVariantDataList
other(value
);
1881 return (GetData()->Eq(other
));
1884 bool wxVariant::operator!= (const wxVariantList
& value
) const
1886 return (!((*this) == value
));
1889 void wxVariant::operator= (const wxVariantList
& value
)
1891 if (GetType() == wxT("list") &&
1892 m_refData
->GetRefCount() == 1)
1894 ((wxVariantDataList
*)GetData())->SetValue(value
);
1899 m_refData
= new wxVariantDataList(value
);
1903 wxVariantList
& wxVariant::GetList() const
1905 wxASSERT( (GetType() == wxT("list")) );
1907 return (wxVariantList
&) ((wxVariantDataList
*) m_refData
)->GetValue();
1911 void wxVariant::NullList()
1913 SetData(new wxVariantDataList());
1917 void wxVariant::Append(const wxVariant
& value
)
1919 wxVariantList
& list
= GetList();
1921 list
.Append(new wxVariant(value
));
1924 // Insert at front of list
1925 void wxVariant::Insert(const wxVariant
& value
)
1927 wxVariantList
& list
= GetList();
1929 list
.Insert(new wxVariant(value
));
1932 // Returns true if the variant is a member of the list
1933 bool wxVariant::Member(const wxVariant
& value
) const
1935 wxVariantList
& list
= GetList();
1937 wxVariantList::compatibility_iterator node
= list
.GetFirst();
1940 wxVariant
* other
= node
->GetData();
1941 if (value
== *other
)
1943 node
= node
->GetNext();
1948 // Deletes the nth element of the list
1949 bool wxVariant::Delete(size_t item
)
1951 wxVariantList
& list
= GetList();
1953 wxASSERT_MSG( (item
< list
.GetCount()), wxT("Invalid index to Delete") );
1954 wxVariantList::compatibility_iterator node
= list
.Item(item
);
1955 wxVariant
* variant
= node
->GetData();
1962 void wxVariant::ClearList()
1964 if (!IsNull() && (GetType() == wxT("list")))
1966 ((wxVariantDataList
*) m_refData
)->Clear();
1970 if (!GetType().IsSameAs(wxT("list")))
1973 m_refData
= new wxVariantDataList
;
1977 // Treat a list variant as an array
1978 wxVariant
wxVariant::operator[] (size_t idx
) const
1980 wxASSERT_MSG( GetType() == wxT("list"), wxT("Invalid type for array operator") );
1982 if (GetType() == wxT("list"))
1984 wxVariantDataList
* data
= (wxVariantDataList
*) m_refData
;
1985 wxASSERT_MSG( (idx
< data
->GetValue().GetCount()), wxT("Invalid index for array") );
1986 return *(data
->GetValue().Item(idx
)->GetData());
1988 return wxNullVariant
;
1991 wxVariant
& wxVariant::operator[] (size_t idx
)
1993 // We can't return a reference to a variant for a string list, since the string
1994 // is actually stored as a char*, not a variant.
1996 wxASSERT_MSG( (GetType() == wxT("list")), wxT("Invalid type for array operator") );
1998 wxVariantDataList
* data
= (wxVariantDataList
*) m_refData
;
1999 wxASSERT_MSG( (idx
< data
->GetValue().GetCount()), wxT("Invalid index for array") );
2001 return * (data
->GetValue().Item(idx
)->GetData());
2004 // Return the number of elements in a list
2005 size_t wxVariant::GetCount() const
2007 wxASSERT_MSG( GetType() == wxT("list"), wxT("Invalid type for GetCount()") );
2009 if (GetType() == wxT("list"))
2011 wxVariantDataList
* data
= (wxVariantDataList
*) m_refData
;
2012 return data
->GetValue().GetCount();
2017 // ----------------------------------------------------------------------------
2019 // ----------------------------------------------------------------------------
2021 bool wxVariant::Convert(long* value
) const
2023 wxString
type(GetType());
2024 if (type
== wxS("double"))
2025 *value
= (long) (((wxVariantDoubleData
*)GetData())->GetValue());
2026 else if (type
== wxS("long"))
2027 *value
= ((wxVariantDataLong
*)GetData())->GetValue();
2028 else if (type
== wxS("bool"))
2029 *value
= (long) (((wxVariantDataBool
*)GetData())->GetValue());
2030 else if (type
== wxS("string"))
2031 *value
= wxAtol(((wxVariantDataString
*)GetData())->GetValue());
2033 else if (type
== wxS("longlong"))
2035 wxLongLong v
= ((wxVariantDataLongLong
*)GetData())->GetValue();
2036 // Don't convert if return value would be vague
2037 if ( v
< LONG_MIN
|| v
> LONG_MAX
)
2039 *value
= v
.ToLong();
2041 else if (type
== wxS("ulonglong"))
2043 wxULongLong v
= ((wxVariantDataULongLong
*)GetData())->GetValue();
2044 // Don't convert if return value would be vague
2047 *value
= (long) v
.ToULong();
2056 bool wxVariant::Convert(bool* value
) const
2058 wxString
type(GetType());
2059 if (type
== wxT("double"))
2060 *value
= ((int) (((wxVariantDoubleData
*)GetData())->GetValue()) != 0);
2061 else if (type
== wxT("long"))
2062 *value
= (((wxVariantDataLong
*)GetData())->GetValue() != 0);
2063 else if (type
== wxT("bool"))
2064 *value
= ((wxVariantDataBool
*)GetData())->GetValue();
2065 else if (type
== wxT("string"))
2067 wxString
val(((wxVariantDataString
*)GetData())->GetValue());
2069 if (val
== wxT("true") || val
== wxT("yes") || val
== wxT('1') )
2071 else if (val
== wxT("false") || val
== wxT("no") || val
== wxT('0') )
2082 bool wxVariant::Convert(double* value
) const
2084 wxString
type(GetType());
2085 if (type
== wxT("double"))
2086 *value
= ((wxVariantDoubleData
*)GetData())->GetValue();
2087 else if (type
== wxT("long"))
2088 *value
= (double) (((wxVariantDataLong
*)GetData())->GetValue());
2089 else if (type
== wxT("bool"))
2090 *value
= (double) (((wxVariantDataBool
*)GetData())->GetValue());
2091 else if (type
== wxT("string"))
2092 *value
= (double) wxAtof(((wxVariantDataString
*)GetData())->GetValue());
2094 else if (type
== wxS("longlong"))
2096 *value
= ((wxVariantDataLongLong
*)GetData())->GetValue().ToDouble();
2098 else if (type
== wxS("ulonglong"))
2100 *value
= ((wxVariantDataULongLong
*)GetData())->GetValue().ToDouble();
2109 bool wxVariant::Convert(wxUniChar
* value
) const
2111 wxString
type(GetType());
2112 if (type
== wxT("char"))
2113 *value
= ((wxVariantDataChar
*)GetData())->GetValue();
2114 else if (type
== wxT("long"))
2115 *value
= (char) (((wxVariantDataLong
*)GetData())->GetValue());
2116 else if (type
== wxT("bool"))
2117 *value
= (char) (((wxVariantDataBool
*)GetData())->GetValue());
2124 bool wxVariant::Convert(char* value
) const
2127 if ( !Convert(&ch
) )
2133 bool wxVariant::Convert(wchar_t* value
) const
2136 if ( !Convert(&ch
) )
2142 bool wxVariant::Convert(wxString
* value
) const
2144 *value
= MakeString();
2149 bool wxVariant::Convert(wxLongLong
* value
) const
2151 wxString
type(GetType());
2152 if (type
== wxS("longlong"))
2153 *value
= ((wxVariantDataLongLong
*)GetData())->GetValue();
2154 else if (type
== wxS("long"))
2155 *value
= ((wxVariantDataLong
*)GetData())->GetValue();
2156 else if (type
== wxS("string"))
2158 wxString s
= ((wxVariantDataString
*)GetData())->GetValue();
2160 wxLongLong_t value_t
;
2161 if ( !s
.ToLongLong(&value_t
) )
2166 if ( !s
.ToLong(&l_value
) )
2171 else if (type
== wxS("bool"))
2172 *value
= (long) (((wxVariantDataBool
*)GetData())->GetValue());
2173 else if (type
== wxS("double"))
2175 value
->Assign(((wxVariantDoubleData
*)GetData())->GetValue());
2177 else if (type
== wxS("ulonglong"))
2178 *value
= ((wxVariantDataULongLong
*)GetData())->GetValue();
2185 bool wxVariant::Convert(wxULongLong
* value
) const
2187 wxString
type(GetType());
2188 if (type
== wxS("ulonglong"))
2189 *value
= ((wxVariantDataULongLong
*)GetData())->GetValue();
2190 else if (type
== wxS("long"))
2191 *value
= ((wxVariantDataLong
*)GetData())->GetValue();
2192 else if (type
== wxS("string"))
2194 wxString s
= ((wxVariantDataString
*)GetData())->GetValue();
2196 wxULongLong_t value_t
;
2197 if ( !s
.ToULongLong(&value_t
) )
2201 unsigned long l_value
;
2202 if ( !s
.ToULong(&l_value
) )
2207 else if (type
== wxS("bool"))
2208 *value
= (long) (((wxVariantDataBool
*)GetData())->GetValue());
2209 else if (type
== wxS("double"))
2211 double value_d
= ((wxVariantDoubleData
*)GetData())->GetValue();
2213 if ( value_d
< 0.0 )
2217 *value
= (wxULongLong_t
) value_d
;
2220 temp
.Assign(value_d
);
2224 else if (type
== wxS("longlong"))
2225 *value
= ((wxVariantDataLongLong
*)GetData())->GetValue();
2231 #endif // wxUSE_LONGLONG
2234 bool wxVariant::Convert(wxDateTime
* value
) const
2236 wxString
type(GetType());
2237 if (type
== wxT("datetime"))
2239 *value
= ((wxVariantDataDateTime
*)GetData())->GetValue();
2243 // Fallback to string conversion
2245 if ( !Convert(&val
) )
2248 // Try to parse this as either date and time, only date or only time
2249 // checking that the entire string was parsed
2250 wxString::const_iterator end
;
2251 if ( value
->ParseDateTime(val
, &end
) && end
== val
.end() )
2254 if ( value
->ParseDate(val
, &end
) && end
== val
.end() )
2257 if ( value
->ParseTime(val
, &end
) && end
== val
.end() )
2262 #endif // wxUSE_DATETIME
2264 #endif // wxUSE_VARIANT