+// wxVariant double code
+
+wxVariant::wxVariant(double val, const wxString& name)
+{
+ m_data = new wxVariantDoubleData(val);
+ m_name = name;
+}
+
+bool wxVariant::operator== (double value) const
+{
+ double thisValue;
+ if (!Convert(&thisValue))
+ return false;
+
+ return wxIsSameDouble(value, thisValue);
+}
+
+bool wxVariant::operator!= (double value) const
+{
+ return (!((*this) == value));
+}
+
+void wxVariant::operator= (double value)
+{
+ if (GetType() == wxT("double") &&
+ m_data->GetRefCount() == 1)
+ {
+ ((wxVariantDoubleData*)GetData())->SetValue(value);
+ }
+ else
+ {
+ UnRef();
+ m_data = 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
+// -----------------------------------------------------------------
+
+#ifdef HAVE_BOOL
+
+class WXDLLIMPEXP_BASE wxVariantDataBool: public wxVariantData
+{
+DECLARE_DYNAMIC_CLASS(wxVariantDataBool)
+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"); };
+
+protected:
+ bool m_value;
+};
+
+IMPLEMENT_DYNAMIC_CLASS(wxVariantDataBool, wxVariantData)
+
+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((const wxChar*) str) != 0);
+ return true;
+}
+
+// wxVariant ****
+
+wxVariant::wxVariant(bool val, const wxString& name)
+{
+ m_data = 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_data->GetRefCount() == 1)
+ {
+ ((wxVariantDataBool*)GetData())->SetValue(value);
+ }
+ else
+ {
+ UnRef();
+ m_data = 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;
+ }
+}
+
+#endif // HAVE_BOOL
+
+// -----------------------------------------------------------------
+// wxVariantDataChar
+// -----------------------------------------------------------------
+
+class WXDLLIMPEXP_BASE wxVariantDataChar: public wxVariantData
+{
+DECLARE_DYNAMIC_CLASS(wxVariantDataChar)
+public:
+ wxVariantDataChar() { m_value = 0; }
+ wxVariantDataChar(wxChar value) { m_value = value; }
+
+ inline wxChar GetValue() const { return m_value; }
+ inline void SetValue(wxChar 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"); };
+
+protected:
+ wxChar m_value;
+};
+
+IMPLEMENT_DYNAMIC_CLASS(wxVariantDataChar, wxVariantData)
+
+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
+{
+ wxString s;
+ Write(s);
+ str << (const char*) s.mb_str();
+ return true;
+}
+#endif
+
+bool wxVariantDataChar::Write(wxString& str) const
+{
+ str.Printf(wxT("%c"), 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);
+
+ s << m_value;
+
+ return true;
+}
+
+bool wxVariantDataChar::Read(wxInputStream& str)
+{
+ wxTextInputStream s(str);
+
+ s >> m_value;
+
+ return true;
+}
+#endif // wxUSE_STREAMS
+
+bool wxVariantDataChar::Read(wxString& str)
+{
+ m_value = str[size_t(0)];
+ return true;
+}
+
+wxVariant::wxVariant(wxChar val, const wxString& name)
+{
+ m_data = new wxVariantDataChar(val);
+ m_name = name;
+}
+
+bool wxVariant::operator== (wxChar value) const
+{
+ wxChar thisValue;
+ if (!Convert(&thisValue))
+ return false;
+ else
+ return (value == thisValue);
+}
+
+bool wxVariant::operator!= (wxChar value) const
+{
+ return (!((*this) == value));
+}
+
+void wxVariant::operator= (wxChar value)
+{
+ if (GetType() == wxT("char") &&
+ m_data->GetRefCount() == 1)
+ {
+ ((wxVariantDataChar*)GetData())->SetValue(value);
+ }
+ else
+ {
+ UnRef();
+ m_data = new wxVariantDataChar(value);
+ }
+}
+
+wxChar wxVariant::GetChar() const
+{
+ wxChar value;
+ if (Convert(& value))
+ return value;
+ else
+ {
+ wxFAIL_MSG(wxT("Could not convert to a char"));
+ return 0;
+ }
+}
+
+// ----------------------------------------------------------------------------
+// wxVariantDataString
+// ----------------------------------------------------------------------------
+
+class WXDLLIMPEXP_BASE wxVariantDataString: public wxVariantData
+{
+DECLARE_DYNAMIC_CLASS(wxVariantDataString)
+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"); };
+
+protected:
+ wxString m_value;
+};
+
+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;
+}
+
+IMPLEMENT_DYNAMIC_CLASS(wxVariantDataString, wxVariantData)
+
+// wxVariant ****
+
+wxVariant::wxVariant(const wxString& val, const wxString& name)
+{
+ m_data = new wxVariantDataString(val);
+ m_name = name;
+}
+
+wxVariant::wxVariant(const wxChar* val, const wxString& name)
+{
+ m_data = new wxVariantDataString(wxString(val));
+ m_name = name;
+}
+
+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));
+}
+
+void wxVariant::operator= (const wxString& value)
+{
+ if (GetType() == wxT("string") &&
+ m_data->GetRefCount() == 1)
+ {
+ ((wxVariantDataString*)GetData())->SetValue(value);
+ }
+ else
+ {
+ UnRef();
+ m_data = new wxVariantDataString(value);
+ }
+}
+
+void wxVariant::operator= (const wxChar* value)
+{
+ if (GetType() == wxT("string") &&
+ m_data->GetRefCount() == 1)
+ {
+ ((wxVariantDataString*)GetData())->SetValue(wxString(value));
+ }
+ else
+ {
+ UnRef();
+ m_data = new wxVariantDataString(wxString(value));
+ }
+}
+
+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
+{
+DECLARE_DYNAMIC_CLASS(wxVariantDataWxObjectPtr)
+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() { return new wxVariantDataWxObjectPtr; }
+
+ virtual wxClassInfo* GetValueClassInfo() ;
+protected:
+ wxObject* m_value;
+
+ DECLARE_NO_COPY_CLASS(wxVariantDataWxObjectPtr)
+};
+
+IMPLEMENT_DYNAMIC_CLASS(wxVariantDataWxObjectPtr, wxVariantData)
+
+bool wxVariantDataWxObjectPtr::Eq(wxVariantData& data) const
+{
+ wxASSERT_MSG( wxIsKindOf((&data), wxVariantDataWxObjectPtr), 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();
+ }
+ 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(), wx_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_data = new wxVariantDataWxObjectPtr(val);
+ m_name = name;
+}
+
+bool wxVariant::operator== (wxObject* value) const
+{
+ return (value == ((wxVariantDataWxObjectPtr*)GetData())->GetValue());
+}