// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
-#ifdef __GNUG__
+#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
#pragma implementation "variant.h"
#endif
IMPLEMENT_ABSTRACT_CLASS(wxVariantData, wxObject)
-wxVariant WXDLLEXPORT wxNullVariant;
+wxVariant WXDLLIMPEXP_BASE wxNullVariant;
/*
* wxVariantDataList
*/
-class WXDLLEXPORT wxVariantDataList: public wxVariantData
+class WXDLLIMPEXP_BASE wxVariantDataList: public wxVariantData
{
DECLARE_DYNAMIC_CLASS(wxVariantDataList)
public:
void wxVariantDataList::SetValue(const wxList& value)
{
Clear();
- wxNode* node = value.GetFirst();
+ wxList::compatibility_iterator node = value.GetFirst();
while (node)
{
wxVariant* var = (wxVariant*) node->GetData();
void wxVariantDataList::Clear()
{
- wxNode* node = m_value.GetFirst();
+ wxList::compatibility_iterator node = m_value.GetFirst();
while (node)
{
wxVariant* var = (wxVariant*) node->GetData();
wxVariantDataList& listData = (wxVariantDataList&) data;
listData.Clear();
- wxNode* node = m_value.GetFirst();
+ wxList::compatibility_iterator node = m_value.GetFirst();
while (node)
{
wxVariant* var = (wxVariant*) node->GetData();
wxASSERT_MSG( (data.GetType() == wxT("list")), wxT("wxVariantDataList::Eq: argument mismatch") );
wxVariantDataList& listData = (wxVariantDataList&) data;
- wxNode* node1 = m_value.GetFirst();
- wxNode* node2 = listData.GetValue().GetFirst();
+ wxList::compatibility_iterator node1 = m_value.GetFirst();
+ wxList::compatibility_iterator node2 = listData.GetValue().GetFirst();
while (node1 && node2)
{
wxVariant* var1 = (wxVariant*) node1->GetData();
bool wxVariantDataList::Write(wxString& str) const
{
str = wxT("");
- wxNode* node = m_value.GetFirst();
+ wxList::compatibility_iterator node = m_value.GetFirst();
while (node)
{
wxVariant* var = (wxVariant*) node->GetData();
* wxVariantDataStringList
*/
-class WXDLLEXPORT wxVariantDataStringList: public wxVariantData
+class WXDLLIMPEXP_BASE wxVariantDataStringList: public wxVariantData
{
DECLARE_DYNAMIC_CLASS(wxVariantDataStringList)
public:
wxASSERT_MSG( (data.GetType() == wxT("stringlist")), wxT("wxVariantDataStringList::Eq: argument mismatch") );
wxVariantDataStringList& listData = (wxVariantDataStringList&) data;
- wxStringList::Node *node1 = m_value.GetFirst();
- wxStringList::Node *node2 = listData.GetValue().GetFirst();
+ wxStringList::compatibility_iterator node1 = m_value.GetFirst();
+ wxStringList::compatibility_iterator node2 = listData.GetValue().GetFirst();
while (node1 && node2)
{
wxString str1 ( node1->GetData() );
bool wxVariantDataStringList::Write(wxString& str) const
{
str.Empty();
- wxStringList::Node *node = m_value.GetFirst();
+ wxStringList::compatibility_iterator node = m_value.GetFirst();
while (node)
{
- wxChar* s = node->GetData();
+ const wxChar* s = node->GetData();
if (node != m_value.GetFirst())
str += wxT(" ");
str += s;
* wxVariantDataLong
*/
-class WXDLLEXPORT wxVariantDataLong: public wxVariantData
+class WXDLLIMPEXP_BASE wxVariantDataLong: public wxVariantData
{
DECLARE_DYNAMIC_CLASS(wxVariantDataLong)
public:
* wxVariantDataReal
*/
-class WXDLLEXPORT wxVariantDataReal: public wxVariantData
+class WXDLLIMPEXP_BASE wxVariantDataReal: public wxVariantData
{
DECLARE_DYNAMIC_CLASS(wxVariantDataReal)
public:
* wxVariantDataBool
*/
-class WXDLLEXPORT wxVariantDataBool: public wxVariantData
+class WXDLLIMPEXP_BASE wxVariantDataBool: public wxVariantData
{
DECLARE_DYNAMIC_CLASS(wxVariantDataBool)
public:
* wxVariantDataChar
*/
-class WXDLLEXPORT wxVariantDataChar: public wxVariantData
+class WXDLLIMPEXP_BASE wxVariantDataChar: public wxVariantData
{
DECLARE_DYNAMIC_CLASS(wxVariantDataChar)
public:
* wxVariantDataString
*/
-#if defined(__BORLANDC__) && defined(__WIN16__)
-// Change name because of truncation
-#define wxVariantDataString wxVariantStringData
-#endif
-
-class WXDLLEXPORT wxVariantDataString: public wxVariantData
+class WXDLLIMPEXP_BASE wxVariantDataString: public wxVariantData
{
-#if defined(__BORLANDC__) && defined(__WIN16__)
-DECLARE_DYNAMIC_CLASS(wxVariantStringData)
-#else
DECLARE_DYNAMIC_CLASS(wxVariantDataString)
-#endif
public:
wxVariantDataString() { }
wxVariantDataString(const wxString& value) { m_value = value; }
return TRUE;
}
-#if defined(__BORLANDC__) && defined(__WIN16__)
-IMPLEMENT_DYNAMIC_CLASS(wxVariantStringData, wxVariantData)
-#else
IMPLEMENT_DYNAMIC_CLASS(wxVariantDataString, wxVariantData)
-#endif
/*
* wxVariantDataVoidPtr
return FALSE;
}
+/*
+ * wxVariantDataWxObjectPtr
+ */
+
+class wxVariantDataWxObjectPtr: public wxVariantData
+{
+DECLARE_DYNAMIC_CLASS(wxVariantDataWxObjectPtr)
+public:
+ wxVariantDataWxObjectPtr() { }
+ wxVariantDataWxObjectPtr(wxObject* value) { m_value = value; }
+
+ inline wxObject* GetValue() const { return m_value; }
+ inline void SetValue(wxObject* 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 ;
+ virtual wxVariantData* Clone() { return new wxVariantDataWxObjectPtr; }
+
+ virtual wxClassInfo* GetValueClassInfo() ;
+protected:
+ wxObject* m_value;
+
+ DECLARE_NO_COPY_CLASS(wxVariantDataWxObjectPtr)
+};
+
+IMPLEMENT_DYNAMIC_CLASS(wxVariantDataWxObjectPtr, wxVariantData)
+
+void wxVariantDataWxObjectPtr::Copy(wxVariantData& data)
+{
+ wxASSERT_MSG( wxIsKindOf((&data), wxVariantDataWxObjectPtr) ,\
+ wxT("wxVariantDataWxObjectPtr::Copy: Can't copy to this type of data") \
+ );
+
+ wxVariantDataWxObjectPtr& otherData = (wxVariantDataWxObjectPtr&) data;
+
+ otherData.m_value = m_value;
+}
+
+bool wxVariantDataWxObjectPtr::Eq(wxVariantData& data) const
+{
+ wxASSERT_MSG( wxIsKindOf((&data), wxVariantDataWxObjectPtr), wxT("wxVariantDataWxObjectPtr::Eq: argument mismatch") );
+
+ wxVariantDataWxObjectPtr& otherData = (wxVariantDataWxObjectPtr&) data;
+
+ return (otherData.m_value == m_value);
+}
+
+wxString wxVariantDataWxObjectPtr::GetType() const
+{
+ wxString returnVal(wxT("wxObject"));
+ if (m_value) {
+ returnVal = m_value->GetClassInfo()->GetClassName();
+ }
+ return returnVal;
+}
+
+wxClassInfo* wxVariantDataWxObjectPtr::GetValueClassInfo()
+{
+ wxClassInfo* returnVal=NULL;
+
+ if (m_value) returnVal = m_value->GetClassInfo();
+
+ return returnVal;
+}
+
+#if wxUSE_STD_IOSTREAM
+bool wxVariantDataWxObjectPtr::Write(wxSTD ostream& str) const
+{
+ wxString s;
+ Write(s);
+ str << (const char*) s.mb_str();
+ return TRUE;
+}
+#endif
+
+bool wxVariantDataWxObjectPtr::Write(wxString& str) const
+{
+ str.Printf(wxT("%s(%ld)"), GetType().c_str(), (long) m_value);
+ return TRUE;
+}
+
+#if wxUSE_STD_IOSTREAM
+bool wxVariantDataWxObjectPtr::Read(wxSTD istream& WXUNUSED(str))
+{
+ // Not implemented
+ return FALSE;
+}
+#endif
+
+bool wxVariantDataWxObjectPtr::Read(wxString& WXUNUSED(str))
+{
+ // Not implemented
+ return FALSE;
+}
+
+
/*
* wxVariantDataDateTime
*/
m_name = name;
}
+wxVariant::wxVariant( void* val, const wxString& name)
+{
+ m_data = new wxVariantDataVoidPtr(val);
+ m_name = name;
+}
+
+wxVariant::wxVariant( wxObject* val, const wxString& name)
+{
+ m_data = new wxVariantDataWxObjectPtr(val);
+ 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
{
wxVariantDataStringList* data = (wxVariantDataStringList*) m_data;
wxASSERT_MSG( (idx < (size_t) data->GetValue().GetCount()), wxT("Invalid index for array") );
- wxVariant variant( wxString( (wxChar*) (data->GetValue().Item(idx)->GetData()) ));
+ wxVariant variant( wxString( (const wxChar*) (data->GetValue().Item(idx)->GetData()) ));
return variant;
}
return wxNullVariant;
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
return (void*) ((wxVariantDataVoidPtr*) m_data)->GetValue();
}
+wxObject* wxVariant::GetWxObjectPtr()
+{
+ wxASSERT(wxIsKindOf(m_data, wxVariantDataWxObjectPtr));
+ return (wxObject*) ((wxVariantDataWxObjectPtr*) m_data)->GetValue();
+}
+
#if wxUSE_DATETIME
wxDateTime wxVariant::GetDateTime() const
{
{
wxList& list = GetList();
- wxNode* node = list.GetFirst();
+ wxList::compatibility_iterator node = list.GetFirst();
while (node)
{
wxVariant* other = (wxVariant*) node->GetData();
wxList& list = GetList();
wxASSERT_MSG( (item < (int) list.GetCount()), wxT("Invalid index to Delete") );
- wxNode* node = list.Item(item);
+ wxList::compatibility_iterator node = list.Item(item);
wxVariant* variant = (wxVariant*) node->GetData();
delete variant;
- delete node;
+ list.Erase(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;