6 #ifndef DOXYGEN_SHOULD_SKIP_THIS
16 struct WeakRef : RefBase<T> {
24 WeakRef(std::nullptr_t) noexcept {}
29 explicit WeakRef(T* ptr) noexcept { *
this = ptr; }
34 WeakRef(
const WeakRef& other) noexcept { *
this = other; }
39 WeakRef(
const Ref<T>& other) noexcept { *
this = other; }
51 WeakRef& operator = (
const Ref<T>& other) noexcept {
52 return assign(other.get());
59 WeakRef& operator = (
const WeakRef& other) noexcept {
60 return assign(other.get());
68 WeakRef& operator = (T* ptr) noexcept {
76 WeakRef& operator = (std::nullptr_t) noexcept {
85 WeakRef& assign(T* ptr) noexcept {
86 if(this->
get() != ptr)
89 this->
get()->releaseWeak();
96 if(this->
get() && this->
get()->retainWeak() < 1)
106 void reset() noexcept {
114 Ref<T> lock() const noexcept {
115 return (!this->
get() || this->isExpired()) ? Ref<T>() : Ref<T>(this->
get());
121 template<
typename S> WeakRef<S> as() noexcept {
122 return WeakRef<S>(
static_cast<S*
>(this->
get()));
132 inline WeakRef<T> make_weak_ref(T* ptr) noexcept {
133 return WeakRef<T>(ptr);
142 template<
typename S,
typename T>
143 inline WeakRef<S> make_weak_ref_as(T* ptr) noexcept {
144 return WeakRef<S>(
static_cast<S*
>(ptr));
151 *
this = other.lock();
Ref & operator=(const Ref &other) noexcept
Assign a strong reference.
Definition: Ref.h:112