+ if (GetType() == wxT("double") &&
+ m_refData->GetRefCount() == 1)
+ {
+ ((wxVariantDoubleData*)GetData())->SetValue(value);
+ }
+ else
+ {
+ UnRef();
+ m_refData = new wxVariantDoubleData(value);
+ }
+}
+
+double wxVariant::GetDouble() const
+{
+ double value;
+ if (Convert(& value))
+ return value;
+ else
+ {
+ wxFAIL_MSG(wxT("Could not convert to a double number"));
+ return 0.0;
+ }
+}
+
+// -----------------------------------------------------------------
+// wxVariantBoolData
+// -----------------------------------------------------------------
+
+class WXDLLIMPEXP_BASE wxVariantDataBool: public wxVariantData
+{
+public:
+ wxVariantDataBool() { m_value = 0; }
+ wxVariantDataBool(bool value) { m_value = value; }
+
+ inline bool GetValue() const { return m_value; }
+ inline void SetValue(bool value) { m_value = value; }
+
+ virtual bool Eq(wxVariantData& data) const;
+#if wxUSE_STD_IOSTREAM
+ virtual bool Write(wxSTD ostream& str) const;
+#endif
+ virtual bool Write(wxString& str) const;
+ virtual bool Read(wxString& str);
+#if wxUSE_STD_IOSTREAM
+ virtual bool Read(wxSTD istream& str);
+#endif
+#if wxUSE_STREAMS
+ virtual bool Read(wxInputStream& str);
+ virtual bool Write(wxOutputStream& str) const;
+#endif // wxUSE_STREAMS
+ virtual wxString GetType() const { return wxT("bool"); }
+
+ wxVariantData* Clone() const { return new wxVariantDataBool(m_value); }
+
+ DECLARE_WXANY_CONVERSION()
+protected:
+ bool m_value;
+};
+
+IMPLEMENT_TRIVIAL_WXANY_CONVERSION(bool, wxVariantDataBool)
+
+bool wxVariantDataBool::Eq(wxVariantData& data) const
+{
+ wxASSERT_MSG( (data.GetType() == wxT("bool")), wxT("wxVariantDataBool::Eq: argument mismatch") );
+
+ wxVariantDataBool& otherData = (wxVariantDataBool&) data;
+
+ return (otherData.m_value == m_value);
+}
+
+#if wxUSE_STD_IOSTREAM
+bool wxVariantDataBool::Write(wxSTD ostream& str) const
+{
+ wxString s;
+ Write(s);
+ str << (const char*) s.mb_str();
+ return true;
+}
+#endif
+
+bool wxVariantDataBool::Write(wxString& str) const
+{
+ str.Printf(wxT("%d"), (int) m_value);
+ return true;
+}
+
+#if wxUSE_STD_IOSTREAM
+bool wxVariantDataBool::Read(wxSTD istream& WXUNUSED(str))
+{
+ wxFAIL_MSG(wxT("Unimplemented"));
+// str >> (long) m_value;
+ return false;
+}
+#endif
+
+#if wxUSE_STREAMS
+bool wxVariantDataBool::Write(wxOutputStream& str) const
+{
+ wxTextOutputStream s(str);
+
+ s.Write8(m_value);
+ return true;
+}
+
+bool wxVariantDataBool::Read(wxInputStream& str)
+{
+ wxTextInputStream s(str);
+
+ m_value = s.Read8() != 0;
+ return true;
+}
+#endif // wxUSE_STREAMS
+
+bool wxVariantDataBool::Read(wxString& str)
+{
+ m_value = (wxAtol(str) != 0);
+ return true;
+}
+
+// wxVariant ****
+
+wxVariant::wxVariant(bool val, const wxString& name)
+{
+ m_refData = new wxVariantDataBool(val);
+ m_name = name;
+}
+
+bool wxVariant::operator== (bool value) const
+{
+ bool thisValue;
+ if (!Convert(&thisValue))
+ return false;
+ else
+ return (value == thisValue);
+}
+
+bool wxVariant::operator!= (bool value) const
+{
+ return (!((*this) == value));
+}
+
+void wxVariant::operator= (bool value)
+{
+ if (GetType() == wxT("bool") &&
+ m_refData->GetRefCount() == 1)
+ {
+ ((wxVariantDataBool*)GetData())->SetValue(value);
+ }
+ else
+ {
+ UnRef();
+ m_refData = new wxVariantDataBool(value);
+ }
+}
+
+bool wxVariant::GetBool() const
+{
+ bool value;
+ if (Convert(& value))
+ return value;
+ else
+ {
+ wxFAIL_MSG(wxT("Could not convert to a bool"));
+ return 0;
+ }
+}
+
+// -----------------------------------------------------------------
+// wxVariantDataChar
+// -----------------------------------------------------------------
+
+class WXDLLIMPEXP_BASE wxVariantDataChar: public wxVariantData
+{
+public:
+ wxVariantDataChar() { m_value = 0; }
+ wxVariantDataChar(const wxUniChar& value) { m_value = value; }
+
+ inline wxUniChar GetValue() const { return m_value; }
+ inline void SetValue(const wxUniChar& value) { m_value = value; }
+
+ virtual bool Eq(wxVariantData& data) const;
+#if wxUSE_STD_IOSTREAM
+ virtual bool Read(wxSTD istream& str);
+ virtual bool Write(wxSTD ostream& str) const;
+#endif
+ virtual bool Read(wxString& str);
+ virtual bool Write(wxString& str) const;
+#if wxUSE_STREAMS
+ virtual bool Read(wxInputStream& str);
+ virtual bool Write(wxOutputStream& str) const;
+#endif // wxUSE_STREAMS
+ virtual wxString GetType() const { return wxT("char"); }
+ wxVariantData* Clone() const { return new wxVariantDataChar(m_value); }
+
+ DECLARE_WXANY_CONVERSION()
+protected:
+ wxUniChar m_value;
+};
+
+IMPLEMENT_TRIVIAL_WXANY_CONVERSION(wxUniChar, wxVariantDataChar)
+
+bool wxVariantDataChar::Eq(wxVariantData& data) const
+{
+ wxASSERT_MSG( (data.GetType() == wxT("char")), wxT("wxVariantDataChar::Eq: argument mismatch") );
+
+ wxVariantDataChar& otherData = (wxVariantDataChar&) data;
+
+ return (otherData.m_value == m_value);
+}
+
+#if wxUSE_STD_IOSTREAM
+bool wxVariantDataChar::Write(wxSTD ostream& str) const
+{
+ str << wxString(m_value);
+ return true;
+}
+#endif
+
+bool wxVariantDataChar::Write(wxString& str) const
+{
+ str = m_value;
+ return true;
+}
+
+#if wxUSE_STD_IOSTREAM
+bool wxVariantDataChar::Read(wxSTD istream& WXUNUSED(str))
+{
+ wxFAIL_MSG(wxT("Unimplemented"));
+
+ return false;
+}
+#endif
+
+#if wxUSE_STREAMS
+bool wxVariantDataChar::Write(wxOutputStream& str) const
+{
+ wxTextOutputStream s(str);
+
+ // FIXME-UTF8: this should be just "s << m_value;" after removal of
+ // ANSI build and addition of wxUniChar to wxTextOutputStream:
+ s << (wxChar)m_value;
+
+ return true;
+}
+
+bool wxVariantDataChar::Read(wxInputStream& str)
+{
+ wxTextInputStream s(str);
+
+ // FIXME-UTF8: this should be just "s >> m_value;" after removal of
+ // ANSI build and addition of wxUniChar to wxTextInputStream:
+ wxChar ch;
+ s >> ch;
+ m_value = ch;
+
+ return true;
+}
+#endif // wxUSE_STREAMS
+
+bool wxVariantDataChar::Read(wxString& str)
+{
+ m_value = str[0u];
+ return true;
+}
+
+wxVariant::wxVariant(const wxUniChar& val, const wxString& name)
+{
+ m_refData = new wxVariantDataChar(val);
+ m_name = name;
+}
+
+wxVariant::wxVariant(char val, const wxString& name)
+{
+ m_refData = new wxVariantDataChar(val);
+ m_name = name;
+}
+
+wxVariant::wxVariant(wchar_t val, const wxString& name)
+{
+ m_refData = new wxVariantDataChar(val);
+ m_name = name;
+}
+
+bool wxVariant::operator==(const wxUniChar& value) const
+{
+ wxUniChar thisValue;
+ if (!Convert(&thisValue))
+ return false;
+ else
+ return (value == thisValue);
+}
+
+wxVariant& wxVariant::operator=(const wxUniChar& value)
+{
+ if (GetType() == wxT("char") &&
+ m_refData->GetRefCount() == 1)
+ {
+ ((wxVariantDataChar*)GetData())->SetValue(value);
+ }
+ else
+ {
+ UnRef();
+ m_refData = new wxVariantDataChar(value);
+ }
+
+ return *this;
+}
+
+wxUniChar wxVariant::GetChar() const
+{
+ wxUniChar value;
+ if (Convert(& value))
+ return value;
+ else
+ {
+ wxFAIL_MSG(wxT("Could not convert to a char"));
+ return wxUniChar(0);
+ }
+}
+
+// ----------------------------------------------------------------------------
+// wxVariantDataString
+// ----------------------------------------------------------------------------
+
+class WXDLLIMPEXP_BASE wxVariantDataString: public wxVariantData
+{
+public:
+ wxVariantDataString() { }
+ wxVariantDataString(const wxString& value) { m_value = value; }
+
+ inline wxString GetValue() const { return m_value; }
+ inline void SetValue(const wxString& value) { m_value = value; }
+
+ virtual bool Eq(wxVariantData& data) const;
+#if wxUSE_STD_IOSTREAM
+ virtual bool Write(wxSTD ostream& str) const;
+#endif
+ virtual bool Read(wxString& str);
+ virtual bool Write(wxString& str) const;
+#if wxUSE_STD_IOSTREAM
+ virtual bool Read(wxSTD istream& WXUNUSED(str)) { return false; }
+#endif
+#if wxUSE_STREAMS
+ virtual bool Read(wxInputStream& str);
+ virtual bool Write(wxOutputStream& str) const;
+#endif // wxUSE_STREAMS
+ virtual wxString GetType() const { return wxT("string"); }
+ wxVariantData* Clone() const { return new wxVariantDataString(m_value); }
+
+ DECLARE_WXANY_CONVERSION()
+protected:
+ wxString m_value;
+};
+
+IMPLEMENT_TRIVIAL_WXANY_CONVERSION(wxString, wxVariantDataString)
+
+#if wxUSE_ANY
+// This allows converting string literal wxAnys to string variants
+wxVariantData* wxVariantDataFromConstCharPAny(const wxAny& any)
+{
+ return new wxVariantDataString(wxANY_AS(any, const char*));
+}
+
+wxVariantData* wxVariantDataFromConstWchar_tPAny(const wxAny& any)
+{
+ return new wxVariantDataString(wxANY_AS(any, const wchar_t*));
+}
+
+_REGISTER_WXANY_CONVERSION(const char*,
+ ConstCharP,
+ wxVariantDataFromConstCharPAny)
+_REGISTER_WXANY_CONVERSION(const wchar_t*,
+ ConstWchar_tP,
+ wxVariantDataFromConstWchar_tPAny)
+#endif
+
+bool wxVariantDataString::Eq(wxVariantData& data) const
+{
+ wxASSERT_MSG( (data.GetType() == wxT("string")), wxT("wxVariantDataString::Eq: argument mismatch") );
+
+ wxVariantDataString& otherData = (wxVariantDataString&) data;
+
+ return (otherData.m_value == m_value);
+}
+
+#if wxUSE_STD_IOSTREAM
+bool wxVariantDataString::Write(wxSTD ostream& str) const
+{
+ str << (const char*) m_value.mb_str();
+ return true;
+}
+#endif
+
+bool wxVariantDataString::Write(wxString& str) const
+{
+ str = m_value;
+ return true;
+}
+
+#if wxUSE_STREAMS
+bool wxVariantDataString::Write(wxOutputStream& str) const
+{
+ // why doesn't wxOutputStream::operator<< take "const wxString&"
+ wxTextOutputStream s(str);
+ s.WriteString(m_value);
+ return true;
+}
+
+bool wxVariantDataString::Read(wxInputStream& str)
+{
+ wxTextInputStream s(str);
+
+ m_value = s.ReadLine();
+ return true;
+}
+#endif // wxUSE_STREAMS
+
+bool wxVariantDataString::Read(wxString& str)
+{
+ m_value = str;
+ return true;
+}
+
+// wxVariant ****
+
+wxVariant::wxVariant(const wxString& val, const wxString& name)
+{
+ m_refData = new wxVariantDataString(val);
+ m_name = name;
+}
+
+wxVariant::wxVariant(const char* val, const wxString& name)
+{
+ m_refData = new wxVariantDataString(wxString(val));
+ m_name = name;
+}
+
+wxVariant::wxVariant(const wchar_t* val, const wxString& name)
+{
+ m_refData = new wxVariantDataString(wxString(val));
+ m_name = name;
+}
+
+wxVariant::wxVariant(const wxCStrData& val, const wxString& name)
+{
+ m_refData = new wxVariantDataString(val.AsString());
+ m_name = name;
+}
+
+wxVariant::wxVariant(const wxScopedCharBuffer& val, const wxString& name)
+{
+ m_refData = new wxVariantDataString(wxString(val));
+ m_name = name;
+}
+
+wxVariant::wxVariant(const wxScopedWCharBuffer& val, const wxString& name)
+{
+ m_refData = new wxVariantDataString(wxString(val));
+ m_name = name;
+}
+
+#if wxUSE_STD_STRING
+wxVariant::wxVariant(const std::string& val, const wxString& name)
+{
+ m_refData = new wxVariantDataString(wxString(val));
+ m_name = name;
+}
+
+wxVariant::wxVariant(const wxStdWideString& val, const wxString& name)
+{
+ m_refData = new wxVariantDataString(wxString(val));
+ m_name = name;
+}
+#endif // wxUSE_STD_STRING
+
+bool wxVariant::operator== (const wxString& value) const
+{
+ wxString thisValue;
+ if (!Convert(&thisValue))
+ return false;
+
+ return value == thisValue;
+}
+
+bool wxVariant::operator!= (const wxString& value) const
+{
+ return (!((*this) == value));
+}
+
+wxVariant& wxVariant::operator= (const wxString& value)
+{
+ if (GetType() == wxT("string") &&
+ m_refData->GetRefCount() == 1)
+ {
+ ((wxVariantDataString*)GetData())->SetValue(value);
+ }
+ else
+ {
+ UnRef();
+ m_refData = new wxVariantDataString(value);
+ }
+ return *this;
+}
+
+wxString wxVariant::GetString() const
+{
+ wxString value;
+ if (!Convert(& value))
+ {
+ wxFAIL_MSG(wxT("Could not convert to a string"));
+ }
+
+ return value;
+}
+
+// ----------------------------------------------------------------------------
+// wxVariantDataWxObjectPtr
+// ----------------------------------------------------------------------------
+
+class wxVariantDataWxObjectPtr: public wxVariantData
+{
+public:
+ wxVariantDataWxObjectPtr() { }
+ wxVariantDataWxObjectPtr(wxObject* value) { m_value = value; }
+
+ inline wxObject* GetValue() const { return m_value; }
+ inline void SetValue(wxObject* value) { m_value = value; }
+
+ virtual bool Eq(wxVariantData& data) const;
+#if wxUSE_STD_IOSTREAM
+ virtual bool Write(wxSTD ostream& str) const;
+#endif
+ virtual bool Write(wxString& str) const;
+#if wxUSE_STD_IOSTREAM
+ virtual bool Read(wxSTD istream& str);
+#endif
+ virtual bool Read(wxString& str);
+ virtual wxString GetType() const ;
+ virtual wxVariantData* Clone() const { return new wxVariantDataWxObjectPtr(m_value); }
+
+ virtual wxClassInfo* GetValueClassInfo();
+
+ DECLARE_WXANY_CONVERSION()
+protected:
+ wxObject* m_value;
+};
+
+IMPLEMENT_TRIVIAL_WXANY_CONVERSION(wxObject*, wxVariantDataWxObjectPtr)
+
+bool wxVariantDataWxObjectPtr::Eq(wxVariantData& data) const
+{
+ wxASSERT_MSG( data.GetType() == GetType(), wxT("wxVariantDataWxObjectPtr::Eq: argument mismatch") );
+
+ wxVariantDataWxObjectPtr& otherData = (wxVariantDataWxObjectPtr&) data;
+
+ return (otherData.m_value == m_value);
+}
+
+wxString wxVariantDataWxObjectPtr::GetType() const
+{
+ wxString returnVal(wxT("wxObject*"));
+
+ if (m_value)
+ {
+ returnVal = m_value->GetClassInfo()->GetClassName();
+ returnVal += wxT("*");
+ }
+
+ return returnVal;
+}
+
+wxClassInfo* wxVariantDataWxObjectPtr::GetValueClassInfo()
+{
+ wxClassInfo* returnVal=NULL;
+
+ if (m_value) returnVal = m_value->GetClassInfo();
+
+ return returnVal;
+}
+
+#if wxUSE_STD_IOSTREAM
+bool wxVariantDataWxObjectPtr::Write(wxSTD ostream& str) const
+{
+ wxString s;
+ Write(s);
+ str << (const char*) s.mb_str();
+ return true;
+}
+#endif
+
+bool wxVariantDataWxObjectPtr::Write(wxString& str) const
+{
+ str.Printf(wxT("%s(%p)"), GetType().c_str(), static_cast<void*>(m_value));
+ return true;
+}
+
+#if wxUSE_STD_IOSTREAM
+bool wxVariantDataWxObjectPtr::Read(wxSTD istream& WXUNUSED(str))
+{
+ // Not implemented
+ return false;
+}
+#endif
+
+bool wxVariantDataWxObjectPtr::Read(wxString& WXUNUSED(str))
+{
+ // Not implemented
+ return false;
+}
+
+// wxVariant
+
+wxVariant::wxVariant( wxObject* val, const wxString& name)
+{
+ m_refData = new wxVariantDataWxObjectPtr(val);
+ m_name = name;
+}
+
+bool wxVariant::operator== (wxObject* value) const
+{
+ return (value == ((wxVariantDataWxObjectPtr*)GetData())->GetValue());
+}
+
+bool wxVariant::operator!= (wxObject* value) const
+{
+ return (!((*this) == (wxObject*) value));
+}
+
+void wxVariant::operator= (wxObject* value)
+{
+ UnRef();
+ m_refData = new wxVariantDataWxObjectPtr(value);
+}
+
+wxObject* wxVariant::GetWxObjectPtr() const
+{
+ return (wxObject*) ((wxVariantDataWxObjectPtr*) m_refData)->GetValue();
+}
+
+// ----------------------------------------------------------------------------
+// wxVariantDataVoidPtr
+// ----------------------------------------------------------------------------
+
+class wxVariantDataVoidPtr: public wxVariantData
+{
+public:
+ wxVariantDataVoidPtr() { }
+ wxVariantDataVoidPtr(void* value) { m_value = value; }
+
+ inline void* GetValue() const { return m_value; }
+ inline void SetValue(void* value) { m_value = value; }
+
+ virtual bool Eq(wxVariantData& data) const;
+#if wxUSE_STD_IOSTREAM
+ virtual bool Write(wxSTD ostream& str) const;
+#endif
+ virtual bool Write(wxString& str) const;
+#if wxUSE_STD_IOSTREAM
+ virtual bool Read(wxSTD istream& str);
+#endif
+ virtual bool Read(wxString& str);
+ virtual wxString GetType() const { return wxT("void*"); }
+ virtual wxVariantData* Clone() const { return new wxVariantDataVoidPtr(m_value); }
+
+ DECLARE_WXANY_CONVERSION()
+protected:
+ void* m_value;
+};
+
+IMPLEMENT_TRIVIAL_WXANY_CONVERSION(void*, wxVariantDataVoidPtr)
+
+bool wxVariantDataVoidPtr::Eq(wxVariantData& data) const
+{
+ wxASSERT_MSG( data.GetType() == wxT("void*"), wxT("wxVariantDataVoidPtr::Eq: argument mismatch") );
+
+ wxVariantDataVoidPtr& otherData = (wxVariantDataVoidPtr&) data;
+
+ return (otherData.m_value == m_value);
+}
+
+#if wxUSE_STD_IOSTREAM
+bool wxVariantDataVoidPtr::Write(wxSTD ostream& str) const
+{
+ wxString s;
+ Write(s);
+ str << (const char*) s.mb_str();
+ return true;
+}
+#endif
+
+bool wxVariantDataVoidPtr::Write(wxString& str) const
+{
+ str.Printf(wxT("%p"), m_value);
+ return true;