UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
FieldAccessor.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3#pragma once
4
5#include "CoreTypes.h"
7
38template <typename T>
40{
41public:
42 // Owned by another class that will control the value. Will not use the internal value.
44 : Get(MoveTemp(InGet))
45 , Set(MoveTemp(InSet))
46 {
47 }
48
49 // Self-owned value with initializer
51 : CapturedValue(InValue)
52 , Get([this]()-> T* { return CapturedValue; })
53 , Set([this](T* InPtr) { CapturedValue = InPtr; })
54 {
55 }
56
57 // Capture the value of the passed field accessor and becomes self-owned.
59 : CapturedValue(Other.Get())
60 , Get([this]()-> T* { return CapturedValue; })
61 , Set([this](T* InPtr) { CapturedValue = InPtr; })
62 {
63 }
64
67
68 T* operator ->() const
69 {
70 return Get();
71 }
72
73 operator bool() const
74 {
75 return Get() != nullptr;
76 }
77
78 operator T* () const
79 {
80 return Get();
81 }
82
83 template<typename OtherT>
84 explicit operator OtherT* () const
85 {
86 return (OtherT*)Get();
87 }
88
89 bool operator!() const
90 {
91 return Get() == nullptr;
92 }
93
94 bool operator == (const T* OtherPtr) const
95 {
96 return Get() == OtherPtr;
97 }
98
99 bool operator != (const T* OtherPtr) const
100 {
101 return Get() != OtherPtr;
102 }
103
105 {
106 Set(OtherPtr);
107 return *this;
108 }
109
110private:
111 // This is used only when capturing the value from another TFieldPtrAccessor.
112 T* CapturedValue = nullptr;
113 TFunction< T* ()> Get;
114 TFunction<void(T*)> Set;
115};
OODEFFUNC typedef void(OODLE_CALLBACK t_fp_OodleCore_Plugin_Free)(void *ptr)
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
const bool
Definition NetworkReplayStreaming.h:178
UE_INTRINSIC_CAST UE_REWRITE constexpr std::remove_reference_t< T > && MoveTemp(T &&Obj) noexcept
Definition UnrealTemplate.h:520
Definition FieldAccessor.h:40
TFieldPtrAccessor & operator=(TFieldPtrAccessor &&)=delete
TFieldPtrAccessor(T *InValue=nullptr)
Definition FieldAccessor.h:50
TFieldPtrAccessor(TFunction< T *()> InGet, TFunction< void(T *)> InSet)
Definition FieldAccessor.h:43
TFieldPtrAccessor & operator=(const TFieldPtrAccessor &Other)=delete
T * operator->() const
Definition FieldAccessor.h:68
bool operator!=(const T *OtherPtr) const
Definition FieldAccessor.h:99
TFieldPtrAccessor(const TFieldPtrAccessor &Other)
Definition FieldAccessor.h:58
bool operator==(const T *OtherPtr) const
Definition FieldAccessor.h:94
bool operator!() const
Definition FieldAccessor.h:89
Definition AndroidPlatformMisc.h:14