X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/2ab25aca26bffe363b1f76623c736602a70eb56f..785f5eaa05195f5e44a974861864324667a3326e:/src/common/variant.cpp diff --git a/src/common/variant.cpp b/src/common/variant.cpp index c6a70f2a33..79f7c116a7 100644 --- a/src/common/variant.cpp +++ b/src/common/variant.cpp @@ -9,7 +9,7 @@ // Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// -#ifdef __GNUG__ +#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA) #pragma implementation "variant.h" #endif @@ -28,6 +28,10 @@ #endif #endif +#if defined(__MWERKS__) && __MSL__ >= 0x6000 +using namespace std ; +#endif + #if wxUSE_STREAMS #include "wx/stream.h" #include "wx/txtstrm.h" @@ -40,13 +44,13 @@ 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: @@ -90,7 +94,7 @@ wxVariantDataList::~wxVariantDataList() void wxVariantDataList::SetValue(const wxList& value) { Clear(); - wxNode* node = value.GetFirst(); + wxList::compatibility_iterator node = value.GetFirst(); while (node) { wxVariant* var = (wxVariant*) node->GetData(); @@ -101,7 +105,7 @@ void wxVariantDataList::SetValue(const wxList& value) void wxVariantDataList::Clear() { - wxNode* node = m_value.GetFirst(); + wxList::compatibility_iterator node = m_value.GetFirst(); while (node) { wxVariant* var = (wxVariant*) node->GetData(); @@ -118,7 +122,7 @@ void wxVariantDataList::Copy(wxVariantData& data) 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(); @@ -132,8 +136,8 @@ bool wxVariantDataList::Eq(wxVariantData& data) const 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(); @@ -160,7 +164,7 @@ bool wxVariantDataList::Write(wxSTD ostream& str) const 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(); @@ -194,7 +198,7 @@ bool wxVariantDataList::Read(wxString& WXUNUSED(str)) * wxVariantDataStringList */ -class WXDLLEXPORT wxVariantDataStringList: public wxVariantData +class WXDLLIMPEXP_BASE wxVariantDataStringList: public wxVariantData { DECLARE_DYNAMIC_CLASS(wxVariantDataStringList) public: @@ -241,8 +245,8 @@ bool wxVariantDataStringList::Eq(wxVariantData& data) const 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() ); @@ -269,10 +273,10 @@ bool wxVariantDataStringList::Write(wxSTD ostream& str) const 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; @@ -302,7 +306,7 @@ bool wxVariantDataStringList::Read(wxString& WXUNUSED(str)) * wxVariantDataLong */ -class WXDLLEXPORT wxVariantDataLong: public wxVariantData +class WXDLLIMPEXP_BASE wxVariantDataLong: public wxVariantData { DECLARE_DYNAMIC_CLASS(wxVariantDataLong) public: @@ -403,7 +407,7 @@ bool wxVariantDataLong::Read(wxString& str) * wxVariantDataReal */ -class WXDLLEXPORT wxVariantDataReal: public wxVariantData +class WXDLLIMPEXP_BASE wxVariantDataReal: public wxVariantData { DECLARE_DYNAMIC_CLASS(wxVariantDataReal) public: @@ -504,7 +508,7 @@ bool wxVariantDataReal::Read(wxString& str) * wxVariantDataBool */ -class WXDLLEXPORT wxVariantDataBool: public wxVariantData +class WXDLLIMPEXP_BASE wxVariantDataBool: public wxVariantData { DECLARE_DYNAMIC_CLASS(wxVariantDataBool) public: @@ -608,7 +612,7 @@ bool wxVariantDataBool::Read(wxString& str) * wxVariantDataChar */ -class WXDLLEXPORT wxVariantDataChar: public wxVariantData +class WXDLLIMPEXP_BASE wxVariantDataChar: public wxVariantData { DECLARE_DYNAMIC_CLASS(wxVariantDataChar) public: @@ -709,18 +713,9 @@ bool wxVariantDataChar::Read(wxString& str) * 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; } @@ -812,11 +807,7 @@ bool wxVariantDataString::Read(wxString& str) return TRUE; } -#if defined(__BORLANDC__) && defined(__WIN16__) -IMPLEMENT_DYNAMIC_CLASS(wxVariantStringData, wxVariantData) -#else IMPLEMENT_DYNAMIC_CLASS(wxVariantDataString, wxVariantData) -#endif /* * wxVariantDataVoidPtr @@ -901,6 +892,111 @@ bool wxVariantDataVoidPtr::Read(wxString& WXUNUSED(str)) 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 */ @@ -1163,6 +1259,26 @@ wxVariant::wxVariant(const wxList& val, const wxString& name) // List of variant 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 { @@ -1606,7 +1722,7 @@ wxVariant wxVariant::operator[] (size_t idx) const 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; @@ -1679,6 +1795,12 @@ 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 @@ -1747,6 +1869,12 @@ void* wxVariant::GetVoidPtr() 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 { @@ -1801,7 +1929,7 @@ bool wxVariant::Member(const wxVariant& value) const { wxList& list = GetList(); - wxNode* node = list.GetFirst(); + wxList::compatibility_iterator node = list.GetFirst(); while (node) { wxVariant* other = (wxVariant*) node->GetData(); @@ -1818,10 +1946,10 @@ bool wxVariant::Delete(int item) 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; } @@ -1878,9 +2006,9 @@ bool wxVariant::Convert(bool* value) const { 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;