UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
VVMNativeType.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3#pragma once
4
5#include "Templates/Casts.h"
6#include "UObject/Class.h"
7#include "UObject/Object.h"
8#if WITH_VERSE_BPVM
9#include "UObject/ObjectPtr.h"
10#endif
11#if WITH_VERSE_VM || defined(__INTELLISENSE__)
12#include "VerseVM/VVMFalse.h"
16#endif
17
18namespace Verse
19{
20class FNativeType;
21struct FNativeConverter;
22template <typename NativeType, typename>
23struct TToVValue;
24struct VType;
25} // namespace Verse
26
27template <>
28struct TIsZeroConstructType<Verse::FNativeType>
29{
30 static constexpr bool Value = true;
31};
32
33namespace Verse
34{
35
37{
39}; // So we can construct FNativeTypes
40
41#if WITH_VERSE_BPVM
42// Opaque wrapper around VM-specific type representation
43class FNativeType
44{
45public:
46 FNativeType() = delete;
47 FNativeType(EDefaultConstructNativeType) {}
48
49 FNativeType(UStruct* InType)
50 : Type(InType)
51 {
52 }
53
54 bool IsNullUnsafeDoNotUse() const { return !Type; }
55 bool IsEqualUnsafeDoNotUse(const FNativeType& Other) const { return Type == Other.Type; }
56 UStruct* AsUEStructNullableUnsafeDoNotUse() const { return Type.Get(); }
59
60protected:
62 {
63 return CastChecked<UClass>(Type);
64 }
65
66 bool IsTypeOf(UObject* Obj) const
67 {
68 if (UClass* Class = Cast<UClass>(Type))
69 {
70 return Obj->IsA(Class);
71 }
72 return false;
73 }
74
75private:
76 // This class is used via FObjectProperty, so must be a thin wrapper around this pointer.
78};
79#endif
80#if WITH_VERSE_VM || defined(__INTELLISENSE__)
81// Opaque wrapper around VM-specific type representation
82class FNativeType
83{
84public:
85 FNativeType() = delete;
86 FNativeType(EDefaultConstructNativeType) {}
87
88 FNativeType(UStruct* InType)
89 {
90 FAllocationContext Context = FAllocationContextPromise{};
91 VType* VerseType = nullptr;
92 if (!InType)
93 {
94 VerseType = &Verse::GlobalFalse();
95 }
97 {
98 VerseType = VerseClass->Class.Get();
99 }
101 {
102 VerseType = VerseStruct->Class.Get();
103 }
104 else
105 {
106 VerseType = Verse::GlobalProgram->LookupImport(Context, InType);
108 }
109
110 Type.Set(Context, VerseType);
111 }
112
113 FNativeType(VType* InType)
114 {
115 FAllocationContext Context = FAllocationContextPromise{};
116 Type.Set(Context, InType);
117 }
118
119 bool IsNullUnsafeDoNotUse() const { return !Type; }
120 bool IsEqualUnsafeDoNotUse(const FNativeType& Other) const { return Type == Other.Type; }
121
123 {
124 if (Type)
125 {
126 if (VClass* Class = Type->DynamicCast<VClass>())
127 {
128 return Class->GetUETypeChecked<UStruct>();
129 }
130 }
131 return nullptr;
132 }
133
135 {
137 }
138
140
141 bool Subsumes(FAllocationContext Context, VCell& Object) const
142 {
143 return Type->Subsumes(Context, Object);
144 }
145
146 TSharedPtr<FJsonValue> ToJSON(FRunningContext Context, EValueJSONFormat Format, TMap<const void*, EVisitState>& VisitedObjects, const VerseVMToJsonCallback& Callback, uint32 RecursionDepth, FJsonObject* Defs) const
147 {
148 return Type->ToJSON(Context, Format, VisitedObjects, Callback, RecursionDepth, Defs);
149 }
150 VValue FromJSON(FRunningContext Context, const FJsonValue& JsonValue, EValueJSONFormat Format) const
151 {
152 return Type->FromJSON(Context, JsonValue, Format);
153 }
154 bool IsSubtype(const Verse::VType& InType)
155 {
156 return InType.GetCppClassInfo()->IsA(Type->GetCppClassInfo());
157 }
158
159protected:
160 UClass* AsUEClassChecked() const
161 {
163 check(Result);
164 return Result;
165 }
166
167 bool IsTypeOf(UObject* Obj) const
168 {
170 }
171
172private:
173 friend class ::FVRestValueProperty;
174 friend struct Verse::FNativeConverter;
175 template <typename NativeType, typename>
176 friend struct Verse::TToVValue;
177
178 // This class is used via FVRestValueProperty, so must be a thin wrapper around this pointer.
180};
181#endif
182
183template <class T, class BaseType = FNativeType>
184class TNativeSubtype : public BaseType
185{
186public:
187 TNativeSubtype() = delete;
191 : BaseType(MoveTemp(Other)) { CheckValid(); }
192 TNativeSubtype(const BaseType& Other)
193 : BaseType(Other) { CheckValid(); }
195 {
196 BaseType::operator=(MoveTemp(Other));
197 CheckValid();
198 return *this;
199 }
201 {
202 BaseType::operator=(Other);
203 CheckValid();
204 return *this;
205 }
206
207 using BaseType::AsUEClassChecked;
208 using BaseType::IsTypeOf;
209
211 : BaseType(InType)
212 {
213 CheckValid();
214 }
215
216private:
217 void CheckValid() const { check(AsUEClassChecked()->IsChildOf(T::StaticClass())); }
218};
219
220// Support for castable types
221
222class FNativeCastableType : public FNativeType
223{
224public:
225 using FNativeType::FNativeType;
226 using FNativeType::IsTypeOf;
227};
228
229template <class T>
231
232// Support for concrete types
233
234class FNativeConcreteType : public FNativeType
235{
236public:
237 using FNativeType::FNativeType;
238 using FNativeType::IsTypeOf;
239};
240
241template <class T>
243
244} // namespace Verse
#define check(expr)
Definition AssertionMacros.h:314
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
UE_INTRINSIC_CAST UE_REWRITE constexpr std::remove_reference_t< T > && MoveTemp(T &&Obj) noexcept
Definition UnrealTemplate.h:520
uint32_t uint32
Definition binka_ue_file_header.h:6
Definition JsonObject.h:23
Definition JsonValue.h:22
Definition UnrealString.h.inl:34
Definition SharedPointer.h:692
Definition Class.h:3793
bool IsA(OtherClassType SomeBase) const
Definition UObjectBaseUtility.h:619
Definition Object.h:95
Definition Class.h:480
Definition VVMVerseClass.h:137
Definition VVMVerseStruct.h:33
Definition VVMNativeType.h:223
Definition VVMNativeType.h:235
Definition VVMNativeType.h:185
TNativeSubtype & operator=(BaseType &&Other)
Definition VVMNativeType.h:194
TNativeSubtype(BaseType &&Other)
Definition VVMNativeType.h:190
TNativeSubtype(const BaseType &Other)
Definition VVMNativeType.h:192
TNativeSubtype(UClass *InType)
Definition VVMNativeType.h:210
TNativeSubtype & operator=(const BaseType &Other)
Definition VVMNativeType.h:200
TNativeSubtype(EDefaultConstructNativeType)
Definition VVMNativeType.h:188
Type
Definition PawnAction_Move.h:11
UE_STRING_CLASS Result(Forward< LhsType >(Lhs), RhsLen)
Definition String.cpp.inl:732
Definition Archive.h:36
EDefaultConstructNativeType
Definition VVMNativeType.h:37
VERSECOMPILER_API bool IsSubtype(const CTypeBase *PositiveType1, const CTypeBase *PositiveType2, const uint32_t UploadedAtFnVersion)
Determine if PositiveType1 is a subtype of PositiveType2
Definition SemanticTypes.cpp:2961
bool FromJSON(const JSONValue &JSON, bool *Value)
Definition JSON.h:71
bool ToJSON(bool Value, JSONValue *JSON, JSONMemoryPoolAllocator &)
Definition JSON.h:211
Definition UnrealTypeTraits.h:172
Definition ObjectPtr.h:488
Definition VVMNativeConverter.h:153
Definition VVMNativeConverter.h:66