-wxString wxVariant::MakeString() const
-{
- if (!IsNull())
- {
- wxString str;
- if (GetData()->Write(str))
- return str;
- }
- return wxEmptyString;
-}
-
-// Accessors
-
-void wxVariant::SetData(wxVariantData* data)
-{
- if (m_data) delete m_data;
- m_data = data;
-}
-
-
-// Returns a string representing the type of the variant,
-// e.g. "string", "bool", "list", "double", "long"
-wxString wxVariant::GetType() const
-{
- if (IsNull())
- return wxString(wxT("null"));
- else
- return m_data->GetType();
-}
-
-
-bool wxVariant::IsType(const wxString& type) const
-{
- return (GetType() == type);
-}
-
-bool wxVariant::IsValueKindOf(const wxClassInfo* type) const
-{
- wxClassInfo* info=m_data->GetValueClassInfo();
- return info ? info->IsKindOf(type) : false ;
-}
-
-
-// Value accessors
-double wxVariant::GetReal() const
-{
- double value;
- if (Convert(& value))
- return value;
- else
- {
- wxFAIL_MSG(wxT("Could not convert to a real number"));
- return 0.0;
- }
-}
-
-long wxVariant::GetInteger() const
-{
- long value;
- if (Convert(& value))
- return value;
- else
- {
- wxFAIL_MSG(wxT("Could not convert to an integer"));
- return 0;
- }
-}
-
-char wxVariant::GetChar() const
-{
- char value;
- if (Convert(& value))
- return value;
- else
- {
- wxFAIL_MSG(wxT("Could not convert to a char"));
- return 0;
- }
-}
-
-bool wxVariant::GetBool() const
-{
- bool value;
- if (Convert(& value))
- return value;
- else
- {
- wxFAIL_MSG(wxT("Could not convert to a bool"));
- return 0;
- }
-}
-
-wxString wxVariant::GetString() const
-{
- wxString value;
- if (!Convert(& value))
- {
- wxFAIL_MSG(wxT("Could not convert to a string"));
- }
-
- return value;
-}
-
-void* wxVariant::GetVoidPtr() const
-{
- wxASSERT( (GetType() == wxT("void*")) );
-
- return (void*) ((wxVariantDataVoidPtr*) m_data)->GetValue();
-}
-
-wxObject* wxVariant::GetWxObjectPtr() const
-{
- wxASSERT(wxIsKindOf(m_data, wxVariantDataWxObjectPtr));
- return (wxObject*) ((wxVariantDataWxObjectPtr*) m_data)->GetValue();
-}
-
-#if wxUSE_DATETIME
-wxDateTime wxVariant::GetDateTime() const
-{
- wxDateTime value;
- if (!Convert(& value))
- {
- wxFAIL_MSG(wxT("Could not convert to a datetime"));
- }
-
- return value;
-}
-#endif // wxUSE_DATETIME
-
-wxList& wxVariant::GetList() const
-{
- wxASSERT( (GetType() == wxT("list")) );
-
- return (wxList&) ((wxVariantDataList*) m_data)->GetValue();
-}
-
-#if WXWIN_COMPATIBILITY_2_4
-
-wxStringList& wxVariant::GetStringList() const
-{
- wxASSERT( (GetType() == wxT("stringlist")) );
-
- return (wxStringList&) ((wxVariantDataStringList*) m_data)->GetValue();
-}
-
-#endif
-
-// Make empty list
-void wxVariant::NullList()
-{
- SetData(new wxVariantDataList());
-}
-
-// Append to list
-void wxVariant::Append(const wxVariant& value)
-{
- wxList& list = GetList();
-
- list.Append(new wxVariant(value));
-}
-
-// Insert at front of list
-void wxVariant::Insert(const wxVariant& value)
-{
- wxList& list = GetList();
-
- list.Insert(new wxVariant(value));
-}
-
-// Returns true if the variant is a member of the list
-bool wxVariant::Member(const wxVariant& value) const
-{
- wxList& list = GetList();
-
- wxList::compatibility_iterator node = list.GetFirst();
- while (node)
- {
- wxVariant* other = (wxVariant*) node->GetData();
- if (value == *other)
- return true;
- node = node->GetNext();
- }
- return false;
-}
-
-// Deletes the nth element of the list
-bool wxVariant::Delete(size_t item)
-{
- wxList& list = GetList();
-
- wxASSERT_MSG( (item < list.GetCount()), wxT("Invalid index to Delete") );
- wxList::compatibility_iterator node = list.Item(item);
- wxVariant* variant = (wxVariant*) node->GetData();
- delete variant;
- list.Erase(node);
- return true;
-}
-
-// Clear list
-void wxVariant::ClearList()
-{
- if (!IsNull() && (GetType() == wxT("list")))
- {
- ((wxVariantDataList*) m_data)->Clear();
- }
- else
- {
- if (!GetType().IsSameAs(wxT("list")))
- {
- delete m_data;
- m_data = NULL;
- }
- m_data = new wxVariantDataList;
- }
-}
-