3 #include <fsdk/Types/RefBase.h>
4 #include <fsdk/Types/Ref.h>
8 #ifndef DOXYGEN_SHOULD_SKIP_THIS
18 struct WeakRef : RefBase<T> {
22 WeakRef() noexcept = default;
26 WeakRef(std::nullptr_t) noexcept {}
31 explicit WeakRef(T* ptr) noexcept { *
this = ptr; }
36 WeakRef(
const WeakRef& other) noexcept { *
this = other; }
41 WeakRef(
const Ref<T>& other) noexcept { *
this = other; }
53 WeakRef& operator = (
const Ref<T>& other) noexcept {
54 return assign(other.get());
61 WeakRef& operator = (
const WeakRef& other) noexcept {
62 return assign(other.get());
70 WeakRef& operator = (T* ptr) noexcept {
78 WeakRef& operator = (std::nullptr_t) noexcept {
87 WeakRef& assign(T* ptr) noexcept {
88 if(this->
get() != ptr)
91 this->
get()->releaseWeak();
96 this->
get()->retainWeak();
105 void reset() noexcept {
113 Ref<T> lock() const noexcept {
114 return (!this->
get() || this->isExpired()) ? Ref<T>() : Ref<T>(*
this);
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));
150 if(this->
get() != other.get())
153 this->
get()->release();
155 this->set(other.get());
158 if(this->
get() && this->
get()->retainLocked() < 1)
Ref & operator=(const Ref &other) noexcept
Assign a strong reference.
Definition: Ref.h:124