]> git.saurik.com Git - wxWidgets.git/blobdiff - src/common/variant.cpp
Revert change to add -t to buildbot test runs as some branches don't have it.
[wxWidgets.git] / src / common / variant.cpp
index b1c8838981a2473b4cfcd3fdcc6f5ef71cc5fed2..86c60ec187fe78c0516c11f31f173af40853d360 100644 (file)
@@ -193,6 +193,49 @@ bool wxVariant::IsValueKindOf(const wxClassInfo* type) const
     return info ? info->IsKindOf(type) : false ;
 }
 
+// -----------------------------------------------------------------
+// wxVariant <-> wxAny conversion code
+// -----------------------------------------------------------------
+
+#if wxUSE_ANY
+
+wxAnyToVariantRegistration::
+    wxAnyToVariantRegistration(wxVariantDataFactory factory)
+        : m_factory(factory)
+{
+    wxPreRegisterAnyToVariant(this);
+}
+
+wxVariant::wxVariant(const wxAny& any)
+    : wxObject()
+{
+    wxVariant variant;
+    if ( !any.GetAs(&variant) )
+    {
+        wxFAIL_MSG("wxAny of this type cannot be converted to wxVariant");
+        return;
+    }
+
+    *this = variant;
+}
+
+wxAny wxVariant::GetAny() const
+{
+    wxAny any;
+
+    if ( IsNull() )
+        return wxAny((const wxAny&)any);
+
+    wxVariantData* data = GetData();
+
+    if ( data->GetAsAny(&any) )
+        return wxAny((const wxAny&)any);
+
+    // If everything else fails, wrap the whole wxVariantData
+    return wxAny(((wxVariantData*)data));
+}
+
+#endif // wxUSE_ANY
 
 // -----------------------------------------------------------------
 // wxVariantDataLong
@@ -224,10 +267,27 @@ public:
 
     virtual wxString GetType() const { return wxT("long"); }
 
+    // Since wxAny does not have separate type for integers shorter than
+    // longlong, we do not usually implement wxVariant->wxAny conversion
+    // here (but in wxVariantDataLongLong instead).
+#ifndef wxLongLong_t
+    DECLARE_WXANY_CONVERSION()
+#else
+    bool GetAsAny(wxAny* any) const
+    {
+        *any = m_value;
+        return true;
+    }
+#endif
+
 protected:
     long m_value;
 };
 
+#ifndef wxLongLong_t
+IMPLEMENT_TRIVIAL_WXANY_CONVERSION(long, wxVariantDataLong)
+#endif
+
 bool wxVariantDataLong::Eq(wxVariantData& data) const
 {
     wxASSERT_MSG( (data.GetType() == wxT("long")), wxT("wxVariantDataLong::Eq: argument mismatch") );
@@ -373,10 +433,14 @@ public:
     virtual wxString GetType() const { return wxT("double"); }
 
     wxVariantData* Clone() const { return new wxVariantDoubleData(m_value); }
+
+    DECLARE_WXANY_CONVERSION()
 protected:
     double m_value;
 };
 
+IMPLEMENT_TRIVIAL_WXANY_CONVERSION(double, wxVariantDoubleData)
+
 bool wxVariantDoubleData::Eq(wxVariantData& data) const
 {
     wxASSERT_MSG( (data.GetType() == wxT("double")), wxT("wxVariantDoubleData::Eq: argument mismatch") );
@@ -509,10 +573,14 @@ public:
     virtual wxString GetType() const { return wxT("bool"); }
 
     wxVariantData* Clone() const { return new wxVariantDataBool(m_value); }
+
+    DECLARE_WXANY_CONVERSION()
 protected:
     bool m_value;
 };
 
+IMPLEMENT_TRIVIAL_WXANY_CONVERSION(bool, wxVariantDataBool)
+
 bool wxVariantDataBool::Eq(wxVariantData& data) const
 {
     wxASSERT_MSG( (data.GetType() == wxT("bool")), wxT("wxVariantDataBool::Eq: argument mismatch") );
@@ -646,10 +714,13 @@ public:
     virtual wxString GetType() const { return wxT("char"); }
     wxVariantData* Clone() const { return new wxVariantDataChar(m_value); }
 
+    DECLARE_WXANY_CONVERSION()
 protected:
     wxUniChar m_value;
 };
 
