X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/edca7a82055fc201fad1bba36742807d08cb6192..217c78b80b34f31b4341d6257e28077255d6eb93:/src/common/variant.cpp diff --git a/src/common/variant.cpp b/src/common/variant.cpp index cab5e3ead1..defe41807f 100644 --- a/src/common/variant.cpp +++ b/src/common/variant.cpp @@ -36,6 +36,8 @@ #endif #include "wx/string.h" +#include "wx/tokenzr.h" + #include "wx/variant.h" #if wxUSE_TIMEDATE @@ -593,7 +595,7 @@ bool wxVariantDataBool::Write(wxOutputStream& str) const { wxTextOutputStream s(str); - s.Write8(m_value); + s.Write8(m_value); return TRUE; } @@ -1088,11 +1090,11 @@ public: wxVariantDataDateTime() { } wxVariantDataDateTime(const wxDateTime& value) { m_value = value; } #if wxUSE_ODBC - wxVariantDataDateTime(const TIME_STRUCT* valptr) + wxVariantDataDateTime(const TIME_STRUCT* valptr) { m_value = wxDateTime(valptr->hour, valptr->minute, valptr->second); } - wxVariantDataDateTime(const DATE_STRUCT* valptr) + wxVariantDataDateTime(const DATE_STRUCT* valptr) { m_value = wxDateTime(valptr->day, (wxDateTime::Month) (valptr->month - 1),valptr->year); } - wxVariantDataDateTime(const TIMESTAMP_STRUCT* valptr) + wxVariantDataDateTime(const TIMESTAMP_STRUCT* valptr) { m_value = wxDateTime(valptr->day, (wxDateTime::Month) (valptr->month - 1), valptr->year, valptr->hour, valptr->minute, valptr->second, valptr->fraction ); } #endif //ODBC @@ -1103,11 +1105,11 @@ public: virtual void Copy(wxVariantData& data); virtual bool Eq(wxVariantData& data) const; #if wxUSE_STD_IOSTREAM - virtual bool Write(ostream& str) const; + virtual bool Write(wxSTD ostream& str) const; #endif virtual bool Write(wxString& str) const; #if wxUSE_STD_IOSTREAM - virtual bool Read(istream& str); + virtual bool Read(wxSTD istream& str); #endif virtual bool Read(wxString& str); virtual wxString GetType() const { return wxT("datetime"); }; @@ -1141,7 +1143,7 @@ bool wxVariantDataDateTime::Eq(wxVariantData& data) const #if wxUSE_STD_IOSTREAM -bool wxVariantDataDateTime::Write(ostream& str) const +bool wxVariantDataDateTime::Write(wxSTD ostream& str) const { // Not implemented return FALSE; @@ -1157,7 +1159,7 @@ bool wxVariantDataDateTime::Write(wxString& str) const #if wxUSE_STD_IOSTREAM -bool wxVariantDataDateTime::Read(istream& WXUNUSED(str)) +bool wxVariantDataDateTime::Read(wxSTD istream& WXUNUSED(str)) { // Not implemented return FALSE; @@ -1172,6 +1174,105 @@ bool wxVariantDataDateTime::Read(wxString& str) return TRUE; } +// ---------------------------------------------------------------------------- +// wxVariantDataArrayString +// ---------------------------------------------------------------------------- + +class wxVariantDataArrayString: public wxVariantData +{ +public: + wxVariantDataArrayString() { } + wxVariantDataArrayString(const wxArrayString& value) { m_value = value; } + + wxArrayString GetValue() const { return m_value; } + void SetValue(const wxArrayString& value) { m_value = value; } + + virtual void Copy(wxVariantData& data); + 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("arrstring"); }; + virtual wxVariantData* Clone() { return new wxVariantDataArrayString; } + +protected: + wxArrayString m_value; + + DECLARE_DYNAMIC_CLASS(wxVariantDataArrayString) +}; + +IMPLEMENT_DYNAMIC_CLASS(wxVariantDataArrayString, wxVariantData) + +void wxVariantDataArrayString::Copy(wxVariantData& data) +{ + wxASSERT_MSG( data.GetType() == GetType(), wxT("wxVariantDataArrayString::Copy: Can't copy to this type of data") ); + + wxVariantDataArrayString& otherData = (wxVariantDataArrayString&) data; + + otherData.m_value = m_value; +} + + +bool wxVariantDataArrayString::Eq(wxVariantData& data) const +{ + wxASSERT_MSG( data.GetType() == GetType(), wxT("wxVariantDataArrayString::Eq: argument mismatch") ); + + wxVariantDataArrayString& otherData = (wxVariantDataArrayString&) data; + + return otherData.m_value == m_value; +} + + +#if wxUSE_STD_IOSTREAM +bool wxVariantDataArrayString::Write(wxSTD ostream& str) const +{ + // Not implemented + return FALSE; +} +#endif + + +bool wxVariantDataArrayString::Write(wxString& str) const +{ + size_t count = m_value.GetCount(); + for ( size_t n = 0; n < count; n++ ) + { + if ( n ) + str += _T(';'); + + str += m_value[n]; + } + + return TRUE; +} + + +#if wxUSE_STD_IOSTREAM +bool wxVariantDataArrayString::Read(wxSTD istream& WXUNUSED(str)) +{ + // Not implemented + return FALSE; +} +#endif + + +bool wxVariantDataArrayString::Read(wxString& str) +{ + wxStringTokenizer tk(str, _T(";")); + while ( tk.HasMoreTokens() ) + { + m_value.Add(tk.GetNextToken()); + } + + return TRUE; +} + + /* * wxVariant @@ -1280,9 +1381,16 @@ wxVariant::wxVariant(const DATE_STRUCT* valptr, const wxString& name) // Date m_data = new wxVariantDataDateTime(valptr); m_name = name; } -#endif +#endif // wxUSE_ODBC + +wxVariant::wxVariant(const wxArrayString& val, const wxString& name) // Strings +{ + m_data = new wxVariantDataArrayString(val); + m_name = name; +} wxVariant::wxVariant(const wxVariant& variant) + : wxObject() { if (!variant.IsNull()) { @@ -1329,8 +1437,10 @@ void wxVariant::operator= (const wxVariant& variant) delete m_data; m_data = (wxVariantData*) variant.GetData()->GetClassInfo()->CreateObject(); } -// GetData()->Copy(* variant.GetData()); + variant.GetData()->Copy(* GetData()); + + m_name = variant.m_name; } // Assignment using data, e.g. @@ -1677,7 +1787,6 @@ void wxVariant::operator= (const wxDateTime& value) } } - #if wxUSE_ODBC void wxVariant::operator= (const DATE_STRUCT* value) { @@ -1702,7 +1811,41 @@ void wxVariant::operator= (const TIMESTAMP_STRUCT* value) m_data = new wxVariantDataDateTime(value); } -#endif +#endif // wxUSE_ODBC + +bool wxVariant::operator==(const wxArrayString& WXUNUSED(value)) const +{ + wxFAIL_MSG( _T("TODO") ); + + return FALSE; +} + +bool wxVariant::operator!=(const wxArrayString& value) const +{ + return !(*this == value); +} + +void wxVariant::operator=(const wxArrayString& value) +{ + if (GetType() == wxT("arrstring")) + { + ((wxVariantDataArrayString *)GetData())->SetValue(value); + } + else + { + delete m_data; + m_data = new wxVariantDataArrayString(value); + } +} + +wxArrayString wxVariant::GetArrayString() const +{ + if ( GetType() == wxT("arrstring") ) + return ((wxVariantDataArrayString *)GetData())->GetValue(); + + return wxArrayString(); +} + // Treat a list variant as an array wxVariant wxVariant::operator[] (size_t idx) const @@ -1911,6 +2054,12 @@ wxStringList& wxVariant::GetStringList() const return (wxStringList&) ((wxVariantDataStringList*) m_data)->GetValue(); } +// Make empty list +void wxVariant::NullList() +{ + SetData(new wxVariantDataList()); +}; + // Append to list void wxVariant::Append(const wxVariant& value) {