class TWeak

template<typename Type, ThreadSafetyPolicy ThreadSafety = ThreadSafe>

References an object owned by a TShared.

Unlike TShared, this type of pointer will not keep the object alive, and the referenced object may or may not still be live. Weak pointer must be converted to a strong pointer (TShared) before use.

Template parameters

Type

Object type to reference by the pointer.

ThreadSafety

If ThreadSafe, shared pointer can be safely accessed from multiple threads, otherwise it is only safe to access from a single thread. Non-thread safe version is faster.

Public

Constructors

TWeak<Type, ThreadSafety>

TWeak<Type, ThreadSafety>() = default

TWeak<Type, ThreadSafety>

explicit TWeak<Type, ThreadSafety>(const TWeak<Type, ThreadSafety> &other)

Methods

~TWeak<Type, ThreadSafety>

~TWeak<Type, ThreadSafety>()

Swap

void Swap(TWeak<Type, ThreadSafety> &other)

Swaps the shared pointer with another.

Reset

void Reset()

Clears the strong reference and the pointed object.

IsExpired

bool IsExpired() const

Returns true if the underlying object is still valid.

Pin

TShared<Type> Pin() const

Converts a weak pointer to a strong pointer.

GetReferenceCount

u32 GetReferenceCount() const

Returns the number of strong references held by the pointer.

Get

Type *Get() const

Returns the underlying object.

Operators

operator=

TWeak<Type, ThreadSafety> &operator=(const TWeak<Type, ThreadSafety> &rhs)

operator=

TWeak<Type, ThreadSafety> &operator=(TWeak<Type, ThreadSafety> &&rhs)

Protected

Methods

~TSharedCommon<Type, ThreadSafety>

~TSharedCommon<Type, ThreadSafety>() = default

IncrementStrongReferenceCount

void IncrementStrongReferenceCount() const

Increments the strong reference count.

DecrementStrongReferenceCount

void DecrementStrongReferenceCount() const

Decrements the strong reference count, and releases the object if count is zero.

IncrementWeakReferenceCount

void IncrementWeakReferenceCount() const

Increments the weak reference count.

DecrementWeakReferenceCount

void DecrementWeakReferenceCount() const

Decrements the weak reference count, and releases the control block if the count is zero.

Fields

mOwnedObject

Type * mOwnedObject

mControlBlock

TSharedControlBlock<ThreadSafety> * mControlBlock