MCRO
C++23 utilities for Unreal Engine.
|
Concepts | |
concept | CSharedInitializeable |
Typedefs | |
template<CSharedOrWeak T> | |
using | TSharedPtrFrom = TSharedPtr<typename T::ElementType, T::Mode> |
template<CSharedOrWeak T> | |
using | TSharedRefFrom = TSharedRef<typename T::ElementType, T::Mode> |
template<CSharedOrWeak T> | |
using | TWeakPtrFrom = TWeakPtr<typename T::ElementType, T::Mode> |
Functions | |
template<typename T , ESPMode Mode = ESPMode::ThreadSafe, typename... Args> requires CSharedInitializeable<T, Args...> | |
TSharedRef< T, Mode > | MakeShareableInit (T *newObject, Args &&... args) |
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) |
template<CRefCounted T, ESPMode Mode = ESPMode::ThreadSafe> | |
TSharedRef< T, Mode > | ShareRefCounted (T *object) |
template<CSharedFromThis T, ESPMode Mode = decltype(DeclVal<T const>().AsShared())::Mode> | |
auto | WeakSelf (const T *self) -> TWeakPtr< T const, Mode > |
template<CSharedFromThis T, ESPMode Mode = decltype(DeclVal<T>().AsShared())::Mode> | |
auto | WeakSelf (T *self) -> TWeakPtr< T, Mode > |
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::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 |
Definition at line 99 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 63 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 114 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 130 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 144 of file SharedObjects.h.