From: Jaakko Salli Date: Fri, 18 Jun 2010 13:30:47 +0000 (+0000) Subject: Added wxAny::HasSameType() X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/f1156cbb0db33e76e031d05c8823f5c27628b685 Added wxAny::HasSameType() git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@64624 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/include/wx/any.h b/include/wx/any.h index 03453ead82..aebc38df55 100644 --- a/include/wx/any.h +++ b/include/wx/any.h @@ -787,14 +787,24 @@ public: @remarks You cannot reliably test whether two wxAnys are of same value type by simply comparing return values - of wxAny::GetType(). Instead use - wxAnyValueType::CheckType() template function. + of wxAny::GetType(). Instead, use wxAny::HasSameType(). + + @see HasSameType() */ const wxAnyValueType* GetType() const { return m_type; } + /** + Returns @true if this and another wxAny have the same + value type. + */ + bool HasSameType(const wxAny& other) const + { + return GetType()->IsSameType(other.GetType()); + } + /** Tests if wxAny is null (that is, whether there is data). */ diff --git a/interface/wx/any.h b/interface/wx/any.h index 47cc6fb6cd..605fb77f3f 100644 --- a/interface/wx/any.h +++ b/interface/wx/any.h @@ -140,12 +140,19 @@ public: Returns the value type as wxAnyValueType instance. @remarks You cannot reliably test whether two wxAnys are of - same value type by simply comparing return values - of wxAny::GetType(). Instead use - wxAnyValueType::CheckType() template function. + same value type by simply comparing return values + of wxAny::GetType(). Instead, use wxAny::HasSameType(). + + @see HasSameType() */ const wxAnyValueType* GetType() const; + /** + Returns @true if this and another wxAny have the same + value type. + */ + bool HasSameType(const wxAny& other) const; + /** Tests if wxAny is null (that is, whether there is data). */ diff --git a/tests/any/anytest.cpp b/tests/any/anytest.cpp index 0d856445a6..a43b8975cf 100644 --- a/tests/any/anytest.cpp +++ b/tests/any/anytest.cpp @@ -178,6 +178,10 @@ void wxAnyTestCase::CheckType() CPPUNIT_ASSERT(wxANY_CHECK_TYPE(m_anyWcharString2, const wchar_t*)); CPPUNIT_ASSERT(!wxANY_CHECK_TYPE(m_anyWcharString2, wxString)); CPPUNIT_ASSERT(!wxANY_CHECK_TYPE(m_anyWcharString2, const char*)); + + // HasSameType() + CPPUNIT_ASSERT( m_anyWcharString1.HasSameType(m_anyWcharString2) ); + CPPUNIT_ASSERT( !m_anyWcharString1.HasSameType(m_anyBool1) ); } void wxAnyTestCase::Equality()