diff options
| author | Maxime Coste <frrrwww@gmail.com> | 2012-06-30 00:33:36 +0200 |
|---|---|---|
| committer | Maxime Coste <frrrwww@gmail.com> | 2012-06-30 00:33:36 +0200 |
| commit | f11d44246cb3a46317d29258a0169dfacdf15eec (patch) | |
| tree | 254f64d64480c7d0b195c45eaa0a13c5f8ee1c43 /src/utils.hh | |
| parent | dfbda951d38386d992c5ecd005fdf78ae93cb3d3 (diff) | |
add safe_ptr::operator=(safe_ptr&&) and safe_ptr::reset(T*)
Diffstat (limited to 'src/utils.hh')
| -rw-r--r-- | src/utils.hh | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/src/utils.hh b/src/utils.hh index ec2ac364..6555e320 100644 --- a/src/utils.hh +++ b/src/utils.hh @@ -76,10 +76,26 @@ public: if (m_ptr) m_ptr->inc_safe_count(); } - return *this; } + safe_ptr& operator=(safe_ptr&& other) + { + if (m_ptr != other.m_ptr) + { + if (m_ptr) + m_ptr->dec_safe_count(); + m_ptr = other.m_ptr; + other.m_ptr = nullptr; + } + return *this; + } + + void reset(T* ptr) + { + *this = safe_ptr(ptr); + } + bool operator== (const safe_ptr& other) const { return m_ptr == other.m_ptr; } bool operator!= (const safe_ptr& other) const { return m_ptr != other.m_ptr; } bool operator== (T* ptr) const { return m_ptr == ptr; } |
