X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/9000cdfb2a40a2d2cc5d7486ec70072a0fd21cb5..3c3b35589a13813433617be9d212fdc768246938:/src/common/variant.cpp diff --git a/src/common/variant.cpp b/src/common/variant.cpp index 58e7e327e7..06ef8faf22 100644 --- a/src/common/variant.cpp +++ b/src/common/variant.cpp @@ -1,5 +1,5 @@ ///////////////////////////////////////////////////////////////////////////// -// Name: variant.cpp +// Name: src/common/variant.cpp // Purpose: wxVariant class, container for any type // Author: Julian Smart // Modified by: @@ -16,6 +16,16 @@ #pragma hdrstop #endif +#include "wx/variant.h" + +#ifndef WX_PRECOMP + #include "wx/string.h" + #include "wx/math.h" + #if wxUSE_STREAMS + #include "wx/stream.h" + #endif +#endif + #if wxUSE_STD_IOSTREAM #if wxUSE_IOSTREAMH #include @@ -30,15 +40,11 @@ using namespace std ; #endif #if wxUSE_STREAMS -#include "wx/stream.h" -#include "wx/txtstrm.h" + #include "wx/txtstrm.h" #endif #include "wx/string.h" #include "wx/tokenzr.h" -#include "wx/math.h" - -#include "wx/variant.h" IMPLEMENT_ABSTRACT_CLASS(wxVariantData, wxObject) @@ -470,7 +476,7 @@ bool wxVariantDataReal::Write(wxSTD ostream& str) const bool wxVariantDataReal::Write(wxString& str) const { - str.Printf(wxT("%.4f"), m_value); + str.Printf(wxT("%.14g"), m_value); return true; } @@ -706,7 +712,7 @@ bool wxVariantDataChar::Read(wxInputStream& str) bool wxVariantDataChar::Read(wxString& str) { - m_value = str.ToAscii()[0u]; + m_value = str.ToAscii()[size_t(0)]; return true; } @@ -797,7 +803,7 @@ bool wxVariantDataString::Read(wxInputStream& str) { wxTextInputStream s(str); - m_value = s.ReadString(); + m_value = s.ReadLine(); return true; } #endif // wxUSE_STREAMS @@ -979,7 +985,7 @@ bool wxVariantDataWxObjectPtr::Write(wxSTD ostream& str) const bool wxVariantDataWxObjectPtr::Write(wxString& str) const { - str.Printf(wxT("%s(%p)"), GetType().c_str(), m_value); + str.Printf(wxT("%s(%p)"), GetType().c_str(), wx_static_cast(void*, m_value)); return true; } @@ -1730,14 +1736,14 @@ wxVariant wxVariant::operator[] (size_t idx) const if (GetType() == wxT("list")) { wxVariantDataList* data = (wxVariantDataList*) m_data; - wxASSERT_MSG( (idx < (size_t) data->GetValue().GetCount()), wxT("Invalid index for array") ); + wxASSERT_MSG( (idx < data->GetValue().GetCount()), wxT("Invalid index for array") ); return * (wxVariant*) (data->GetValue().Item(idx)->GetData()); } #if WXWIN_COMPATIBILITY_2_4 else if (GetType() == wxT("stringlist")) { wxVariantDataStringList* data = (wxVariantDataStringList*) m_data; - wxASSERT_MSG( (idx < (size_t) data->GetValue().GetCount()), wxT("Invalid index for array") ); + wxASSERT_MSG( (idx < data->GetValue().GetCount()), wxT("Invalid index for array") ); wxString str( (const wxChar*) (data->GetValue().Item(idx)->GetData()) ); wxVariant variant( str ); @@ -1755,13 +1761,13 @@ 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().GetCount()), wxT("Invalid index for array") ); + wxASSERT_MSG( (idx < data->GetValue().GetCount()), wxT("Invalid index for array") ); return * (wxVariant*) (data->GetValue().Item(idx)->GetData()); } // Return the number of elements in a list -int wxVariant::GetCount() const +size_t wxVariant::GetCount() const { #if WXWIN_COMPATIBILITY_2_4 wxASSERT_MSG( (GetType() == wxT("list") || GetType() == wxT("stringlist")), wxT("Invalid type for GetCount()") ); @@ -1970,11 +1976,11 @@ bool wxVariant::Member(const wxVariant& value) const } // Deletes the nth element of the list -bool wxVariant::Delete(int item) +bool wxVariant::Delete(size_t item) { wxList& list = GetList(); - wxASSERT_MSG( (item < (int) list.GetCount()), wxT("Invalid index to Delete") ); + wxASSERT_MSG( (item < list.GetCount()), wxT("Invalid index to Delete") ); wxList::compatibility_iterator node = list.Item(item); wxVariant* variant = (wxVariant*) node->GetData(); delete variant; @@ -2105,4 +2111,3 @@ bool wxVariant::Convert(wxDateTime* value) const (value->ParseDateTime(val) || value->ParseDate(val)); } #endif // wxUSE_DATETIME -