summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--AK/RefPtr.h30
1 files changed, 30 insertions, 0 deletions
diff --git a/AK/RefPtr.h b/AK/RefPtr.h
index 866cea0964..bcf04ec328 100644
--- a/AK/RefPtr.h
+++ b/AK/RefPtr.h
@@ -42,6 +42,17 @@ public:
: m_ptr(other.leak_ref())
{
}
+ RefPtr(const NonnullRefPtr<T>& other)
+ : m_ptr(const_cast<T*>(other.ptr()))
+ {
+ m_ptr->ref();
+ }
+ template<typename U>
+ RefPtr(const NonnullRefPtr<U>& other)
+ : m_ptr(static_cast<T*>(const_cast<U*>(other.ptr())))
+ {
+ m_ptr->ref();
+ }
template<typename U>
RefPtr(NonnullRefPtr<U>&& other)
: m_ptr(static_cast<T*>(&other.leak_ref()))
@@ -100,6 +111,16 @@ public:
return *this;
}
+ RefPtr& operator=(const NonnullRefPtr<T>& other)
+ {
+ if (m_ptr != other.ptr())
+ deref_if_not_null(m_ptr);
+ m_ptr = const_cast<T*>(other.ptr());
+ ASSERT(m_ptr);
+ ref_if_not_null(m_ptr);
+ return *this;
+ }
+
template<typename U>
RefPtr& operator=(const NonnullRefPtr<U>& other)
{
@@ -111,6 +132,15 @@ public:
return *this;
}
+ RefPtr& operator=(const RefPtr& other)
+ {
+ if (m_ptr != other.ptr())
+ deref_if_not_null(m_ptr);
+ m_ptr = const_cast<T*>(other.ptr());
+ ref_if_not_null(m_ptr);
+ return *this;
+ }
+
template<typename U>
RefPtr& operator=(const RefPtr<U>& other)
{