wxVariant::wxVariant()
{
- m_data = (wxVariantData*) NULL;
+ m_data = NULL;
}
bool wxVariant::IsNull() const
{
- return (m_data == (wxVariantData*) NULL);
+ return (m_data == NULL);
}
void wxVariant::MakeNull()
wxVariant::wxVariant(const wxVariant& variant)
: wxObject()
{
- m_data = (wxVariantData*) NULL;
+ m_data = NULL;
if (!variant.IsNull())
Ref(variant);
m_name = name;
}
-wxVariant::wxVariant(const wxCharBuffer& val, const wxString& name)
+wxVariant::wxVariant(const wxScopedCharBuffer& val, const wxString& name)
{
m_data = new wxVariantDataString(wxString(val));
m_name = name;
}
-wxVariant::wxVariant(const wxWCharBuffer& val, const wxString& name)
+wxVariant::wxVariant(const wxScopedWCharBuffer& val, const wxString& name)
{
m_data = new wxVariantDataString(wxString(val));
m_name = name;
void* wxVariant::GetVoidPtr() const
{
- wxASSERT( (GetType() == wxT("void*")) );
+ // handling this specially is convenient when working with COM, see #9873
+ if ( IsNull() )
+ return NULL;
+
+ wxASSERT( GetType() == wxT("void*") );
return (void*) ((wxVariantDataVoidPtr*) m_data)->GetValue();
}
bool wxVariantDataDateTime::Write(wxString& str) const
{
- str = m_value.Format();
+ if ( m_value.IsValid() )
+ str = m_value.Format();
+ else
+ str = wxS("Invalid");
return true;
}
bool wxVariantDataDateTime::Read(wxString& str)
{
- if(! m_value.ParseDateTime(str.c_str()/*FIXME-UTF8*/))
- return false;
- return true;
+ if ( str == wxS("Invalid") )
+ {
+ m_value = wxInvalidDateTime;
+ return true;
+ }
+
+ wxString::const_iterator end;
+ return m_value.ParseDateTime(str, &end) && end == str.end();
}
// wxVariant
*value = ((wxVariantDataDateTime*)GetData())->GetValue();
return true;
}
+
// Fallback to string conversion
wxString val;
- return Convert(&val) &&
- (value->ParseDateTime(val.c_str()/*FIXME-UTF8*/) ||
- value->ParseDate(val.c_str()/*FIXME-UTF8*/) ||
- value->ParseTime(val.c_str()/*FIXME-UTF8*/));
+ if ( !Convert(&val) )
+ return false;
+
+ // Try to parse this as either date and time, only date or only time
+ // checking that the entire string was parsed
+ wxString::const_iterator end;
+ if ( value->ParseDateTime(val, &end) && end == val.end() )
+ return true;
+
+ if ( value->ParseDate(val, &end) && end == val.end() )
+ return true;
+
+ if ( value->ParseTime(val, &end) && end == val.end() )
+ return true;
+
+ return false;
}
#endif // wxUSE_DATETIME