5#include "HAL/Platform.h"
6#include "Serialization/StructuredArchive.h"
13#define UE_WITH_OBJECT_PTR_DEPRECATIONS 0
15 #define UE_OBJPTR_DEPRECATED(Version, Message) UE_DEPRECATED(Version, Message)
17 #define UE_OBJPTR_DEPRECATED(Version, Message)
21
22
23
24
25
26#define UE_TRANSITIONAL_OBJECT_PTR(Type) auto
27#define UE_TRANSITIONAL_OBJECT_PTR_TEMPLATE(Templ, Type) auto
28#define UE_TRANSITIONAL_OBJECT_PTR_TEMPLATE_SUFFIXED(Templ, Type, Suffix) auto
29#define UE_TRANSITIONAL_OBJECT_PTR_TEMPLATE2_ARG1(Templ, Type1, Type2) auto
30#define UE_TRANSITIONAL_OBJECT_PTR_TEMPLATE2_ARG1_SUFFIXED(Templ, Type1, Type2, Suffix) auto
31#define UE_TRANSITIONAL_OBJECT_PTR_TEMPLATE2_ARG2(Templ, Type1, Type2) auto
32#define UE_TRANSITIONAL_OBJECT_PTR_TEMPLATE2_ARG2_SUFFIXED(Templ, Type1, Type2, Suffix) auto
33#define UE_TRANSITIONAL_OBJECT_PTR_TEMPLATE2_ARG_BOTH(Templ, Type1, Type2) auto
34#define UE_TRANSITIONAL_OBJECT_PTR_TEMPLATE2_ARG_BOTH_SUFFIXED(Templ, Type1, Type2, Suffix) auto
38
39
40
41
42 #define UE_OBJECT_PTR_NONCONFORMANCE_SUPPORT 1
44 #define UE_OBJECT_PTR_NONCONFORMANCE_SUPPORT 0
51
52
55 struct FObjectHandlePrivate;
58using FObjectHandle =
UE::CoreUObject::
Private::FObjectHandlePrivate;
64#if UE_WITH_OBJECT_HANDLE_LATE_RESOLVE
65 {
return { UPTRINT(Object) }; }
73#if UE_WITH_OBJECT_HANDLE_LATE_RESOLVE || UE_WITH_OBJECT_HANDLE_TRACKING
74 UObject* ResolvedObject = ResolveObjectHandleNoRead(Handle);
75 UE::CoreUObject::Private::OnHandleRead(ResolvedObject);
76 return ResolvedObject;
78 return ReadObjectHandlePointerNoCheck(Handle);
82#if UE_WITH_OBJECT_HANDLE_LATE_RESOLVE
91#if UE_WITH_OBJECT_HANDLE_LATE_RESOLVE
92 if (IsObjectHandleResolved(Handle))
94 UObject* Obj = ReadObjectHandlePointerNoCheck(Handle);
95 return Obj !=
nullptr ? Obj->GetClass() :
nullptr;
100 FPackedObjectRef PackedObjectRef = ReadObjectHandlePackedObjectRefNoCheck(Handle);
101 FObjectRef ObjectRef = MakeObjectRef(PackedObjectRef);
102 return ObjectRef.ResolveObjectRefClass();
105 UObject* Obj = ReadObjectHandlePointerNoCheck(Handle);
106 return Obj !=
nullptr ? Obj->GetClass() :
nullptr;
112#if UE_WITH_OBJECT_HANDLE_LATE_RESOLVE
113 FObjectHandle LocalHandle = Handle;
114 if (IsObjectHandleResolved(LocalHandle))
116 UObject* ResolvedObject = ReadObjectHandlePointerNoCheck(LocalHandle);
117 return ResolvedObject;
121 FPackedObjectRef PackedObjectRef = ReadObjectHandlePackedObjectRefNoCheck(LocalHandle);
122 FObjectRef ObjectRef = MakeObjectRef(PackedObjectRef);
123 UObject* ResolvedObject = ObjectRef.Resolve();
124 Handle = MakeObjectHandle(ResolvedObject);
125 return ResolvedObject;
128 return ReadObjectHandlePointerNoCheck(Handle);
135#if UE_WITH_OBJECT_HANDLE_LATE_RESOLVE
136 FObjectHandle LocalHandle = Handle;
137 FPackedObjectRef PackedObjectRef = ReadObjectHandlePackedObjectRefNoCheck(LocalHandle);
138 FObjectRef ObjectRef = MakeObjectRef(PackedObjectRef);
139 UObject* ResolvedObject = ObjectRef.Resolve();
140 LocalHandle = MakeObjectHandle(ResolvedObject);
141 Handle = LocalHandle;
142 return ResolvedObject;
144 return ReadObjectHandlePointerNoCheck(Handle);
150#if UE_WITH_OBJECT_HANDLE_LATE_RESOLVE
151 return reinterpret_cast<UObject*>(Handle.PointerOrRef);
179#if UE_WITH_OBJECT_HANDLE_LATE_RESOLVE
212 UE_OBJPTR_DEPRECATED(5.0,
"Construction with incomplete type pointer is deprecated. Please update this code to use MakeObjectPtrUnsafe.")
218#if UE_WITH_OBJECT_HANDLE_LATE_RESOLVE
228 return UE::CoreUObject::Private::ResolveObjectHandle(Handle);
233 return UE::CoreUObject::Private::ResolveObjectHandleClass(Handle);
243 Handle = UE::CoreUObject::Private::MakeObjectHandle(Other);
247 UE_OBJPTR_DEPRECATED(5.0,
"Assignment with incomplete type pointer is deprecated. Please update this code to use MakeObjectPtrUnsafe.")
250 Handle = UE::CoreUObject::Private::MakeObjectHandle(
reinterpret_cast<UObject*>(IncompleteOther));
256 Handle = UE::CoreUObject::Private::MakeObjectHandle(
nullptr);
271 UE_DEPRECATED(5.1,
"IsNull is deprecated, please use operator bool instead.")
272 FORCEINLINE bool IsNull()
const {
return UE::CoreUObject::Private::ResolveObjectHandleNoRead(Handle) ==
nullptr; }
274 UE_DEPRECATED(5.1,
"IsNullNoResolve is deprecated, please use operator bool instead.")
286#if UE_WITH_OBJECT_HANDLE_LATE_RESOLVE
305 return ResolvedObject ? ResolvedObject->GetPathName() :
TEXT(
"None");
311 return ResolvedObject ? ResolvedObject->GetFName() : NAME_None;
316 return GetFName().ToString();
320
321
322
326 return Get()->GetFullName(
nullptr, Flags);
335 checkfSlow(SomeBase, TEXT(
"IsA(NULL) cannot yield meaningful results"));
339 return ThisClass->IsChildOf(SomeBase);
345 template <
typename T>
354 return GetTypeHash(Object.Handle);
367struct TPrivateObjectPtr;
378 template <
typename T>
386
387
388
389 template <
typename T>
390 UE_OBJPTR_DEPRECATED(5.0,
"Coercing a NULL for operations with a TObjectPtr is deprecated when running in a non-standards conforming compiler mode.")
393 checkfSlow(
Other == 0,
TEXT(
"TObjectPtr cannot be compared to a non-zero NULL type value."));
404 std::is_pointer<CommonPointerType>::value
417 !TIsTObjectPtr<std::decay_t<U>>::Value,
418 decltype(std::declval<U>().Get())
426 template <
typename T,
typename U>
429#if UE_WITH_OBJECT_HANDLE_LATE_RESOLVE
447 !TIsTObjectPtr<std::decay_t<U>>::Value,
448 decltype(CoerceToPointer<T>(std::declval<U>()) == std::declval<
const T*>())
458 template <
typename T,
int =
sizeof(T)>
461 template <
typename T>
468
469
470
471
472
473
474
475
476
477
478
482#ifndef PLATFORM_COMPILER_IWYU
493 using ElementType = T;
515 decltype(ImplicitConv<T*>(
std::declval<U*>()))* =
nullptr
526 !TIsTObjectPtr<std::decay_t<U>>::Value,
527 decltype(ImplicitConv<T*>(std::declval<U>()))
551 decltype(ImplicitConv<T*>(
std::declval<U*>()))* =
nullptr
563 !TIsTObjectPtr<std::decay_t<U>>::Value,
564 decltype(ImplicitConv<T*>(std::declval<U>()))
605#if __cplusplus
< 202002L
640 template <
typename U>
641 UE_OBJPTR_DEPRECATED(5.0,
"Explicit cast to other raw pointer types is deprecated. Please use the Cast API or get the raw pointer with ToRawPtr and cast that instead.")
647 UE_OBJPTR_DEPRECATED(5.0,
"Conversion to a mutable pointer is deprecated. Please pass a TObjectPtr<T>& instead so that assignment can be tracked accurately.")
650 UE_DEPRECATED(5.1,
"IsNull is deprecated, please use operator bool instead. if (!MyObjectPtr) { ... }")
653 UE_DEPRECATED(5.1,
"IsNullNoResolve is deprecated, please use operator bool instead. if (!MyObjectPtr) { ... }")
732 template <
typename T>
738 template <
typename T>
745 template <
typename T>
756 return ObjectPtr_Private::Friend::GetPtrTypeHash(InObjectPtr);
762 return ObjectPtr_Private::Friend::Serialize(Ar, InObjectPtr);
768 ObjectPtr_Private::Friend::SerializePtrStructured(Slot, InObjectPtr);
780 return ObjectPtr_Private::IsObjectPtrEqual(Ptr, Other);
789 return !ObjectPtr_Private::IsObjectPtrEqual(Ptr, Other);
797struct TPrivateObjectPtr
811 friend TPrivateObjectPtr MakeObjectPtrUnsafe<T>(
const UObject* Obj);
818 return TPrivateObjectPtr<T>{Obj};
824 return TObjectPtr<T>{Obj};
840template <
typename T, SIZE_T Size>
843#if UE_WITH_OBJECT_HANDLE_LATE_RESOLVE || UE_WITH_OBJECT_HANDLE_TRACKING
844 for (TObjectPtr<T>& Item : ArrayOfPtr)
850 return reinterpret_cast<T**>(ArrayOfPtr);
863 std::enable_if_t<TIsTArray<ArrayTypeNoRef>::Value>* =
nullptr
867 using ArrayElementType =
typename ArrayTypeNoRef::ElementType;
868 using ArrayAllocatorType =
typename ArrayTypeNoRef::AllocatorType;
870 using QualifiedRawPointerType =
typename TCopyQualifiersFromTo<ArrayElementType, RawPointerType>::Type;
871 using NewArrayType =
TArray<QualifiedRawPointerType, ArrayAllocatorType>;
874 return (RefQualifiedNewArrayType&)Array;
885 UE_OBJPTR_DEPRECATED(5.0,
"Reinterpretation between ranges of one type to another type is deprecated.")
886 static void ReinterpretRange(IterBeginType Iter, IterEndType IterEnd, OperatorType Operator = [](IterBeginType& InIt) ->
decltype(
auto) {
return *InIt; })
888#if UE_WITH_OBJECT_HANDLE_LATE_RESOLVE || UE_WITH_OBJECT_HANDLE_TRACKING
898 UE_OBJPTR_DEPRECATED(5.0,
"Reinterpretation between ranges of one type to another type is deprecated.")
899 static void ReinterpretRangeContiguous(IterBeginType Iter, IterEndType IterEnd, SizeType Size, OperatorType Operator = [](IterBeginType& InIt) ->
decltype(
auto) {
return *InIt; })
901#if UE_WITH_OBJECT_HANDLE_LATE_RESOLVE || UE_WITH_OBJECT_HANDLE_TRACKING
926 UE_OBJPTR_DEPRECATED(5.0,
"Reinterpretation between ranges of one type to another type is deprecated.")
927 static void ReinterpretRange(IterBeginType Iter, IterEndType IterEnd, OperatorType Operator = [](IterBeginType& InIt) ->
decltype(
auto) {
return *InIt; })
929#if UE_WITH_OBJECT_HANDLE_LATE_RESOLVE || UE_WITH_OBJECT_HANDLE_TRACKING
939 UE_OBJPTR_DEPRECATED(5.0,
"Reinterpretation between ranges of one type to another type is deprecated.")
940 static void ReinterpretRangeContiguous(IterBeginType Iter, IterEndType IterEnd, SizeType Size, OperatorType Operator = [](IterBeginType& InIt) ->
decltype(
auto) {
return *InIt; })
942#if UE_WITH_OBJECT_HANDLE_LATE_RESOLVE || UE_WITH_OBJECT_HANDLE_TRACKING
974template <
typename T,
class PREDICATE_CLASS>
999 return TWeakObjectPtr<T>(Ptr);
1013template <
typename T>
1018template <
typename T>
1025template <
typename T>
1026inline void Swap(TArray<TObjectPtr<T>>& A, TArray<T*>& B)
1028 Swap(ToRawPtrTArrayUnsafe(A), B);
1030template <
typename T>
1031inline void Swap(TArray<T*>& A, TArray<TObjectPtr<T>>& B)
1033 Swap(A, ToRawPtrTArrayUnsafe(B));
1037template <
typename T>
1042template <
typename T>
1049template <
typename T>
1050inline void Exchange(TArray<TObjectPtr<T>>& A, TArray<T*>& B)
1052 Swap(ToRawPtrTArrayUnsafe(A), B);
1054template <
typename T>
1055inline void Exchange(TArray<T*>& A, TArray<TObjectPtr<T>>& B)
1057 Swap(A, ToRawPtrTArrayUnsafe(B));
1061
1062
1063template <
typename T>
1066 T* TestPtr = ToRawPtr(Test);
1067 return IsValid(TestPtr) ? TestPtr :
nullptr;
1081template <
typename T,
typename DerivedType>
1087template <
typename T,
typename DerivedType>
1093template <
typename T,
typename DerivedType>
1099template <
typename T,
typename DerivedType>
1102 enum {
Value = TIsPointerOrObjectPtrToBaseOfImpl<std::remove_cv_t<T>, DerivedType>::Value };
1116template <
typename T>
1117struct TPointedToTypeImpl;
1119template <
typename T>
1120struct TPointedToTypeImpl<T*>
1125template <
typename T>
1131template <
typename T>
1132using TPointedToType =
typename TPointedToTypeImpl<T>::Type;
#define checkfSlow(expr, format,...)
#define UE_DEPRECATED(Version, Message)
T * ToRawPtr(const TObjectPtr< T > &Ptr)
FORCEINLINE T ** ToRawPtrArrayUnsafe(T **ArrayOfPtr)
FORCEINLINE bool operator==(U &&Other, const TObjectPtr< T > &Ptr)
void Exchange(TArray< TObjectPtr< T > > &A, TArray< T * > &B)
T * GetValid(const TObjectPtr< T > &Test)
TObjectPtr< T > ToObjectPtr(T *Obj)
void Exchange(TObjectPtr< T > &A, T *&B)
void Swap(TObjectPtr< T > &A, T *&B)
FORCEINLINE uint32 GetTypeHash(const TObjectPtr< T > &InObjectPtr)
FORCEINLINE T * ToRawPtr(T *Ptr)
FORCEINLINE T ** ToRawPtrArrayUnsafe(TObjectPtr< T >(&ArrayOfPtr)[Size])
FORCEINLINE TWeakObjectPtr< T > MakeWeakObjectPtr(TObjectPtr< T > Ptr)
#define UE_OBJECT_PTR_NONCONFORMANCE_SUPPORT
FORCEINLINE bool operator!=(U &&Other, const TObjectPtr< T > &Ptr)
void Swap(TArray< TObjectPtr< T > > &A, TArray< T * > &B)
#define UE_OBJPTR_DEPRECATED(Version, Message)
PRAGMA_DISABLE_DEPRECATION_WARNINGS decltype(auto) ToRawPtrTArrayUnsafe(ArrayType &&Array)
void Exchange(T *&A, TObjectPtr< T > &B)
#define UE_WITH_OBJECT_PTR_DEPRECATIONS
TPrivateObjectPtr< T > MakeObjectPtrUnsafe(const UObject *Obj)
void Swap(T *&A, TObjectPtr< T > &B)
FORCEINLINE void operator<<(FStructuredArchiveSlot Slot, TObjectPtr< T > &InObjectPtr)
bool IsObjectPtrEqual(const TObjectPtr< T > &Ptr, U &&Other)
char(& ResolveTypeIsComplete(...))[1]
char(& ResolveTypeIsComplete(int))[2]
bool IsObjectPtrEqualToRawPtrOfRelatedType(const TObjectPtr< T > &Ptr, const U *Other)
FORCEINLINE auto CoerceToPointer(U &&Other) -> decltype(std::declval< U >().Get())
FORCEINLINE const T * CoerceToPointer(const T *Other)
FORCEINLINE auto CoerceToPointer(U &&Other) -> CommonPointerType
UObject * ReadObjectHandlePointerNoCheck(FObjectHandle Handle)
UObject * ResolveObjectHandleNoReadNoCheck(FObjectHandle &Handle)
UObject * ResolveObjectHandleNoRead(FObjectHandle &Handle)
constexpr uint32 ObjectPathIdShift
constexpr uint32 DataClassDescriptorIdShift
constexpr uint32 ObjectPathIdMask
FObjectHandle MakeObjectHandle(UObject *Object)
UObject * ResolveObjectHandle(FObjectHandle &Handle)
constexpr uint32 DataClassDescriptorIdMask
UClass * ResolveObjectHandleClass(FObjectHandle Handle)
constexpr uint32 PackageIdMask
constexpr uint32 PackageIdShift
FORCEINLINE bool operator!=(FObjectPtr Other) const
FORCEINLINE UObject * Get() const
FORCEINLINE FObjectPtr(UObject *Object)
FORCEINLINE FObjectPtr(TYPE_OF_NULLPTR)
FORCEINLINE operator bool() const
FORCEINLINE FObjectHandle & GetHandleRef() const
FORCEINLINE TObjectPtr< UObject > & ToTObjectPtr()
FORCEINLINE bool IsNullNoResolve() const
FObjectPtr & operator=(UObject *Other)
FORCEINLINE bool IsA(const UClass *SomeBase) const
FORCEINLINE bool operator==(FObjectPtr Other) const
FObjectPtr & operator=(FObjectPtr &&)=default
FORCEINLINE bool IsResolved() const
FORCEINLINE UClass * GetClass() const
FORCEINLINE FObjectHandle GetHandle() const
FORCEINLINE bool operator!() const
FORCEINLINE bool IsA() const
FObjectPtr & operator=(const FObjectPtr &)=default
FORCEINLINE const TObjectPtr< UObject > & ToTObjectPtr() const
FObjectPtr(const FObjectPtr &)=default
FObjectPtr & operator=(void *IncompleteOther)
FObjectPtr(FObjectPtr &&)=default
friend FORCEINLINE uint32 GetTypeHash(const FObjectPtr &Object)
FORCEINLINE FObjectPtr(void *IncompleteObject)
FString GetFullName(EObjectFullNameFlags Flags=EObjectFullNameFlags::None) const
FString GetPathName() const
FORCEINLINE bool IsNull() const
FORCEINLINE UObject * operator->() const
FORCEINLINE UObject & operator*() const
FObjectPtr & operator=(TYPE_OF_NULLPTR)
static FORCEINLINE uint32 GetPtrTypeHash(const TObjectPtr< T > &InObjectPtr)
static FORCEINLINE FArchive & Serialize(FArchive &Ar, TObjectPtr< T > &InObjectPtr)
static FORCEINLINE void SerializePtrStructured(FStructuredArchiveSlot Slot, TObjectPtr< T > &InObjectPtr)
static void ReinterpretRange(IterBeginType Iter, IterEndType IterEnd, OperatorType Operator=[](IterBeginType &InIt) -> decltype(auto) { return *InIt;})
static void ReinterpretRangeContiguous(IterBeginType Iter, IterEndType IterEnd, SizeType Size, OperatorType Operator=[](IterBeginType &InIt) -> decltype(auto) { return *InIt;})
static constexpr void CopyingFromOtherType()
static void ReinterpretRangeContiguous(IterBeginType Iter, IterEndType IterEnd, SizeType Size, OperatorType Operator=[](IterBeginType &InIt) -> decltype(auto) { return *InIt;})
static constexpr void CopyingFromOtherType()
T *const CopyFromOtherType
static void ReinterpretRange(IterBeginType Iter, IterEndType IterEnd, OperatorType Operator=[](IterBeginType &InIt) -> decltype(auto) { return *InIt;})
TDereferenceWrapper(const PREDICATE_CLASS &InPredicate)
const PREDICATE_CLASS & Predicate
FORCEINLINE bool operator()(const TObjectPtr< T > &A, const TObjectPtr< T > &B) const
FORCEINLINE bool IsResolved() const
FORCEINLINE TObjectPtr(U &&Object)
FORCEINLINE FString GetPathName() const
FORCEINLINE T *& GetInternalRef()
FORCEINLINE TObjectPtr< T > & operator=(U &&Object)
FORCEINLINE bool IsNull() const
FORCEINLINE UClass * GetClass() const
FORCEINLINE T * GetNoResolveNoCheck() const
FORCEINLINE T * GetNoReadNoCheck() const
FORCEINLINE TObjectPtr(const TObjectPtr< U > &Other)
TObjectPtr< T > & operator=(const TObjectPtr< T > &)=default
FORCEINLINE TObjectPtr< T > & operator=(TPrivateObjectPtr< T > &&PrivatePtr)
FORCEINLINE operator T*() const
FORCEINLINE T * operator->() const
FORCEINLINE bool operator!=(TYPE_OF_NULLPTR) const
TObjectPtr(TObjectPtr< T > &&Other)=default
FORCEINLINE FString GetName() const
FORCEINLINE TObjectPtr(TPrivateObjectPtr< T > &&PrivatePtr)
FORCEINLINE bool operator==(const TObjectPtr< U > &Other) const
FORCEINLINE bool operator!=(U &&Other) const
FORCEINLINE operator bool() const
FORCEINLINE bool operator==(U &&Other) const
FORCEINLINE bool operator==(TYPE_OF_NULLPTR) const
FORCEINLINE FObjectHandle GetHandle() const
FORCEINLINE operator T*&()
FORCEINLINE bool operator!=(const TObjectPtr< U > &Other) const
FORCEINLINE T * Get() const
FORCEINLINE bool IsA(const UClass *SomeBase) const
FORCEINLINE bool operator!() const
TObjectPtr(const TObjectPtr< T > &Other)=default
FORCEINLINE uint32 GetPtrTypeHash() const
FORCEINLINE TObjectPtr< T > & operator=(const TObjectPtr< U > &Other)
FORCEINLINE bool IsA() const
FORCEINLINE TObjectPtr< T > & operator=(TYPE_OF_NULLPTR)
FORCEINLINE FString GetFullName(EObjectFullNameFlags Flags=EObjectFullNameFlags::None) const
FORCEINLINE FString GetPath() const
TObjectPtr< T > & operator=(TObjectPtr< T > &&)=default
FORCEINLINE operator UPTRINT() const
FORCEINLINE operator U*() const
friend bool ObjectPtr_Private::IsObjectPtrEqualToRawPtrOfRelatedType(const TObjectPtr< U > &Ptr, const V *Other)
FORCEINLINE TObjectPtr(ENoInit)
FORCEINLINE FName GetFName() const
FORCEINLINE void SerializePtrStructured(FStructuredArchiveSlot Slot)
FORCEINLINE bool IsNullNoResolve() const
FORCEINLINE TObjectPtr(TYPE_OF_NULLPTR)
FORCEINLINE T & operator*() const
TPrivateObjectPtr(const TPrivateObjectPtr< T > &Other)=default
TPrivateObjectPtr(const UObject *InPointer)
uint8 _Padding[sizeof(FRWLock)]
FScriptArray DataClassDescriptors