/////////////////////////////////////////////////////////////////////////////
-// Name: variant.cpp
+// Name: src/common/variant.cpp
// Purpose: wxVariant class, container for any type
// Author: Julian Smart
// Modified by:
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
-#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
-#pragma implementation "variant.h"
-#endif
-
// For compilers that support precompilation, includes "wx/wx.h".
#include "wx/wxprec.h"
#pragma hdrstop
#endif
+#include "wx/variant.h"
+
+#ifndef WX_PRECOMP
+ #include "wx/string.h"
+ #if wxUSE_STREAMS
+ #include "wx/stream.h"
+ #endif
+#endif
+
#if wxUSE_STD_IOSTREAM
#if wxUSE_IOSTREAMH
#include <fstream.h>
#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/variant.h"
+#include "wx/math.h"
IMPLEMENT_ABSTRACT_CLASS(wxVariantData, wxObject)
wxVariantDataList(const wxList& list);
~wxVariantDataList();
- wxList& GetValue() const { return (wxList&) m_value; }
+ wxList& GetValue() { return m_value; }
void SetValue(const wxList& value) ;
virtual void Copy(wxVariantData& data);
return false;
}
-#endif //2.4 compat
+#endif //2.4 compat
/*
* wxVariantDataLong
wxVariantDataReal& otherData = (wxVariantDataReal&) data;
- return (otherData.m_value == m_value);
+ return wxIsSameDouble(otherData.m_value, m_value);
}
#if wxUSE_STD_IOSTREAM
bool wxVariantDataReal::Write(wxString& str) const
{
- str.Printf(wxT("%.4f"), m_value);
+ str.Printf(wxT("%.14g"), m_value);
return true;
}
bool wxVariantDataChar::Read(wxString& str)
{
- m_value = str.ToAscii()[0u];
+ m_value = str.ToAscii()[size_t(0)];
return true;
}
{
wxTextInputStream s(str);
- m_value = s.ReadString();
+ m_value = s.ReadLine();
return true;
}
#endif // wxUSE_STREAMS
bool wxVariantDataVoidPtr::Write(wxString& str) const
{
- str.Printf(wxT("%ld"), (long) m_value);
+ str.Printf(wxT("%p"), m_value);
return true;
}
bool wxVariantDataWxObjectPtr::Write(wxString& str) const
{
- str.Printf(wxT("%s(%ld)"), GetType().c_str(), (long) m_value);
+ str.Printf(wxT("%s(%p)"), GetType().c_str(), m_value);
return true;
}
#if wxUSE_STD_IOSTREAM
-bool wxVariantDataDateTime::Write(wxSTD ostream& str) const
+bool wxVariantDataDateTime::Write(wxSTD ostream& WXUNUSED(str)) const
{
// Not implemented
return false;
#if wxUSE_STD_IOSTREAM
-bool wxVariantDataArrayString::Write(wxSTD ostream& str) const
+bool wxVariantDataArrayString::Write(wxSTD ostream& WXUNUSED(str)) const
{
// Not implemented
return false;
double thisValue;
if (!Convert(&thisValue))
return false;
- else
- return (value == thisValue);
+
+ return wxIsSameDouble(value, thisValue);
}
bool wxVariant::operator!= (double value) 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 );
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()") );
void wxVariant::NullList()
{
SetData(new wxVariantDataList());
-};
+}
// Append to list
void wxVariant::Append(const wxVariant& value)
}
// 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;
}
else
{
- if (GetType() != wxT("list"))
+ if (!GetType().IsSameAs(wxT("list")))
{
delete m_data;
m_data = NULL;
{
wxString val(((wxVariantDataString*)GetData())->GetValue());
val.MakeLower();
- if (val == wxT("true") || val == wxT("yes"))
+ if (val == wxT("true") || val == wxT("yes") || val == wxT('1') )
*value = true;
- else if (val == wxT("false") || val == wxT("no"))
+ else if (val == wxT("false") || val == wxT("no") || val == wxT('0') )
*value = false;
else
return false;
(value->ParseDateTime(val) || value->ParseDate(val));
}
#endif // wxUSE_DATETIME
-