#include "wx/listimpl.cpp"
-WX_DEFINE_LIST(wxVariantList);
+WX_DEFINE_LIST(wxVariantList)
/*
* wxVariant
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);
if (IsNull() || variant.IsNull())
return (IsNull() == variant.IsNull());
+ if (GetType() != variant.GetType())
+ return false;
+
return (GetData()->Eq(* variant.GetData()));
}
return (!(*this == variant));
}
-
wxString wxVariant::MakeString() const
{
if (!IsNull())
}
}
+bool wxVariant::Unshare()
+{
+ if ( m_data && m_data->GetRefCount() > 1 )
+ {
+ // note that ref is not going to be destroyed in this case...
+ const wxVariantData* ref = m_data;
+ UnRef();
+
+ // ... so we can still access it
+ m_data = ref->Clone();
+
+ wxASSERT_MSG( (m_data && m_data->GetRefCount() == 1),
+ _T("wxVariant::AllocExclusive() failed.") );
+
+ if (!m_data || m_data->GetRefCount() != 1)
+ return false;
+ else
+ return true;
+ }
+ //else: data is null or ref count is 1, so we are exclusive owners of m_refData anyhow
+ else
+ return true;
+}
+
// Returns a string representing the type of the variant,
// e.g. "string", "bool", "list", "double", "long"
virtual bool Write(wxOutputStream &str) const;
#endif // wxUSE_STREAMS
+ wxVariantData* Clone() const { return new wxVariantDataLong(m_value); }
+
virtual wxString GetType() const { return wxT("long"); }
protected:
#endif // wxUSE_STREAMS
virtual wxString GetType() const { return wxT("double"); }
+ wxVariantData* Clone() const { return new wxVariantDoubleData(m_value); }
protected:
double m_value;
};
// wxVariantBoolData
// -----------------------------------------------------------------
-#ifdef HAVE_BOOL
-
class WXDLLIMPEXP_BASE wxVariantDataBool: public wxVariantData
{
public:
#endif // wxUSE_STREAMS
virtual wxString GetType() const { return wxT("bool"); }
+ wxVariantData* Clone() const { return new wxVariantDataBool(m_value); }
protected:
bool m_value;
};
}
}
-#endif // HAVE_BOOL
-
// -----------------------------------------------------------------
// wxVariantDataChar
// -----------------------------------------------------------------
virtual bool Write(wxOutputStream& str) const;
#endif // wxUSE_STREAMS
virtual wxString GetType() const { return wxT("char"); }
+ wxVariantData* Clone() const { return new wxVariantDataChar(m_value); }
protected:
wxUniChar m_value;
virtual bool Write(wxOutputStream& str) const;
#endif // wxUSE_STREAMS
virtual wxString GetType() const { return wxT("string"); }
+ wxVariantData* Clone() const { return new wxVariantDataString(m_value); }
protected:
wxString m_value;
#endif
virtual bool Read(wxString& str);
virtual wxString GetType() const ;
- virtual wxVariantData* Clone() { return new wxVariantDataWxObjectPtr; }
+ virtual wxVariantData* Clone() const { return new wxVariantDataWxObjectPtr(m_value); }
virtual wxClassInfo* GetValueClassInfo();
-
+
protected:
wxObject* m_value;
};
wxString wxVariantDataWxObjectPtr::GetType() const
{
wxString returnVal(wxT("wxObject*"));
-
+
if (m_value)
{
returnVal = m_value->GetClassInfo()->GetClassName();
returnVal += wxT("*");
}
-
+
return returnVal;
}
bool wxVariantDataWxObjectPtr::Write(wxString& str) const
{
- str.Printf(wxT("%s(%p)"), GetType().c_str(), wx_static_cast(void*, m_value));
+ str.Printf(wxT("%s(%p)"), GetType().c_str(), static_cast<void*>(m_value));
return true;
}
#endif
virtual bool Read(wxString& str);
virtual wxString GetType() const { return wxT("void*"); }
- virtual wxVariantData* Clone() { return new wxVariantDataVoidPtr; }
+ virtual wxVariantData* Clone() const { return new wxVariantDataVoidPtr(m_value); }
protected:
void* m_value;
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();
}
public:
wxVariantDataDateTime() { }
wxVariantDataDateTime(const wxDateTime& value) { m_value = value; }
-#if wxUSE_ODBC
- wxVariantDataDateTime(const TIME_STRUCT* valptr)
- { m_value = wxDateTime(valptr->hour, valptr->minute, valptr->second); }
- wxVariantDataDateTime(const DATE_STRUCT* valptr)
- { m_value = wxDateTime(valptr->day, (wxDateTime::Month) (valptr->month - 1),valptr->year); }
- wxVariantDataDateTime(const TIMESTAMP_STRUCT* valptr)
- { m_value = wxDateTime(valptr->day, (wxDateTime::Month) (valptr->month - 1), valptr->year,
- valptr->hour, valptr->minute, valptr->second, (wxDateTime::wxDateTime_t)valptr->fraction ); }
-#endif //ODBC
inline wxDateTime GetValue() const { return m_value; }
inline void SetValue(const wxDateTime& value) { m_value = value; }
#endif
virtual bool Read(wxString& str);
virtual wxString GetType() const { return wxT("datetime"); }
- virtual wxVariantData* Clone() { return new wxVariantDataDateTime; }
+ virtual wxVariantData* Clone() const { return new wxVariantDataDateTime(m_value); }
protected:
wxDateTime m_value;
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 ( str == wxS("Invalid") )
+ {
+ m_value = wxInvalidDateTime;
+ return true;
+ }
+
if(! m_value.ParseDateTime(str.c_str()/*FIXME-UTF8*/))
return false;
return true;
m_name = name;
}
-#if wxUSE_ODBC
-wxVariant::wxVariant(const TIME_STRUCT* valptr, const wxString& name) // Date
-{
- m_data = new wxVariantDataDateTime(valptr);
- m_name = name;
-}
-
-wxVariant::wxVariant(const TIMESTAMP_STRUCT* valptr, const wxString& name) // Date
-{
- m_data = new wxVariantDataDateTime(valptr);
- m_name = name;
-}
-
-wxVariant::wxVariant(const DATE_STRUCT* valptr, const wxString& name) // Date
-{
- m_data = new wxVariantDataDateTime(valptr);
- m_name = name;
-}
-#endif // wxUSE_ODBC
-
bool wxVariant::operator== (const wxDateTime& value) const
{
wxDateTime thisValue;
}
}
-#if wxUSE_ODBC
-void wxVariant::operator= (const DATE_STRUCT* value)
-{
- UnRef();
- m_data = new wxVariantDataDateTime(value);
-}
-
-void wxVariant::operator= (const TIME_STRUCT* value)
-{
- UnRef();
- m_data = new wxVariantDataDateTime(value);
-}
-
-void wxVariant::operator= (const TIMESTAMP_STRUCT* value)
-{
- UnRef();
- m_data = new wxVariantDataDateTime(value);
-}
-
-#endif // wxUSE_ODBC
-
wxDateTime wxVariant::GetDateTime() const
{
wxDateTime value;
#endif
virtual bool Read(wxString& str);
virtual wxString GetType() const { return wxT("arrstring"); }
- virtual wxVariantData* Clone() { return new wxVariantDataArrayString; }
+ virtual wxVariantData* Clone() const { return new wxVariantDataArrayString(m_value); }
protected:
wxArrayString m_value;
void Clear();
+ wxVariantData* Clone() const { return new wxVariantDataList(m_value); }
protected:
wxVariantList m_value;
};
*value = (long) (((wxVariantDoubleData*)GetData())->GetValue());
else if (type == wxT("long"))
*value = ((wxVariantDataLong*)GetData())->GetValue();
-#ifdef HAVE_BOOL
else if (type == wxT("bool"))
*value = (long) (((wxVariantDataBool*)GetData())->GetValue());
-#endif
else if (type == wxT("string"))
*value = wxAtol(((wxVariantDataString*)GetData())->GetValue());
else
*value = ((int) (((wxVariantDoubleData*)GetData())->GetValue()) != 0);
else if (type == wxT("long"))
*value = (((wxVariantDataLong*)GetData())->GetValue() != 0);
-#ifdef HAVE_BOOL
else if (type == wxT("bool"))
*value = ((wxVariantDataBool*)GetData())->GetValue();
-#endif
else if (type == wxT("string"))
{
wxString val(((wxVariantDataString*)GetData())->GetValue());
*value = ((wxVariantDoubleData*)GetData())->GetValue();
else if (type == wxT("long"))
*value = (double) (((wxVariantDataLong*)GetData())->GetValue());
-#ifdef HAVE_BOOL
else if (type == wxT("bool"))
*value = (double) (((wxVariantDataBool*)GetData())->GetValue());
-#endif
else if (type == wxT("string"))
*value = (double) wxAtof(((wxVariantDataString*)GetData())->GetValue());
else
*value = ((wxVariantDataChar*)GetData())->GetValue();
else if (type == wxT("long"))
*value = (char) (((wxVariantDataLong*)GetData())->GetValue());
-#ifdef HAVE_BOOL
else if (type == wxT("bool"))
*value = (char) (((wxVariantDataBool*)GetData())->GetValue());
-#endif
else
return false;