#endif
#include "wx/string.h"
+#include "wx/tokenzr.h"
+
#include "wx/variant.h"
#if wxUSE_TIMEDATE
void wxVariantDataList::SetValue(const wxList& value)
{
Clear();
- wxNode* node = value.First();
+ wxNode* node = value.GetFirst();
while (node)
{
- wxVariant* var = (wxVariant*) node->Data();
+ wxVariant* var = (wxVariant*) node->GetData();
m_value.Append(new wxVariant(*var));
- node = node->Next();
+ node = node->GetNext();
}
}
void wxVariantDataList::Clear()
{
- wxNode* node = m_value.First();
+ wxNode* node = m_value.GetFirst();
while (node)
{
- wxVariant* var = (wxVariant*) node->Data();
+ wxVariant* var = (wxVariant*) node->GetData();
delete var;
- node = node->Next();
+ node = node->GetNext();
}
m_value.Clear();
}
wxVariantDataList& listData = (wxVariantDataList&) data;
listData.Clear();
- wxNode* node = m_value.First();
+ wxNode* node = m_value.GetFirst();
while (node)
{
- wxVariant* var = (wxVariant*) node->Data();
+ wxVariant* var = (wxVariant*) node->GetData();
listData.m_value.Append(new wxVariant(*var));
- node = node->Next();
+ node = node->GetNext();
}
}
wxASSERT_MSG( (data.GetType() == wxT("list")), wxT("wxVariantDataList::Eq: argument mismatch") );
wxVariantDataList& listData = (wxVariantDataList&) data;
- wxNode* node1 = m_value.First();
- wxNode* node2 = listData.GetValue().First();
+ wxNode* node1 = m_value.GetFirst();
+ wxNode* node2 = listData.GetValue().GetFirst();
while (node1 && node2)
{
- wxVariant* var1 = (wxVariant*) node1->Data();
- wxVariant* var2 = (wxVariant*) node2->Data();
+ wxVariant* var1 = (wxVariant*) node1->GetData();
+ wxVariant* var2 = (wxVariant*) node2->GetData();
if ((*var1) != (*var2))
return FALSE;
- node1 = node1->Next();
- node2 = node2->Next();
+ node1 = node1->GetNext();
+ node2 = node2->GetNext();
}
if (node1 || node2) return FALSE;
return TRUE;
bool wxVariantDataList::Write(wxString& str) const
{
str = wxT("");
- wxNode* node = m_value.First();
+ wxNode* node = m_value.GetFirst();
while (node)
{
- wxVariant* var = (wxVariant*) node->Data();
- if (node != m_value.First())
+ wxVariant* var = (wxVariant*) node->GetData();
+ if (node != m_value.GetFirst())
str += wxT(" ");
wxString str1;
str += var->MakeString();
- node = node->Next();
+ node = node->GetNext();
}
return TRUE;
wxASSERT_MSG( (data.GetType() == wxT("stringlist")), wxT("wxVariantDataStringList::Eq: argument mismatch") );
wxVariantDataStringList& listData = (wxVariantDataStringList&) data;
- wxNode* node1 = m_value.First();
- wxNode* node2 = listData.GetValue().First();
+ wxStringList::Node *node1 = m_value.GetFirst();
+ wxStringList::Node *node2 = listData.GetValue().GetFirst();
while (node1 && node2)
{
- wxString str1 ((wxChar*) node1->Data());
- wxString str2 ((wxChar*) node2->Data());
+ wxString str1 ( node1->GetData() );
+ wxString str2 ( node2->GetData() );
if (str1 != str2)
return FALSE;
- node1 = node1->Next();
- node2 = node2->Next();
+ node1 = node1->GetNext();
+ node2 = node2->GetNext();
}
if (node1 || node2) return FALSE;
return TRUE;
bool wxVariantDataStringList::Write(wxString& str) const
{
- str = wxT("");
- wxNode* node = m_value.First();
+ str.Empty();
+ wxStringList::Node *node = m_value.GetFirst();
while (node)
{
- wxChar* s = (wxChar*) node->Data();
- if (node != m_value.First())
+ wxChar* s = node->GetData();
+ if (node != m_value.GetFirst())
str += wxT(" ");
str += s;
- node = node->Next();
+ node = node->GetNext();
}
return TRUE;
{
wxTextOutputStream s(str);
- s.Write8(m_value);
+ s.Write8(m_value);
return TRUE;
}
#endif
virtual bool Read(wxString& str);
virtual wxString GetType() const { return wxT("time"); };
- virtual wxVariantData* Clone() { return new wxVariantDataTime; }
+ virtual wxVariantData* Clone() { return new wxVariantDataTime; }
protected:
wxTime m_value;
#endif
virtual bool Read(wxString& str);
virtual wxString GetType() const { return wxT("date"); };
- virtual wxVariantData* Clone() { return new wxVariantDataDate; }
+ virtual wxVariantData* Clone() { return new wxVariantDataDate; }
protected:
wxDate m_value;
#endif
virtual bool Read(wxString& str);
virtual wxString GetType() const { return wxT("void*"); };
- virtual wxVariantData* Clone() { return new wxVariantDataVoidPtr; }
+ virtual wxVariantData* Clone() { return new wxVariantDataVoidPtr; }
protected:
void* m_value;
+
+ DECLARE_NO_COPY_CLASS(wxVariantDataVoidPtr)
};
IMPLEMENT_DYNAMIC_CLASS(wxVariantDataVoidPtr, wxVariantData)
* wxVariantDataDateTime
*/
+#if wxUSE_DATETIME
+
class wxVariantDataDateTime: public wxVariantData
{
DECLARE_DYNAMIC_CLASS(wxVariantDataDateTime)
wxVariantDataDateTime() { }
wxVariantDataDateTime(const wxDateTime& value) { m_value = value; }
#if wxUSE_ODBC
- wxVariantDataDateTime(const TIME_STRUCT* valptr)
+ wxVariantDataDateTime(const TIME_STRUCT* valptr)
{ m_value = wxDateTime(valptr->hour, valptr->minute, valptr->second); }
- wxVariantDataDateTime(const DATE_STRUCT* valptr)
+ wxVariantDataDateTime(const DATE_STRUCT* valptr)
{ m_value = wxDateTime(valptr->day, (wxDateTime::Month) (valptr->month - 1),valptr->year); }
- wxVariantDataDateTime(const TIMESTAMP_STRUCT* valptr)
+ wxVariantDataDateTime(const TIMESTAMP_STRUCT* valptr)
{ m_value = wxDateTime(valptr->day, (wxDateTime::Month) (valptr->month - 1), valptr->year,
valptr->hour, valptr->minute, valptr->second, valptr->fraction ); }
#endif //ODBC
virtual void Copy(wxVariantData& data);
virtual bool Eq(wxVariantData& data) const;
#if wxUSE_STD_IOSTREAM
- virtual bool Write(ostream& str) const;
+ virtual bool Write(wxSTD ostream& str) const;
#endif
virtual bool Write(wxString& str) const;
#if wxUSE_STD_IOSTREAM
- virtual bool Read(istream& str);
+ virtual bool Read(wxSTD istream& str);
#endif
virtual bool Read(wxString& str);
virtual wxString GetType() const { return wxT("datetime"); };
#if wxUSE_STD_IOSTREAM
-bool wxVariantDataDateTime::Write(ostream& str) const
+bool wxVariantDataDateTime::Write(wxSTD ostream& str) const
{
// Not implemented
return FALSE;
#if wxUSE_STD_IOSTREAM
-bool wxVariantDataDateTime::Read(istream& WXUNUSED(str))
+bool wxVariantDataDateTime::Read(wxSTD istream& WXUNUSED(str))
{
// Not implemented
return FALSE;
return TRUE;
}
+#endif // wxUSE_DATETIME
+
+// ----------------------------------------------------------------------------
+// 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_name = name;
}
+#if wxUSE_DATETIME
wxVariant::wxVariant(const wxDateTime& val, const wxString& name) // Date
{
m_data = new wxVariantDataDateTime(val);
m_name = name;
}
+#endif // wxUSE_DATETIME
#if wxUSE_ODBC
wxVariant::wxVariant(const TIME_STRUCT* valptr, const wxString& name) // Date
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_DATETIME
bool wxVariant::operator== (const wxDateTime& value) const
{
wxDateTime thisValue;
m_data = new wxVariantDataDateTime(value);
}
}
-
+#endif // wxUSE_DATETIME
#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
if (GetType() == wxT("list"))
{
wxVariantDataList* data = (wxVariantDataList*) m_data;
- wxASSERT_MSG( (idx < (size_t) data->GetValue().Number()), wxT("Invalid index for array") );
- return * (wxVariant*) (data->GetValue().Nth(idx)->Data());
+ wxASSERT_MSG( (idx < (size_t) data->GetValue().GetCount()), wxT("Invalid index for array") );
+ return * (wxVariant*) (data->GetValue().Item(idx)->GetData());
}
else if (GetType() == wxT("stringlist"))
{
wxVariantDataStringList* data = (wxVariantDataStringList*) m_data;
- wxASSERT_MSG( (idx < (size_t) data->GetValue().Number()), wxT("Invalid index for array") );
+ wxASSERT_MSG( (idx < (size_t) data->GetValue().GetCount()), wxT("Invalid index for array") );
- wxVariant variant( wxString( (wxChar*) (data->GetValue().Nth(idx)->Data()) ));
+ wxVariant variant( wxString( (wxChar*) (data->GetValue().Item(idx)->GetData()) ));
return variant;
}
return wxNullVariant;
wxASSERT_MSG( (GetType() == wxT("list")), wxT("Invalid type for array operator") );
wxVariantDataList* data = (wxVariantDataList*) m_data;
- wxASSERT_MSG( (idx < (size_t) data->GetValue().Number()), wxT("Invalid index for array") );
+ wxASSERT_MSG( (idx < (size_t) data->GetValue().GetCount()), wxT("Invalid index for array") );
- return * (wxVariant*) (data->GetValue().Nth(idx)->Data());
+ return * (wxVariant*) (data->GetValue().Item(idx)->GetData());
}
// Return the number of elements in a list
if (GetType() == wxT("list"))
{
wxVariantDataList* data = (wxVariantDataList*) m_data;
- return data->GetValue().Number();
+ return data->GetValue().GetCount();
}
else if (GetType() == wxT("stringlist"))
{
wxVariantDataStringList* data = (wxVariantDataStringList*) m_data;
- return data->GetValue().Number();
+ return data->GetValue().GetCount();
}
return 0;
}
return (void*) ((wxVariantDataVoidPtr*) m_data)->GetValue();
}
+#if wxUSE_DATETIME
wxDateTime wxVariant::GetDateTime() const
{
wxDateTime value;
return value;
}
+#endif // wxUSE_DATETIME
wxList& wxVariant::GetList() 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)
{
{
wxList& list = GetList();
- wxNode* node = list.First();
+ wxNode* node = list.GetFirst();
while (node)
{
- wxVariant* other = (wxVariant*) node->Data();
+ wxVariant* other = (wxVariant*) node->GetData();
if (value == *other)
return TRUE;
- node = node->Next();
+ node = node->GetNext();
}
return FALSE;
}
{
wxList& list = GetList();
- wxASSERT_MSG( (item < list.Number()), wxT("Invalid index to Delete") );
- wxNode* node = list.Nth(item);
- wxVariant* variant = (wxVariant*) node->Data();
+ wxASSERT_MSG( (item < (int) list.GetCount()), wxT("Invalid index to Delete") );
+ wxNode* node = list.Item(item);
+ wxVariant* variant = (wxVariant*) node->GetData();
delete variant;
delete node;
return TRUE;
{
wxString val(((wxVariantDataString*)GetData())->GetValue());
val.MakeLower();
- if (val == wxT("true") || val == wxT("yes"))
+ if (val == wxT("TRUE") || val == wxT("yes"))
*value = TRUE;
- else if (val == wxT("false") || val == wxT("no"))
+ else if (val == wxT("FALSE") || val == wxT("no"))
*value = FALSE;
else
return FALSE;
}
#endif // wxUSE_TIMEDATE
+#if wxUSE_DATETIME
bool wxVariant::Convert(wxDateTime* value) const
{
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));
}
+#endif // wxUSE_DATETIME
+