+IMPLEMENT_TRIVIAL_WXANY_CONVERSION(wxUniChar, wxVariantDataChar)
+
 bool wxVariantDataChar::Eq(wxVariantData& data) const
 {
     wxASSERT_MSG( (data.GetType() == wxT("char")), wxT("wxVariantDataChar::Eq: argument mismatch") );
@@ -798,10 +869,13 @@ public:
     virtual wxString GetType() const { return wxT("string"); }
     wxVariantData* Clone() const { return new wxVariantDataString(m_value); }
 
+    DECLARE_WXANY_CONVERSION()
 protected:
     wxString m_value;
 };
 
+IMPLEMENT_TRIVIAL_WXANY_CONVERSION(wxString, wxVariantDataString)
+
 bool wxVariantDataString::Eq(wxVariantData& data) const
 {
     wxASSERT_MSG( (data.GetType() == wxT("string")), wxT("wxVariantDataString::Eq: argument mismatch") );
@@ -954,10 +1028,13 @@ public:
 
     virtual wxClassInfo* GetValueClassInfo();
 
+    DECLARE_WXANY_CONVERSION()
 protected:
     wxObject* m_value;
 };
 
+IMPLEMENT_TRIVIAL_WXANY_CONVERSION(wxObject*, wxVariantDataWxObjectPtr)
+
 bool wxVariantDataWxObjectPtr::Eq(wxVariantData& data) const
 {
     wxASSERT_MSG( data.GetType() == GetType(), wxT("wxVariantDataWxObjectPtr::Eq: argument mismatch") );
@@ -1073,10 +1150,13 @@ public:
     virtual wxString GetType() const { return wxT("void*"); }
     virtual wxVariantData* Clone() const { return new wxVariantDataVoidPtr(m_value); }
 
+    DECLARE_WXANY_CONVERSION()
 protected:
     void* m_value;
 };
 
+IMPLEMENT_TRIVIAL_WXANY_CONVERSION(void*, wxVariantDataVoidPtr)
+
 bool wxVariantDataVoidPtr::Eq(wxVariantData& data) const
 {
     wxASSERT_MSG( data.GetType() == wxT("void*"), wxT("wxVariantDataVoidPtr::Eq: argument mismatch") );
@@ -1185,10 +1265,12 @@ public:
     virtual wxString GetType() const { return wxT("datetime"); }
     virtual wxVariantData* Clone() const { return new wxVariantDataDateTime(m_value); }
 
+    DECLARE_WXANY_CONVERSION()
 protected:
     wxDateTime m_value;
 };
 
+IMPLEMENT_TRIVIAL_WXANY_CONVERSION(wxDateTime, wxVariantDataDateTime)
 
 bool wxVariantDataDateTime::Eq(wxVariantData& data) const
 {
@@ -1316,10 +1398,13 @@ public:
     virtual wxString GetType() const { return wxT("arrstring"); }
     virtual wxVariantData* Clone() const { return new wxVariantDataArrayString(m_value); }
 
+    DECLARE_WXANY_CONVERSION()
 protected:
     wxArrayString m_value;
 };
 
+IMPLEMENT_TRIVIAL_WXANY_CONVERSION(wxArrayString, wxVariantDataArrayString)
+
 bool wxVariantDataArrayString::Eq(wxVariantData& data) const
 {
     wxASSERT_MSG( data.GetType() == GetType(), wxT("wxVariantDataArrayString::Eq: argument mismatch") );
@@ -1449,10 +1534,48 @@ public:
 
     virtual wxString GetType() const { return wxS("longlong"); }
 
+    DECLARE_WXANY_CONVERSION()
 protected:
     wxLongLong m_value;
 };
 
