5 #ifndef DOXYGEN_SHOULD_SKIP_THIS
15 struct WeakRef : RefBase<T> {
23 WeakRef(std::nullptr_t) noexcept {}
28 explicit WeakRef(T* ptr) noexcept { *
this = ptr; }
33 WeakRef(
const WeakRef& other) noexcept { *
this = other; }
38 WeakRef(
const Ref<T>& other) noexcept { *
this = other; }
50 WeakRef& operator = (
const Ref<T>& other) noexcept {
51 return assign(other.get());
58 WeakRef& operator = (
const WeakRef& other) noexcept {
59 return assign(other.get());
67 WeakRef& operator = (T* ptr) noexcept {
75 WeakRef& operator = (std::nullptr_t) noexcept {
84 WeakRef& assign(T* ptr) noexcept {
85 if(this->
get() != ptr)
88 this->
get()->releaseWeak();
95 if(this->
get() && this->
get()->retainWeak() < 1)
105 void reset() noexcept {
113 Ref<T> lock() const noexcept {
114 return (!this->
get() || this->isExpired()) ? Ref<T>() : Ref<T>(this->
get());
120 template<
typename S> WeakRef<S> as() noexcept {
121 return WeakRef<S>(
static_cast<S*
>(this->
get()));
131 inline WeakRef<T> make_weak_ref(T* ptr) noexcept {
132 return WeakRef<T>(ptr);
141 template<
typename S,
typename T>
142 inline WeakRef<S> make_weak_ref_as(T* ptr) noexcept {
143 return WeakRef<S>(
static_cast<S*
>(ptr));
151 *
this = other.lock();
Ref & operator=(const Ref &other) noexcept
Assign a strong reference.
Definition: Ref.h:110