24#include <kiwano/core/Common.h>
33template <
typename _Ty,
typename _RefPolicy>
37 using value_type = _Ty;
38 using pointer_type = _Ty*;
39 using const_pointer_type =
const _Ty*;
40 using reference_type = _Ty&;
41 using const_reference_type =
const _Ty&;
56 _RefPolicy::Retain(ptr_);
62 _RefPolicy::Retain(ptr_);
76 template <typename _UTy, typename std::enable_if<std::is_convertible<_UTy*, _Ty*>::value,
int>::type = 0>
79 ptr_ =
dynamic_cast<pointer_type
>(other.Get());
80 _RefPolicy::Retain(ptr_);
83 inline pointer_type Get()
const noexcept
88 inline pointer_type* GetAddressOfAndRelease()
94 inline void Reset(pointer_type ptr =
nullptr)
104 std::swap(ptr_, other.ptr_);
107 inline pointer_type operator->()
112 inline const_pointer_type operator->()
const
117 inline reference_type operator*()
122 inline const_reference_type operator*()
const
127 inline pointer_type* operator&()
129 return this->GetAddressOfAndRelease();
132 inline operator bool()
const noexcept
134 return ptr_ !=
nullptr;
137 inline bool operator!()
const noexcept
144 if (other.ptr_ != ptr_)
151 if (other.ptr_ != ptr_)
163 template <typename _UTy, typename std::enable_if<std::is_convertible<_UTy*, _Ty*>::value,
int>::type = 0>
166 if (other.Get() != ptr_)
167 RefBasePtr(
dynamic_cast<pointer_type
>(other.Get())).Swap(*
this);
180 _RefPolicy::Release(ptr_);
188template <
class _Ty,
class _UTy,
class _RefPolicy>
191 return lhs.Get() == rhs.Get();
194template <
class _Ty,
class _RefPolicy>
195inline bool operator==(
const RefBasePtr<_Ty, _RefPolicy>& lhs, _Ty* rhs)
noexcept
197 return lhs.Get() == rhs;
200template <
class _Ty,
class _RefPolicy>
201inline bool operator==(_Ty* lhs,
const RefBasePtr<_Ty, _RefPolicy>& rhs)
noexcept
203 return lhs == rhs.Get();
206template <
class _Ty,
class _RefPolicy>
207inline bool operator==(
const RefBasePtr<_Ty, _RefPolicy>& lhs, std::nullptr_t)
noexcept
209 return !
static_cast<bool>(lhs);
212template <
class _Ty,
class _RefPolicy>
213inline bool operator==(std::nullptr_t,
const RefBasePtr<_Ty, _RefPolicy>& rhs)
noexcept
215 return !
static_cast<bool>(rhs);
218template <
class _Ty,
class _UTy,
class _RefPolicy>
219inline bool operator!=(
const RefBasePtr<_Ty, _RefPolicy>& lhs,
const RefBasePtr<_UTy, _RefPolicy>& rhs)
noexcept
221 return !(lhs == rhs);
224template <
class _Ty,
class _RefPolicy>
225inline bool operator!=(
const RefBasePtr<_Ty, _RefPolicy>& lhs, _Ty* rhs)
noexcept
227 return lhs.Get() != rhs;
230template <
class _Ty,
class _RefPolicy>
231inline bool operator!=(_Ty* lhs,
const RefBasePtr<_Ty, _RefPolicy>& rhs)
noexcept
233 return lhs != rhs.Get();
236template <
class _Ty,
class _RefPolicy>
237inline bool operator!=(
const RefBasePtr<_Ty, _RefPolicy>& lhs, std::nullptr_t)
noexcept
239 return static_cast<bool>(lhs);
242template <
class _Ty,
class _RefPolicy>
243inline bool operator!=(std::nullptr_t,
const RefBasePtr<_Ty, _RefPolicy>& rhs)
noexcept
245 return static_cast<bool>(rhs);
248template <
class _Ty,
class _UTy,
class _RefPolicy>
249inline bool operator<(
const RefBasePtr<_Ty, _RefPolicy>& lhs,
const RefBasePtr<_UTy, _RefPolicy>& rhs)
noexcept
251 return lhs.Get() < rhs.Get();
256template <
class _Ty,
class _RefPolicy>
257inline void swap(RefBasePtr<_Ty, _RefPolicy>& lhs, RefBasePtr<_Ty, _RefPolicy>& rhs)
noexcept
引用计数智能指针
Definition: RefBasePtr.hpp:35