+//
+// wxLongLong type requires customized wxAny conversion code
+//
+#if wxUSE_ANY
+#ifdef wxLongLong_t
+
+bool wxVariantDataLongLong::GetAsAny(wxAny* any) const
+{
+    *any = m_value.GetValue();
+    return true;
+}
+
+wxVariantData* wxVariantDataLongLong::VariantDataFactory(const wxAny& any)
+{
+    return new wxVariantDataLongLong(wxANY_AS(any, wxLongLong_t));
+}
+
+REGISTER_WXANY_CONVERSION(wxLongLong_t, wxVariantDataLongLong)
+
+#else // if !defined(wxLongLong_t)
+
+bool wxVariantDataLongLong::GetAsAny(wxAny* any) const
+{
+    *any = m_value;
+    return true;
+}
+
+wxVariantData* wxVariantDataLongLong::VariantDataFactory(const wxAny& any)
+{
+    return new wxVariantDataLongLong(wxANY_AS(any, wxLongLong));
+}
+
+REGISTER_WXANY_CONVERSION(wxLongLong, wxVariantDataLongLong)
+
+#endif // defined(wxLongLong_t)/!defined(wxLongLong_t)
+#endif // wxUSE_ANY
+
 bool wxVariantDataLongLong::Eq(wxVariantData& data) const
 {
     wxASSERT_MSG( (data.GetType() == wxS("longlong")),
@@ -1610,10 +1733,49 @@ public:
 
     virtual wxString GetType() const { return wxS("ulonglong"); }
 
+    DECLARE_WXANY_CONVERSION()
 protected:
     wxULongLong m_value;
 };
 
+//
+// wxULongLong type requires customized wxAny conversion code
+//
+#if wxUSE_ANY
+#ifdef wxLongLong_t
+
+bool wxVariantDataULongLong::GetAsAny(wxAny* any) const
+{
+    *any = m_value.GetValue();
+    return true;
+}
+
+wxVariantData* wxVariantDataULongLong::VariantDataFactory(const wxAny& any)
+{
+    return new wxVariantDataULongLong(wxANY_AS(any, wxULongLong_t));
+}
+
+REGISTER_WXANY_CONVERSION(wxULongLong_t, wxVariantDataULongLong)
+
+#else // if !defined(wxLongLong_t)
+
+bool wxVariantDataULongLong::GetAsAny(wxAny* any) const
+{
+    *any = m_value;
+    return true;
+}
+
+wxVariantData* wxVariantDataULongLong::VariantDataFactory(const wxAny& any)
+{
+    return new wxVariantDataULongLong(wxANY_AS(any, wxULongLong));
+}
+
+REGISTER_WXANY_CONVERSION(wxULongLong, wxVariantDataULongLong)
+
+#endif // defined(wxLongLong_t)/!defined(wxLongLong_t)
+#endif // wxUSE_ANY
+
+
 bool wxVariantDataULongLong::Eq(wxVariantData& data) const
 {
     wxASSERT_MSG( (data.GetType() == wxS("ulonglong")),
@@ -1764,10 +1926,54 @@ public:
     void Clear();
 
     wxVariantData* Clone() const { return new wxVariantDataList(m_value); }
+
+    DECLARE_WXANY_CONVERSION()
 protected:
     wxVariantList  m_value;
 };
 
+#if wxUSE_ANY
+
+//
+// Convert to/from list of wxAnys
+//
+
+WX_DEFINE_LIST(wxAnyList)
+
+bool wxVariantDataList::GetAsAny(wxAny* any) const
+{
+    wxAnyList dst;
+    wxVariantList::compatibility_iterator node = m_value.GetFirst();
+    while (node)
+    {
+        wxVariant* pVar = node->GetData();
+        dst.push_back(new wxAny(((const wxVariant&)*pVar)));
+        node = node->GetNext();
+    }
+
+    *any = dst;
+    return true;
+}
+
+wxVariantData* wxVariantDataList::VariantDataFactory(const wxAny& any)
+{
+    wxAnyList src = wxANY_AS(any, wxAnyList);
+    wxVariantList dst;
+    wxAnyList::compatibility_iterator node = src.GetFirst();
+    while (node)
+    {
+        wxAny* pAny = node->GetData();
+        dst.push_back(new wxVariant(*pAny));
+        node = node->GetNext();
+    }
+
+    return new wxVariantDataList(dst);
+}
+
+REGISTER_WXANY_CONVERSION(wxAnyList, wxVariantDataList)
+
+#endif // wxUSE_ANY
+
 wxVariantDataList::wxVariantDataList(const wxVariantList& list)
 {
     SetValue(list);