UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
VVMTypeInitOrValidate.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3#pragma once
4
5#if (WITH_VERSE_COMPILER && WITH_VERSE_BPVM) || WITH_VERSE_VM
6
7#include "CoreTypes.h"
11#include <type_traits>
12
13#if WITH_VERSE_VM || defined(__INTELLISENSE__)
14#include "Logging/LogMacros.h"
15
17#endif // WITH_VERSE_VM || defined(__INTELLISENSE__)
18
19namespace Verse
20{
28
29enum class EAddInterfaceType : uint8
30{
31 Direct,
33};
34
36{
38 : Field(InField)
39 , bIsValidating(bInIsValidating)
40 {
41 }
42 virtual ~FInitOrValidateUField() = default;
43
44 UField* GetField() const { return Field; }
45
46 virtual const FInitOrValidateUEnum* AsUEnum() const { return nullptr; }
47 virtual const FInitOrValidateUVerseEnum* AsUVerseEnum() const { return nullptr; }
48 virtual const FInitOrValidateUStruct* AsUStruct() const { return nullptr; }
49 virtual const FInitOrValidateUScriptStruct* AsUScriptStruct() const { return nullptr; }
50 virtual const FInitOrValidateUVerseStruct* AsUVerseStruct() const { return nullptr; }
51 virtual const FInitOrValidateUClass* AsUClass() const { return nullptr; }
52 virtual const FInitOrValidateUVerseClass* AsUVerseClass() const { return nullptr; }
53
54 bool IsValidating() const { return bIsValidating; }
55 bool IsInitializing() const { return !bIsValidating; }
56
57#if WITH_METADATA
58 COREUOBJECT_API void SetMetaData(bool bEnabled, FName MetaDataName, const TCHAR* MetaDataValue) const;
59#endif
60
61 template <typename DestinationType, typename ValueType>
62 void SetValue(DestinationType& Destination, const ValueType& Value, const TCHAR* What) const
63 {
64 if (bIsValidating)
65 {
66 CheckValueMismatch(Destination, Value, What);
67 }
68 else
69 {
70 Destination = Value;
71 }
72 }
73
74 // Set value, but skip any validation
75 template <typename DestinationType, typename ValueType>
76 void SetValueNoValidate(DestinationType& Destination, const ValueType& Value) const
77 {
78 if (!bIsValidating)
79 {
80 Destination = Value;
81 }
82 }
83
84 // Set the value regardless of validation step.
85 template <typename DestinationType, typename ValueType>
86 void ForceValue(DestinationType& Destination, const ValueType& Value) const
87 {
88 Destination = Value;
89 }
90
91protected:
92 template <typename ValueType>
93 static FString FormatValue(ValueType Value)
94 {
95 if constexpr (std::is_enum<ValueType>::value)
96 {
97 using UEnumType = std::underlying_type<ValueType>::type;
100 }
101 else if constexpr (std::is_same_v<FName, ValueType>)
102 {
103 return Value.ToString();
104 }
105 else if constexpr (std::is_same_v<FProperty, std::remove_pointer_t<ValueType>>)
106 {
107 return Value ? Value->GetFullName() : TEXT("null");
108 }
109 else if constexpr (std::is_base_of_v<UObject, std::remove_pointer_t<ValueType>>)
110 {
111 return Value ? Value->GetFullName() : TEXT("null");
112 }
113 else if constexpr (std::is_same_v<FGuid, ValueType>)
114 {
115 return LexToString(Value);
116 }
117 else if constexpr (std::is_same_v<FUtf8String, ValueType>)
118 {
119 return FString(Value);
120 }
121 else
122 {
123 return FString::Format(TEXT("{0}"), {Value}); // yeah, this is horrible
124 }
125 }
126
127 template <typename ObjectType>
128 static FString FormatValue(TObjectPtr<ObjectType> Value)
129 {
130 return FormatValue(Value.Get());
131 }
132
133 template <typename DestinationType, typename ValueType>
134 void CheckValueMismatch(const DestinationType& Destination, const ValueType& Value, const TCHAR* What, const TCHAR* SubWhat = nullptr) const
135 {
136 if (Destination != Value)
137 {
138 LogValueMismatch(Destination, Value, What, SubWhat);
139 }
140 }
141
142 template <typename DestinationType, typename ValueType>
143 void LogValueMismatch(const DestinationType& Destination, const ValueType& Value, const TCHAR* What, const TCHAR* SubWhat = nullptr) const
144 {
145 if (SubWhat != nullptr)
146 {
147 LogError(FString::Format(TEXT("'{0}:{1}:{2}' doesn't have the correct value. Expected: '{3}' Got: '{4}'"),
148 {Field->GetName(), What, SubWhat, FormatValue(Value), FormatValue(Destination)}));
149 }
150 else
151 {
152 LogError(FString::Format(TEXT("'{0}:{1}' doesn't have the correct value. Expected: '{2}' Got: '{3}'"),
153 {Field->GetName(), What, FormatValue(Value), FormatValue(Destination)}));
154 }
155 }
156
157 virtual void LogError(const FString& text) const = 0;
158
160 bool bIsValidating;
161};
162
164{
167 {
168 }
169
170 virtual const FInitOrValidateUEnum* AsUEnum() const override { return this; }
171
173
174 UEnum* GetUEnum() const { return static_cast<UEnum*>(Field.Get()); }
175};
176
178{
181 {
182 }
183
184 virtual const FInitOrValidateUVerseEnum* AsUVerseEnum() const override { return this; }
185
186 UVerseEnum* GetUVerseEnum() const { return static_cast<UVerseEnum*>(Field.Get()); }
187};
188
190{
193 {
194 }
195
196 virtual const FInitOrValidateUStruct* AsUStruct() const override { return this; }
197
198 COREUOBJECT_API void SetSuperStruct(UClass* SuperStruct) const;
199
200 UStruct* GetUStruct() const { return static_cast<UStruct*>(Field.Get()); }
201};
202
204{
207 {
208 }
209
210 virtual const FInitOrValidateUScriptStruct* AsUScriptStruct() const override { return this; }
211
212 UScriptStruct* GetUScriptStruct() const { return static_cast<UScriptStruct*>(Field.Get()); }
213};
214
216{
219 {
220 }
221
222 virtual const FInitOrValidateUVerseStruct* AsUVerseStruct() const override { return this; }
223
224 COREUOBJECT_API void SetVerseClassFlags(uint32 ClassFlags, bool bSetFlags, const TCHAR* What) const;
225 COREUOBJECT_API void ForceVerseClassFlags(uint32 ClassFlags, bool bSetFlags) const;
226
227 UVerseStruct* GetUVerseStruct() const { return static_cast<UVerseStruct*>(Field.Get()); }
228};
229
231{
234 {
235 }
236
237 virtual const FInitOrValidateUClass* AsUClass() const override { return this; }
238
239 COREUOBJECT_API void SetClassFlags(EClassFlags ClassFlags, bool bSetFlags, const TCHAR* What) const;
241
242 UClass* GetUClass() const { return static_cast<UClass*>(Field.Get()); }
243};
244
246{
249 {
250 }
251
252 virtual const FInitOrValidateUVerseClass* AsUVerseClass() const override { return this; }
253
254 COREUOBJECT_API void SetVerseClassFlags(uint32 ClassFlags, bool bSetFlags, const TCHAR* What) const;
255 COREUOBJECT_API void ForceVerseClassFlags(uint32 ClassFlags, bool bSetFlags) const;
256
257 UVerseClass* GetUVerseClass() const { return static_cast<UVerseClass*>(Field.Get()); }
258
259 COREUOBJECT_API bool AddInterface(UClass* InterfaceClass, EAddInterfaceType InterfaceType);
261
262private:
263 TArray<UClass*> Interfaces;
264 TArray<UClass*> DirectInterfaces;
265};
266
267template <typename UEType>
269{
270};
271
272template <>
274{
275 using Validator = FInitOrValidateUVerseClass;
276};
277
278template <>
280{
281 using Validator = FInitOrValidateUVerseStruct;
282};
283
284template <>
286{
287 using Validator = FInitOrValidateUVerseEnum;
288};
289
290#if WITH_VERSE_VM || defined(__INTELLISENSE__)
291namespace Private
292{
293// Wrapper class to implement the logging for the FInitOrValidate types
294template <typename UEType>
295struct FVerseVMInitOrValidate : FInitOrValidatorSelector<UEType>::Validator
296{
297 using Super = FInitOrValidatorSelector<UEType>::Validator;
299 : Super(Type, Type->IsUHTNative())
300 {
301 }
302
304 {
305 if (bGotError)
306 {
307 UE_LOG(LogVerseValidation, Fatal, TEXT("Type \"%s\" validation terminated due to mismatches with UHT type."), *Super::GetField()->GetName());
308 }
309 }
310
311 virtual void LogError(const FString& text) const override
312 {
313 UE_LOG(LogVerseValidation, Error, TEXT("Type \"%s\" %s"), *Super::GetField()->GetName(), *text);
314 bGotError = true;
315 }
316
317 mutable bool bGotError = false;
318};
319} // namespace Private
320#endif // WITH_VERSE_VM || defined(__INTELLISENSE__)
321
322} // namespace Verse
323
324#endif // (WITH_VERSE_COMPILER && WITH_VERSE_BPVM) || WITH_VERSE_VM
#define TEXT(x)
Definition Platform.h:1272
FPlatformTypes::TCHAR TCHAR
Either ANSICHAR or WIDECHAR, depending on whether the platform supports wide characters or the requir...
Definition Platform.h:1135
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
const TCHAR * LexToString(EAnalyticsRecordEventMode Mode)
Definition IAnalyticsProvider.cpp:5
#define DECLARE_LOG_CATEGORY_EXTERN(CategoryName, DefaultVerbosity, CompileTimeVerbosity)
Definition LogMacros.h:361
#define UE_LOG(CategoryName, Verbosity, Format,...)
Definition LogMacros.h:270
EClassFlags
Definition ObjectMacros.h:199
uint8_t uint8
Definition binka_ue_file_header.h:8
uint32_t uint32
Definition binka_ue_file_header.h:6
Definition NameTypes.h:617
Definition Array.h:670
Definition Class.h:3793
Definition Class.h:2791
ECppForm
Definition Class.h:2799
Definition Class.h:181
Definition Class.h:1720
Definition Class.h:480
Definition VVMVerseClass.h:137
Definition VVMVerseEnum.h:36
Definition VVMVerseStruct.h:33
IAnalyticsPropertyStore::EStatusCode SetValue(TGetter &&GetterFn, TSetter &&SetterFn, const T &ProposedValue, TCompare &&ConditionFn)
Definition AnalyticsPropertyStore.cpp:34
Type
Definition PawnAction_Move.h:11
IMAGECORE_API const TCHAR * GetName(Type Format)
Definition ImageCore.cpp:1378
Definition FieldSystemNoiseAlgo.cpp:6
Definition OverriddenPropertySet.cpp:45
Definition Archive.h:36
Definition ObjectPtr.h:488
Definition Tuple.h:652