Added the conversion to unspecfied_bool to all smart pointers, added T& operator* to wxObjectDataPtr

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@51118 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Robert Roebling
2008-01-08 22:02:12 +00:00
parent b3a029f0bb
commit a60b0ddc20
7 changed files with 128 additions and 63 deletions

View File

@@ -55,6 +55,17 @@ public:
return *this;
}
// test for pointer validity: defining conversion to unspecified_bool_type
// and not more obvious bool to avoid implicit conversions to integer types
typedef T *(wxSharedPtr<T>::*unspecified_bool_type)() const;
operator unspecified_bool_type() const
{
if (m_ref && m_ref->m_ptr)
return &wxSharedPtr<T>::get;
else
return NULL;
}
T& operator*() const
{
wxASSERT(m_ref != NULL);
@@ -83,7 +94,6 @@ public:
bool unique() const { return (m_ref ? m_ref->m_count == 1 : true); }
long use_count() const { return (m_ref ? (long)m_ref->m_count : 0); }
operator bool() const { return (get() != NULL); }
private: