-wxString wxVariant::MakeString() const
-{
- if (!IsNull())
- {
- wxString str;
- if (GetData()->Write(str))
- return str;
- }
- return wxString(wxT(""));
-}
-
-// 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", "stringlist", "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);
-}
-
-
-// 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;
-}
-
-// For some reason, Watcom C++ can't link variant.cpp with time/date classes compiled
-#if wxUSE_TIMEDATE && !defined(__WATCOMC__)
-wxTime wxVariant::GetTime() const
-{
- wxTime value;
- if (!Convert(& value))
- {
- wxFAIL_MSG(wxT("Could not convert to a time"));
- }
-
- return value;
-}
-
-wxDate wxVariant::GetDate() const
-{
- wxDate value;
- if (!Convert(& value))
- {
- wxFAIL_MSG(wxT("Could not convert to a date"));
- }
-
- return value;
-}
-#endif // wxUSE_TIMEDATE
-
-void* wxVariant::GetVoidPtr() const
-{
- wxASSERT( (GetType() == wxT("void*")) );
-
- return (void*) ((wxVariantDataVoidPtr*) m_data)->GetValue();
-}
-
-wxDateTime wxVariant::GetDateTime() const
-{
- wxDateTime value;
- if (!Convert(& value))
- {
- wxFAIL_MSG(wxT("Could not convert to a datetime"));
- }
-
- return value;
-}
-
-wxList& wxVariant::GetList() const
-{
- wxASSERT( (GetType() == wxT("list")) );
-
- return (wxList&) ((wxVariantDataList*) m_data)->GetValue();
-}
-
-wxStringList& wxVariant::GetStringList() const
-{
- wxASSERT( (GetType() == wxT("stringlist")) );
-
- 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();
-
- 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();
-
- wxNode* node = list.First();
- while (node)
- {
- wxVariant* other = (wxVariant*) node->Data();
- if (value == *other)
- return TRUE;
- node = node->Next();
- }
- return FALSE;
-}
-
-// Deletes the nth element of the list
-bool wxVariant::Delete(int item)
-{
- wxList& list = GetList();
-
- wxASSERT_MSG( (item < list.Number()), wxT("Invalid index to Delete") );
- wxNode* node = list.Nth(item);
- wxVariant* variant = (wxVariant*) node->Data();
- delete variant;
- delete node;
- return TRUE;
-}
-
-// Clear list
-void wxVariant::ClearList()
-{
- if (!IsNull() && (GetType() == wxT("list")))
- {
- ((wxVariantDataList*) m_data)->Clear();
- }
- else
- {
- if (GetType() != wxT("list"))
- {
- delete m_data;
- m_data = NULL;
- }
- m_data = new wxVariantDataList;
- }
-}
-