![]() |
MCRO
C++23 utilities for Unreal Engine.
|
Utilities for TSharedPtr/Ref and related. More...
Data Structures | |
struct | TSharedStorage |
A simple mutable shared storage of any value. More... | |
Concepts | |
concept | CSharedInitializeable |
Concept describing an object which provides a deferred initializer for shared objects. | |
Typedefs | |
template<CSharedOrWeak T> | |
using | TSharedPtrFrom = TSharedPtr<typename T::ElementType, T::Mode> |
Copy thread-safety from other shared object type. | |
template<CSharedOrWeak T> | |
using | TSharedRefFrom = TSharedRef<typename T::ElementType, T::Mode> |
Copy thread-safety from other shared object type. | |
template<CSharedOrWeak T> | |
using | TWeakPtrFrom = TWeakPtr<typename T::ElementType, T::Mode> |
Copy thread-safety from other shared object type. | |
template<CDefaultInitializable T> | |
using | TSharedStoragePtr = TSharedPtr<TSharedStorage<T>> |
template<CDefaultInitializable T> | |
using | TSharedStorageRef = TSharedRef<TSharedStorage<T>> |
template<CDefaultInitializable T> | |
using | TSharedStorageWeakPtr = TWeakPtr<TSharedStorage<T>> |
Functions | |
template<typename T , ESPMode Mode = ESPMode::ThreadSafe, typename... Args> requires CSharedInitializeable<T, Args...> | |
TSharedRef< T, Mode > | MakeShareableInit (T *newObject, Args &&... args) |
A wrapper around MakeShareable that automatically calls an initializer method Initialize on the instantiated object. | |
template<CFunctorObject Initializer, typename... Args, ESPMode Mode = ESPMode::ThreadSafe, typename ResultArg = TFunction_Arg<Initializer, 0>, typename Result = std::decay_t<ResultArg>> requires std::is_lvalue_reference_v<ResultArg> | |
TSharedRef< Result, Mode > | ConstructShared (Initializer &&init, Args &&... args) |
A combination of MakeShareable and Mcro::Construct::ConstructNew. | |
template<CRefCounted T, ESPMode Mode = ESPMode::ThreadSafe> | |
TSharedRef< T, Mode > | ShareRefCounted (T *object) |
Create a shared pointer which takes in an object with in-place refcounting. | |
template<CSharedFromThis T, ESPMode Mode = decltype(DeclVal<T const>().AsShared())::Mode> | |
auto | WeakSelf (const T *self) -> TWeakPtr< T const, Mode > |
Same as SharedThis(this) in TSharedFromThis but returning a weak pointer instead. | |
template<CSharedFromThis T, ESPMode Mode = decltype(DeclVal<T>().AsShared())::Mode> | |
auto | WeakSelf (T *self) -> TWeakPtr< T, Mode > |
Same as SharedThis(this) in TSharedFromThis but returning a weak pointer instead. | |
FORCEINLINE TSharedStorageRef< FDelegateHandle > | MakeSharedDelegateHandle () |
A simple convenience wrapper around making FDelegateHandles shared. | |
Utilities for TSharedPtr/Ref and related.
using Mcro::SharedObjects::TSharedPtrFrom = TSharedPtr<typename T::ElementType, T::Mode> |
Copy thread-safety from other shared object type.
Definition at line 26 of file SharedObjects.h.
using Mcro::SharedObjects::TSharedRefFrom = TSharedRef<typename T::ElementType, T::Mode> |
Copy thread-safety from other shared object type.
Definition at line 30 of file SharedObjects.h.
using Mcro::SharedObjects::TSharedStoragePtr = TSharedPtr<TSharedStorage<T>> |
Definition at line 175 of file SharedObjects.h.
using Mcro::SharedObjects::TSharedStorageRef = TSharedRef<TSharedStorage<T>> |
Definition at line 178 of file SharedObjects.h.
using Mcro::SharedObjects::TSharedStorageWeakPtr = TWeakPtr<TSharedStorage<T>> |
Definition at line 181 of file SharedObjects.h.
using Mcro::SharedObjects::TWeakPtrFrom = TWeakPtr<typename T::ElementType, T::Mode> |
Copy thread-safety from other shared object type.
Definition at line 34 of file SharedObjects.h.
TSharedRef< Result, Mode > Mcro::SharedObjects::ConstructShared | ( | Initializer && | init, |
Args &&... | args ) |
A combination of MakeShareable and Mcro::Construct::ConstructNew.
Usage:
init | A lambda function with a single l-value reference parameter of the object type to initialize. |
args | Arguments of the object constructor |
Definition at line 100 of file SharedObjects.h.
TSharedRef< T, Mode > Mcro::SharedObjects::MakeShareableInit | ( | T * | newObject, |
Args &&... | args ) |
A wrapper around MakeShareable that automatically calls an initializer method Initialize on the instantiated object.
This works around the annoyance of TSharedFromThis objects cannot use their shared pointers in their constructor, braking RAII in some cases. Of course this is only achievable if the object cooperates and implements an Initialize method. It's important that Initialize should not be virtual so derived classes can hide them with their own overload.
Definition at line 64 of file SharedObjects.h.
FORCEINLINE TSharedStorageRef< FDelegateHandle > Mcro::SharedObjects::MakeSharedDelegateHandle | ( | ) |
A simple convenience wrapper around making FDelegateHandles shared.
Definition at line 184 of file SharedObjects.h.
TSharedRef< T, Mode > Mcro::SharedObjects::ShareRefCounted | ( | T * | object | ) |
Create a shared pointer which takes in an object with in-place refcounting.
Refcounted TSharedPtr/Ref doesn't take ownership of the object and when the last reference goes out of scope it simply decreases the refcount instead of deleting the object.
Definition at line 115 of file SharedObjects.h.
auto Mcro::SharedObjects::WeakSelf | ( | const T * | self | ) | -> TWeakPtr<T const, Mode> |
Same as SharedThis(this)
in TSharedFromThis
but returning a weak pointer instead.
Indeed, TSharedFromThis
already has AsWeak()
but that can only return the type which was originally set by TSharedFromThis
making its usage slightly less convenient in derived classes.
Definition at line 133 of file SharedObjects.h.
auto Mcro::SharedObjects::WeakSelf | ( | T * | self | ) | -> TWeakPtr<T, Mode> |
Same as SharedThis(this)
in TSharedFromThis
but returning a weak pointer instead.
Indeed, TSharedFromThis
already has AsWeak()
but that can only return the type which was originally set by TSharedFromThis
making its usage slightly less convenient in derived classes.
Definition at line 149 of file SharedObjects.h.