X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/9a0a58f5afb88fc72f04333e32208e3b3bf2ccc5..472137baebae6c011ad7d70285de454b9ce7796d:/src/common/variant.cpp diff --git a/src/common/variant.cpp b/src/common/variant.cpp index c7a0e1b3ba..42c9742966 100644 --- a/src/common/variant.cpp +++ b/src/common/variant.cpp @@ -53,7 +53,7 @@ wxVariant WXDLLIMPEXP_BASE wxNullVariant; #include "wx/listimpl.cpp" -WX_DEFINE_LIST(wxVariantList); +WX_DEFINE_LIST(wxVariantList) /* * wxVariant @@ -122,6 +122,9 @@ bool wxVariant::operator== (const wxVariant& variant) const if (IsNull() || variant.IsNull()) return (IsNull() == variant.IsNull()); + if (GetType() != variant.GetType()) + return false; + return (GetData()->Eq(* variant.GetData())); } @@ -130,7 +133,6 @@ bool wxVariant::operator!= (const wxVariant& variant) const return (!(*this == variant)); } - wxString wxVariant::MakeString() const { if (!IsNull()) @@ -177,6 +179,30 @@ void wxVariant::UnRef() } } +bool wxVariant::Unshare() +{ + if ( m_data && m_data->GetRefCount() > 1 ) + { + // note that ref is not going to be destroyed in this case... + const wxVariantData* ref = m_data; + UnRef(); + + // ... so we can still access it + m_data = ref->Clone(); + + wxASSERT_MSG( (m_data && m_data->GetRefCount() == 1), + _T("wxVariant::AllocExclusive() failed.") ); + + if (!m_data || m_data->GetRefCount() != 1) + return false; + else + return true; + } + //else: data is null or ref count is 1, so we are exclusive owners of m_refData anyhow + else + return true; +} + // Returns a string representing the type of the variant, // e.g. "string", "bool", "list", "double", "long" @@ -227,6 +253,8 @@ public: virtual bool Write(wxOutputStream &str) const; #endif // wxUSE_STREAMS + wxVariantData* Clone() const { return new wxVariantDataLong(m_value); } + virtual wxString GetType() const { return wxT("long"); } protected: @@ -377,6 +405,7 @@ public: #endif // wxUSE_STREAMS virtual wxString GetType() const { return wxT("double"); } + wxVariantData* Clone() const { return new wxVariantDoubleData(m_value); } protected: double m_value; }; @@ -514,6 +543,7 @@ public: #endif // wxUSE_STREAMS virtual wxString GetType() const { return wxT("bool"); } + wxVariantData* Clone() const { return new wxVariantDataBool(m_value); } protected: bool m_value; }; @@ -651,6 +681,7 @@ public: virtual bool Write(wxOutputStream& str) const; #endif // wxUSE_STREAMS virtual wxString GetType() const { return wxT("char"); } + wxVariantData* Clone() const { return new wxVariantDataChar(m_value); } protected: wxUniChar m_value; @@ -802,6 +833,7 @@ public: virtual bool Write(wxOutputStream& str) const; #endif // wxUSE_STREAMS virtual wxString GetType() const { return wxT("string"); } + wxVariantData* Clone() const { return new wxVariantDataString(m_value); } protected: wxString m_value; @@ -955,10 +987,10 @@ public: #endif virtual bool Read(wxString& str); virtual wxString GetType() const ; - virtual wxVariantData* Clone() { return new wxVariantDataWxObjectPtr; } + virtual wxVariantData* Clone() const { return new wxVariantDataWxObjectPtr(m_value); } virtual wxClassInfo* GetValueClassInfo(); - + protected: wxObject* m_value; }; @@ -975,13 +1007,13 @@ bool wxVariantDataWxObjectPtr::Eq(wxVariantData& data) const wxString wxVariantDataWxObjectPtr::GetType() const { wxString returnVal(wxT("wxObject*")); - + if (m_value) { returnVal = m_value->GetClassInfo()->GetClassName(); returnVal += wxT("*"); } - + return returnVal; } @@ -1076,7 +1108,7 @@ public: #endif virtual bool Read(wxString& str); virtual wxString GetType() const { return wxT("void*"); } - virtual wxVariantData* Clone() { return new wxVariantDataVoidPtr; } + virtual wxVariantData* Clone() const { return new wxVariantDataVoidPtr(m_value); } protected: void* m_value; @@ -1170,15 +1202,6 @@ class wxVariantDataDateTime: public wxVariantData public: wxVariantDataDateTime() { } wxVariantDataDateTime(const wxDateTime& value) { m_value = value; } -#if wxUSE_ODBC - wxVariantDataDateTime(const TIME_STRUCT* valptr) - { m_value = wxDateTime(valptr->hour, valptr->minute, valptr->second); } - wxVariantDataDateTime(const DATE_STRUCT* valptr) - { m_value = wxDateTime(valptr->day, (wxDateTime::Month) (valptr->month - 1),valptr->year); } - wxVariantDataDateTime(const TIMESTAMP_STRUCT* valptr) - { m_value = wxDateTime(valptr->day, (wxDateTime::Month) (valptr->month - 1), valptr->year, - valptr->hour, valptr->minute, valptr->second, (wxDateTime::wxDateTime_t)valptr->fraction ); } -#endif //ODBC inline wxDateTime GetValue() const { return m_value; } inline void SetValue(const wxDateTime& value) { m_value = value; } @@ -1193,7 +1216,7 @@ public: #endif virtual bool Read(wxString& str); virtual wxString GetType() const { return wxT("datetime"); } - virtual wxVariantData* Clone() { return new wxVariantDataDateTime; } + virtual wxVariantData* Clone() const { return new wxVariantDataDateTime(m_value); } protected: wxDateTime m_value; @@ -1252,26 +1275,6 @@ wxVariant::wxVariant(const wxDateTime& val, const wxString& name) // Date m_name = name; } -#if wxUSE_ODBC -wxVariant::wxVariant(const TIME_STRUCT* valptr, const wxString& name) // Date -{ - m_data = new wxVariantDataDateTime(valptr); - m_name = name; -} - -wxVariant::wxVariant(const TIMESTAMP_STRUCT* valptr, const wxString& name) // Date -{ - m_data = new wxVariantDataDateTime(valptr); - m_name = name; -} - -wxVariant::wxVariant(const DATE_STRUCT* valptr, const wxString& name) // Date -{ - m_data = new wxVariantDataDateTime(valptr); - m_name = name; -} -#endif // wxUSE_ODBC - bool wxVariant::operator== (const wxDateTime& value) const { wxDateTime thisValue; @@ -1300,27 +1303,6 @@ void wxVariant::operator= (const wxDateTime& value) } } -#if wxUSE_ODBC -void wxVariant::operator= (const DATE_STRUCT* value) -{ - UnRef(); - m_data = new wxVariantDataDateTime(value); -} - -void wxVariant::operator= (const TIME_STRUCT* value) -{ - UnRef(); - m_data = new wxVariantDataDateTime(value); -} - -void wxVariant::operator= (const TIMESTAMP_STRUCT* value) -{ - UnRef(); - m_data = new wxVariantDataDateTime(value); -} - -#endif // wxUSE_ODBC - wxDateTime wxVariant::GetDateTime() const { wxDateTime value; @@ -1357,7 +1339,7 @@ public: #endif virtual bool Read(wxString& str); virtual wxString GetType() const { return wxT("arrstring"); } - virtual wxVariantData* Clone() { return new wxVariantDataArrayString; } + virtual wxVariantData* Clone() const { return new wxVariantDataArrayString(m_value); } protected: wxArrayString m_value; @@ -1484,6 +1466,7 @@ public: void Clear(); + wxVariantData* Clone() const { return new wxVariantDataList(m_value); } protected: wxVariantList m_value; };