UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
VVMStructuredArchiveVisitor.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_VM || defined(__INTELLISENSE__)
6
7#include "CoreTypes.h"
8#include "Misc/TVariant.h"
11#include "VerseVM/VVMContext.h"
14
15namespace Verse
16{
17template <typename T>
18constexpr bool bAlwaysFalse = false;
19
21{
24 , Archive(InSlot.GetUnderlyingArchive())
26 {
27 }
28
31 , Archive(InRecord.GetUnderlyingArchive())
33 {
34 }
35
36 // Canonical visit methods.
37
38 void Visit(VCell*& Value, const TCHAR* ElementName);
39 void Visit(UObject*& Value, const TCHAR* ElementName);
40
41 void Visit(VValue& Value, const TCHAR* ElementName);
42 void Visit(VInt& Value, const TCHAR* ElementName);
43
44 void Visit(bool& Value, const TCHAR* ElementName);
45 void Visit(uint8& Value, const TCHAR* ElementName);
46 void Visit(uint16& Value, const TCHAR* ElementName);
47 void Visit(int32& Value, const TCHAR* ElementName);
48 void Visit(uint32& Value, const TCHAR* ElementName);
49 void Visit(double& Value, const TCHAR* ElementName);
50 void Visit(FUtf8String& Value, const TCHAR* ElementName);
51 void VisitBulkData(void* Data, uint64 DataSize, const TCHAR* ElementName);
52
53 // Convenience methods. These forward to the canonical methods above.
54
55 template <typename T>
56 void Visit(TWriteBarrier<T>& Value, const TCHAR* ElementName)
57 {
58 if (IsLoading())
59 {
60 if constexpr (TWriteBarrier<T>::bIsVValue)
61 {
62 T ScratchValue{};
63 Visit(ScratchValue, ElementName);
65 }
66 else if constexpr (!TWriteBarrier<T>::bIsAux)
67 {
68 VCell* ScratchValue = nullptr;
69 Visit(ScratchValue, ElementName);
70 Value.Set(Context, ScratchValue ? &ScratchValue->StaticCast<T>() : nullptr);
71 }
72 else
73 {
74 static_assert(bAlwaysFalse<T>, "Cannot serialize TAux");
75 }
76 }
77 else
78 {
79 if constexpr (TWriteBarrier<T>::bIsVValue)
80 {
81 T ScratchValue = Value.Get();
82 Visit(ScratchValue, ElementName);
83 }
84 else if constexpr (!TWriteBarrier<T>::bIsAux)
85 {
86 VCell* ScratchValue = Value.Get();
87 Visit(ScratchValue, ElementName);
88 }
89 else
90 {
91 static_assert(bAlwaysFalse<T>, "Cannot serialize TAux");
92 }
93 }
94 }
95
96 void Visit(VRestValue& Value, const TCHAR* ElementName)
97 {
98 V_DIE_UNLESS(IsLoading() || !Value.CanDefQuickly());
99 Visit(Value.Value, ElementName);
100 }
101
102 template <typename T>
103 void Visit(T& Value, const TCHAR* ElementName)
104 {
105 VisitObject(ElementName, [this, &Value] {
106 using Verse::Visit;
107 Visit(*this, Value);
108 });
109 }
110
111 template <typename T>
112 void Visit(T Begin, T End, const TCHAR* ElementName)
113 {
114 VisitArray(ElementName, [this, &Begin, &End] {
115 for (; Begin != End; ++Begin)
116 {
117 auto&& Element = *Begin;
118 Visit(Element, TEXT(""));
119 }
120 });
121 }
122
123 template <typename T>
124 void Visit(T* Values, uint64 Count, const TCHAR* ElementName)
125 {
126 Visit(Values, Values + Count, ElementName);
127 }
128
129 template <typename F>
130 void VisitObject(const TCHAR* ElementName, const F& VisitFields)
131 {
132 WithSlot(Slot(ElementName).EnterRecord(), VisitFields);
133 }
134
135 template <typename F>
136 void VisitArray(const TCHAR* ElementName, const F& VisitElements)
137 {
138 WithSlot(Slot(ElementName).EnterStream(), VisitElements);
139 }
140
141 bool IsLoading()
142 {
143 return Archive.IsLoading();
144 }
145
146 FStructuredArchiveSlot Slot(const TCHAR* ElementName);
147
148private:
149 enum class EEncodedType : uint8
150 {
151 None,
152 Cell,
154 Object,
155 Char,
156 Char32,
157 Float,
158 Int,
159
160 Count,
161 };
162
163 // Read/Write the element type description
164 static const TArray<FName, TFixedAllocator<uint32(EEncodedType::Count)>>& EncodedTypeNames();
167
168 // Read/Write a value
169 void WriteValueBody(FStructuredArchiveRecord Record, VValue InValue, bool bAllowBatch = false);
171
172 template <typename SlotType, typename F>
173 void WithSlot(SlotType Slot, const F& VisitSlot)
174 {
176 CurrentSlot.Emplace<SlotType>(Slot);
177
178 VisitSlot();
179
181 }
182
183 FAllocationContext Context;
184 FArchive& Archive;
186};
187
188} // namespace Verse
189
190#endif // 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
FPlatformTypes::int32 int32
A 32-bit signed integer.
Definition Platform.h:1125
FPlatformTypes::uint64 uint64
A 64-bit unsigned integer.
Definition Platform.h:1117
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
@ Char
Character type.
decltype(auto) Visit(Func &&Callable, Variants &&... Args)
Definition TVariant.h:271
bool IsLoading()
Definition UObjectGlobals.cpp:2087
UE_INTRINSIC_CAST UE_REWRITE constexpr std::remove_reference_t< T > && MoveTemp(T &&Obj) noexcept
Definition UnrealTemplate.h:520
uint8_t uint8
Definition binka_ue_file_header.h:8
uint16_t uint16
Definition binka_ue_file_header.h:7
uint32_t uint32
Definition binka_ue_file_header.h:6
Definition Archive.h:1208
Definition NameTypes.h:617
Definition StructuredArchiveSlots.h:144
Definition StructuredArchiveSlots.h:52
Definition Array.h:670
Definition ContainerAllocationPolicies.h:1276
Definition TVariant.h:48
Definition Object.h:95
@ Element
Definition Visu.h:18
Definition Archive.h:36
Definition TVariant.h:13