+ if (!GetType().IsSameAs(wxT("list")))
+ UnRef();
+
+ m_refData = new wxVariantDataList;
+ }
+}
+
+// Treat a list variant as an array
+wxVariant wxVariant::operator[] (size_t idx) const
+{
+ wxASSERT_MSG( GetType() == wxT("list"), wxT("Invalid type for array operator") );
+
+ if (GetType() == wxT("list"))
+ {
+ wxVariantDataList* data = (wxVariantDataList*) m_refData;
+ wxASSERT_MSG( (idx < data->GetValue().GetCount()), wxT("Invalid index for array") );
+ return *(data->GetValue().Item(idx)->GetData());
+ }
+ return wxNullVariant;
+}
+
+wxVariant& wxVariant::operator[] (size_t idx)
+{
+ // We can't return a reference to a variant for a string list, since the string
+ // is actually stored as a char*, not a variant.
+
+ wxASSERT_MSG( (GetType() == wxT("list")), wxT("Invalid type for array operator") );
+
+ wxVariantDataList* data = (wxVariantDataList*) m_refData;
+ wxASSERT_MSG( (idx < data->GetValue().GetCount()), wxT("Invalid index for array") );
+
+ return * (data->GetValue().Item(idx)->GetData());
+}
+
+// Return the number of elements in a list
+size_t wxVariant::GetCount() const
+{
+ wxASSERT_MSG( GetType() == wxT("list"), wxT("Invalid type for GetCount()") );
+
+ if (GetType() == wxT("list"))
+ {
+ wxVariantDataList* data = (wxVariantDataList*) m_refData;
+ return data->GetValue().GetCount();