X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/574c939ef1c1b835a8bc65c0fe724548fa04ec49..0e878cfcc6486c7903ae89b316bc71700320199d:/src/common/variant.cpp diff --git a/src/common/variant.cpp b/src/common/variant.cpp index 859f722a79..42a6343ed6 100644 --- a/src/common/variant.cpp +++ b/src/common/variant.cpp @@ -101,23 +101,23 @@ wxVariantDataList::~wxVariantDataList() void wxVariantDataList::SetValue(const wxList& value) { Clear(); - wxNode* node = value.First(); + wxNode* node = value.GetFirst(); while (node) { - wxVariant* var = (wxVariant*) node->Data(); + wxVariant* var = (wxVariant*) node->GetData(); m_value.Append(new wxVariant(*var)); - node = node->Next(); + node = node->GetNext(); } } void wxVariantDataList::Clear() { - wxNode* node = m_value.First(); + wxNode* node = m_value.GetFirst(); while (node) { - wxVariant* var = (wxVariant*) node->Data(); + wxVariant* var = (wxVariant*) node->GetData(); delete var; - node = node->Next(); + node = node->GetNext(); } m_value.Clear(); } @@ -129,12 +129,12 @@ void wxVariantDataList::Copy(wxVariantData& data) wxVariantDataList& listData = (wxVariantDataList&) data; listData.Clear(); - wxNode* node = m_value.First(); + wxNode* node = m_value.GetFirst(); while (node) { - wxVariant* var = (wxVariant*) node->Data(); + wxVariant* var = (wxVariant*) node->GetData(); listData.m_value.Append(new wxVariant(*var)); - node = node->Next(); + node = node->GetNext(); } } @@ -143,16 +143,16 @@ bool wxVariantDataList::Eq(wxVariantData& data) const wxASSERT_MSG( (data.GetType() == wxT("list")), wxT("wxVariantDataList::Eq: argument mismatch") ); wxVariantDataList& listData = (wxVariantDataList&) data; - wxNode* node1 = m_value.First(); - wxNode* node2 = listData.GetValue().First(); + wxNode* node1 = m_value.GetFirst(); + wxNode* node2 = listData.GetValue().GetFirst(); while (node1 && node2) { - wxVariant* var1 = (wxVariant*) node1->Data(); - wxVariant* var2 = (wxVariant*) node2->Data(); + wxVariant* var1 = (wxVariant*) node1->GetData(); + wxVariant* var2 = (wxVariant*) node2->GetData(); if ((*var1) != (*var2)) return FALSE; - node1 = node1->Next(); - node2 = node2->Next(); + node1 = node1->GetNext(); + node2 = node2->GetNext(); } if (node1 || node2) return FALSE; return TRUE; @@ -171,15 +171,15 @@ bool wxVariantDataList::Write(wxSTD ostream& str) const bool wxVariantDataList::Write(wxString& str) const { str = wxT(""); - wxNode* node = m_value.First(); + wxNode* node = m_value.GetFirst(); while (node) { - wxVariant* var = (wxVariant*) node->Data(); - if (node != m_value.First()) + wxVariant* var = (wxVariant*) node->GetData(); + if (node != m_value.GetFirst()) str += wxT(" "); wxString str1; str += var->MakeString(); - node = node->Next(); + node = node->GetNext(); } return TRUE; @@ -252,16 +252,16 @@ bool wxVariantDataStringList::Eq(wxVariantData& data) const wxASSERT_MSG( (data.GetType() == wxT("stringlist")), wxT("wxVariantDataStringList::Eq: argument mismatch") ); wxVariantDataStringList& listData = (wxVariantDataStringList&) data; - wxNode* node1 = m_value.First(); - wxNode* node2 = listData.GetValue().First(); + wxStringList::Node *node1 = m_value.GetFirst(); + wxStringList::Node *node2 = listData.GetValue().GetFirst(); while (node1 && node2) { - wxString str1 ((wxChar*) node1->Data()); - wxString str2 ((wxChar*) node2->Data()); + wxString str1 ( node1->GetData() ); + wxString str2 ( node2->GetData() ); if (str1 != str2) return FALSE; - node1 = node1->Next(); - node2 = node2->Next(); + node1 = node1->GetNext(); + node2 = node2->GetNext(); } if (node1 || node2) return FALSE; return TRUE; @@ -279,15 +279,15 @@ bool wxVariantDataStringList::Write(wxSTD ostream& str) const bool wxVariantDataStringList::Write(wxString& str) const { - str = wxT(""); - wxNode* node = m_value.First(); + str.Empty(); + wxStringList::Node *node = m_value.GetFirst(); while (node) { - wxChar* s = (wxChar*) node->Data(); - if (node != m_value.First()) + wxChar* s = node->GetData(); + if (node != m_value.GetFirst()) str += wxT(" "); str += s; - node = node->Next(); + node = node->GetNext(); } return TRUE; @@ -857,7 +857,7 @@ public: #endif virtual bool Read(wxString& str); virtual wxString GetType() const { return wxT("time"); }; - virtual wxVariantData* Clone() { return new wxVariantDataTime; } + virtual wxVariantData* Clone() { return new wxVariantDataTime; } protected: wxTime m_value; @@ -939,7 +939,7 @@ public: #endif virtual bool Read(wxString& str); virtual wxString GetType() const { return wxT("date"); }; - virtual wxVariantData* Clone() { return new wxVariantDataDate; } + virtual wxVariantData* Clone() { return new wxVariantDataDate; } protected: wxDate m_value; @@ -1022,10 +1022,12 @@ public: #endif virtual bool Read(wxString& str); virtual wxString GetType() const { return wxT("void*"); }; - virtual wxVariantData* Clone() { return new wxVariantDataVoidPtr; } + virtual wxVariantData* Clone() { return new wxVariantDataVoidPtr; } protected: void* m_value; + + DECLARE_NO_COPY_CLASS(wxVariantDataVoidPtr) }; IMPLEMENT_DYNAMIC_CLASS(wxVariantDataVoidPtr, wxVariantData) @@ -1082,6 +1084,8 @@ bool wxVariantDataVoidPtr::Read(wxString& WXUNUSED(str)) * wxVariantDataDateTime */ +#if wxUSE_DATETIME + class wxVariantDataDateTime: public wxVariantData { DECLARE_DYNAMIC_CLASS(wxVariantDataDateTime) @@ -1174,6 +1178,8 @@ bool wxVariantDataDateTime::Read(wxString& str) return TRUE; } +#endif // wxUSE_DATETIME + // ---------------------------------------------------------------------------- // wxVariantDataArrayString // ---------------------------------------------------------------------------- @@ -1357,11 +1363,13 @@ wxVariant::wxVariant(void* val, const wxString& name) // Void ptr m_name = name; } +#if wxUSE_DATETIME wxVariant::wxVariant(const wxDateTime& val, const wxString& name) // Date { m_data = new wxVariantDataDateTime(val); m_name = name; } +#endif // wxUSE_DATETIME #if wxUSE_ODBC wxVariant::wxVariant(const TIME_STRUCT* valptr, const wxString& name) // Date @@ -1390,6 +1398,7 @@ wxVariant::wxVariant(const wxArrayString& val, const wxString& name) // Strings } wxVariant::wxVariant(const wxVariant& variant) + : wxObject() { if (!variant.IsNull()) { @@ -1436,8 +1445,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. @@ -1756,6 +1767,7 @@ void wxVariant::operator= (void* value) } } +#if wxUSE_DATETIME bool wxVariant::operator== (const wxDateTime& value) const { wxDateTime thisValue; @@ -1783,6 +1795,7 @@ void wxVariant::operator= (const wxDateTime& value) m_data = new wxVariantDataDateTime(value); } } +#endif // wxUSE_DATETIME #if wxUSE_ODBC void wxVariant::operator= (const DATE_STRUCT* value) @@ -1852,15 +1865,15 @@ wxVariant wxVariant::operator[] (size_t idx) const if (GetType() == wxT("list")) { wxVariantDataList* data = (wxVariantDataList*) m_data; - wxASSERT_MSG( (idx < (size_t) data->GetValue().Number()), wxT("Invalid index for array") ); - return * (wxVariant*) (data->GetValue().Nth(idx)->Data()); + wxASSERT_MSG( (idx < (size_t) data->GetValue().GetCount()), wxT("Invalid index for array") ); + return * (wxVariant*) (data->GetValue().Item(idx)->GetData()); } else if (GetType() == wxT("stringlist")) { wxVariantDataStringList* data = (wxVariantDataStringList*) m_data; - wxASSERT_MSG( (idx < (size_t) data->GetValue().Number()), wxT("Invalid index for array") ); + wxASSERT_MSG( (idx < (size_t) data->GetValue().GetCount()), wxT("Invalid index for array") ); - wxVariant variant( wxString( (wxChar*) (data->GetValue().Nth(idx)->Data()) )); + wxVariant variant( wxString( (wxChar*) (data->GetValue().Item(idx)->GetData()) )); return variant; } return wxNullVariant; @@ -1874,9 +1887,9 @@ wxVariant& wxVariant::operator[] (size_t idx) wxASSERT_MSG( (GetType() == wxT("list")), wxT("Invalid type for array operator") ); wxVariantDataList* data = (wxVariantDataList*) m_data; - wxASSERT_MSG( (idx < (size_t) data->GetValue().Number()), wxT("Invalid index for array") ); + wxASSERT_MSG( (idx < (size_t) data->GetValue().GetCount()), wxT("Invalid index for array") ); - return * (wxVariant*) (data->GetValue().Nth(idx)->Data()); + return * (wxVariant*) (data->GetValue().Item(idx)->GetData()); } // Return the number of elements in a list @@ -1887,12 +1900,12 @@ int wxVariant::GetCount() const if (GetType() == wxT("list")) { wxVariantDataList* data = (wxVariantDataList*) m_data; - return data->GetValue().Number(); + return data->GetValue().GetCount(); } else if (GetType() == wxT("stringlist")) { wxVariantDataStringList* data = (wxVariantDataStringList*) m_data; - return data->GetValue().Number(); + return data->GetValue().GetCount(); } return 0; } @@ -2026,6 +2039,7 @@ void* wxVariant::GetVoidPtr() const return (void*) ((wxVariantDataVoidPtr*) m_data)->GetValue(); } +#if wxUSE_DATETIME wxDateTime wxVariant::GetDateTime() const { wxDateTime value; @@ -2036,6 +2050,7 @@ wxDateTime wxVariant::GetDateTime() const return value; } +#endif // wxUSE_DATETIME wxList& wxVariant::GetList() const { @@ -2051,6 +2066,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) { @@ -2072,13 +2093,13 @@ bool wxVariant::Member(const wxVariant& value) const { wxList& list = GetList(); - wxNode* node = list.First(); + wxNode* node = list.GetFirst(); while (node) { - wxVariant* other = (wxVariant*) node->Data(); + wxVariant* other = (wxVariant*) node->GetData(); if (value == *other) return TRUE; - node = node->Next(); + node = node->GetNext(); } return FALSE; } @@ -2088,9 +2109,9 @@ bool wxVariant::Delete(int item) { wxList& list = GetList(); - wxASSERT_MSG( (item < list.Number()), wxT("Invalid index to Delete") ); - wxNode* node = list.Nth(item); - wxVariant* variant = (wxVariant*) node->Data(); + wxASSERT_MSG( (item < (int) list.GetCount()), wxT("Invalid index to Delete") ); + wxNode* node = list.Item(item); + wxVariant* variant = (wxVariant*) node->GetData(); delete variant; delete node; return TRUE; @@ -2149,9 +2170,9 @@ bool wxVariant::Convert(bool* value) const { wxString val(((wxVariantDataString*)GetData())->GetValue()); val.MakeLower(); - if (val == wxT("true") || val == wxT("yes")) + if (val == wxT("TRUE") || val == wxT("yes")) *value = TRUE; - else if (val == wxT("false") || val == wxT("no")) + else if (val == wxT("FALSE") || val == wxT("no")) *value = FALSE; else return FALSE; @@ -2231,13 +2252,17 @@ bool wxVariant::Convert(wxDate* value) const } #endif // wxUSE_TIMEDATE +#if wxUSE_DATETIME bool wxVariant::Convert(wxDateTime* value) const { wxString type(GetType()); if (type == wxT("datetime")) + { *value = ((wxVariantDataDateTime*)GetData())->GetValue(); - else - return FALSE; - - return TRUE; + return TRUE; + } + // Fallback to string conversion + wxString val; + return Convert(&val) && (value->ParseDate(val)); } +#endif // wxUSE_DATETIME \ No newline at end of file