class TShared

template<typename Type, ThreadSafetyPolicy ThreadSafety = ThreadSafe>

Reference counted object pointer that will keep the underlying object alive as long as the reference count is above 0.

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

TShared<Type, ThreadSafety>

TShared<Type, ThreadSafety>() = default

TShared<Type, ThreadSafety>

constexpr TShared<Type, ThreadSafety>(nullptr_t)

TShared<Type, ThreadSafety>

TShared<Type, ThreadSafety>(const TShared<Type, ThreadSafety> &other)

TShared<Type, ThreadSafety>

TShared<Type, ThreadSafety>(TShared<Type, ThreadSafety> &&other)

Methods

~TShared<Type, ThreadSafety>

~TShared<Type, ThreadSafety>()

Swap

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

Swaps the shared pointer with another.

Reset

void Reset()

Clears the strong reference and the pointed object.

GetReferenceCount

u32 GetReferenceCount() const

Returns the number of strong references held by the pointer.

Get

Type *Get() const

Returns the underlying object.

Operators

operator=

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

operator=

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

operator bool

explicit operator bool() const

True if the pointed object is still alive.

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