Navigation
API > API/Runtime > API/Runtime/Core
Helper to provide backward compatibility when converting a raw pointer into accessors.
The helper is trying hard to mimic's a raw pointer field functionality without breaking compatibility for existing code.
The helper's getter are all const and return a non-const pointer. This is because accessing a pointer field inside a const struct will not make that pointer const like we typically do for accessors. Since we want to mimic the behavior of a public field as much as possible, we offer that same functionality.
The helper supports being captured in a lamba as seen below and will become a const copy of the value at the capture's moment. ex: CapturedValue = Object.OnceARawFieldBecomingAnAccessor { // ExtractedValue contains a copy that will not change even if the original Object.OnceARawFieldBecomingAnAccessor changes. const Class* ExtractedValue = CapturedValue; });
This helper also supports taking a nullptr in its constructor so it properly supports conditional like such ex: ExtractedValue* Val = (Condition) ? Object.OnceARawFieldBecomingAnAccessor : nullptr;
A comforming compiler is supposed to try both conversions (nullptr -> TFieldPtrAccessor and TFieldPtrAccessor -> nullptr) but MSVC without the /permissive- flag will only try to cast nullptr into a TFieldPtrAccessor, which has to succeed to avoid breaking compabitility with existing code.
For more info, please refer to https://docs.microsoft.com/en-us/cpp/build/reference/permissive-standards-conformance?view=vs-2019#ambiguous-conditional-operator-arguments
| Name | TFieldPtrAccessor |
| Type | class |
| Header File | /Engine/Source/Runtime/Core/Public/Misc/FieldAccessor.h |
| Include Path | #include "Misc/FieldAccessor.h" |
Syntax
template<typename T>
class TFieldPtrAccessor
Constructors
| Name | Remarks | Include Path | Unreal Specifiers |
|---|---|---|---|
TFieldPtrAccessor
(
T* InValue |
Self-owned value with initializer. | Misc/FieldAccessor.h | |
TFieldPtrAccessor
(
const TFieldPtrAccessor& Other |
Capture the value of the passed field accessor and becomes self-owned. | Misc/FieldAccessor.h | |
TFieldPtrAccessor
(
TFunction< T*()> InGet, |
Owned by another class that will control the value. Will not use the internal value. | Misc/FieldAccessor.h |
Variables
Protected
| Name | Type | Remarks | Include Path | Unreal Specifiers |
|---|---|---|---|---|
| CapturedValue | T * | This is used only when capturing the value from another TFieldPtrAccessor. | Misc/FieldAccessor.h | |
| Get | TFunction< T *()> | Misc/FieldAccessor.h | ||
| Set | TFunction< void(T *)> | Misc/FieldAccessor.h |
Functions
Public
Operators
| Name | Remarks | Include Path | Unreal Specifiers |
|---|---|---|---|
operator bool() |
Misc/FieldAccessor.h | ||
operator OtherT *() |
Misc/FieldAccessor.h | ||
operator T*() |
Misc/FieldAccessor.h | ||
bool operator!() |
Misc/FieldAccessor.h | ||
bool operator!=
(
const T* OtherPtr |
Misc/FieldAccessor.h | ||
TFieldPtrAccessor & operator=
(
const TFieldPtrAccessor& Other |
Misc/FieldAccessor.h | ||
| Misc/FieldAccessor.h | |||
TFieldPtrAccessor & operator=
(
T* OtherPtr |
Misc/FieldAccessor.h | ||
bool operator==
(
const T* OtherPtr |
Misc/FieldAccessor.h | ||
T * operator->() |
Misc/FieldAccessor.h |