#endif
#include "wx/string.h"
+#include "wx/tokenzr.h"
+
#include "wx/variant.h"
#if wxUSE_TIMEDATE
return TRUE;
}
+// ----------------------------------------------------------------------------
+// wxVariantDataArrayString
+// ----------------------------------------------------------------------------
+
+class wxVariantDataArrayString: public wxVariantData
+{
+public:
+ wxVariantDataArrayString() { }
+ wxVariantDataArrayString(const wxArrayString& value) { m_value = value; }
+
+ wxArrayString GetValue() const { return m_value; }
+ void SetValue(const wxArrayString& value) { m_value = value; }
+
+ virtual void Copy(wxVariantData& data);
+ virtual bool Eq(wxVariantData& data) const;
+#if wxUSE_STD_IOSTREAM
+ virtual bool Write(wxSTD ostream& str) const;
+#endif
+ virtual bool Write(wxString& str) const;
+#if wxUSE_STD_IOSTREAM
+ virtual bool Read(wxSTD istream& str);
+#endif
+ virtual bool Read(wxString& str);
+ virtual wxString GetType() const { return wxT("arrstring"); };
+ virtual wxVariantData* Clone() { return new wxVariantDataArrayString; }
+
+protected:
+ wxArrayString m_value;
+
+ DECLARE_DYNAMIC_CLASS(wxVariantDataArrayString)
+};
+
+IMPLEMENT_DYNAMIC_CLASS(wxVariantDataArrayString, wxVariantData)
+
+void wxVariantDataArrayString::Copy(wxVariantData& data)
+{
+ wxASSERT_MSG( data.GetType() == GetType(), wxT("wxVariantDataArrayString::Copy: Can't copy to this type of data") );
+
+ wxVariantDataArrayString& otherData = (wxVariantDataArrayString&) data;
+
+ otherData.m_value = m_value;
+}
+
+
+bool wxVariantDataArrayString::Eq(wxVariantData& data) const
+{
+ wxASSERT_MSG( data.GetType() == GetType(), wxT("wxVariantDataArrayString::Eq: argument mismatch") );
+
+ wxVariantDataArrayString& otherData = (wxVariantDataArrayString&) data;
+
+ return otherData.m_value == m_value;
+}
+
+
+#if wxUSE_STD_IOSTREAM
+bool wxVariantDataArrayString::Write(wxSTD ostream& str) const
+{
+ // Not implemented
+ return FALSE;
+}
+#endif
+
+
+bool wxVariantDataArrayString::Write(wxString& str) const
+{
+ size_t count = m_value.GetCount();
+ for ( size_t n = 0; n < count; n++ )
+ {
+ if ( n )
+ str += _T(';');
+
+ str += m_value[n];
+ }
+
+ return TRUE;
+}
+
+
+#if wxUSE_STD_IOSTREAM
+bool wxVariantDataArrayString::Read(wxSTD istream& WXUNUSED(str))
+{
+ // Not implemented
+ return FALSE;
+}
+#endif
+
+
+bool wxVariantDataArrayString::Read(wxString& str)
+{
+ wxStringTokenizer tk(str, _T(";"));
+ while ( tk.HasMoreTokens() )
+ {
+ m_value.Add(tk.GetNextToken());
+ }
+
+ return TRUE;
+}
+
+
/*
* wxVariant
m_data = new wxVariantDataDateTime(valptr);
m_name = name;
}
-#endif
+#endif // wxUSE_ODBC
+
+wxVariant::wxVariant(const wxArrayString& val, const wxString& name) // Strings
+{
+ m_data = new wxVariantDataArrayString(val);
+ m_name = name;
+}
wxVariant::wxVariant(const wxVariant& variant)
+ : wxObject()
{
if (!variant.IsNull())
{
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.
}
}
-
#if wxUSE_ODBC
void wxVariant::operator= (const DATE_STRUCT* value)
{
m_data = new wxVariantDataDateTime(value);
}
-#endif
+#endif // wxUSE_ODBC
+
+bool wxVariant::operator==(const wxArrayString& WXUNUSED(value)) const
+{
+ wxFAIL_MSG( _T("TODO") );
+
+ return FALSE;
+}
+
+bool wxVariant::operator!=(const wxArrayString& value) const
+{
+ return !(*this == value);
+}
+
+void wxVariant::operator=(const wxArrayString& value)
+{
+ if (GetType() == wxT("arrstring"))
+ {
+ ((wxVariantDataArrayString *)GetData())->SetValue(value);
+ }
+ else
+ {
+ delete m_data;
+ m_data = new wxVariantDataArrayString(value);
+ }
+}
+
+wxArrayString wxVariant::GetArrayString() const
+{
+ if ( GetType() == wxT("arrstring") )
+ return ((wxVariantDataArrayString *)GetData())->GetValue();
+
+ return wxArrayString();
+}
+
// Treat a list variant as an array
wxVariant wxVariant::operator[] (size_t idx) 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)
{
{
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));
}