UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
StructView.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3#pragma once
4
7#include "StructUtils.h"
8#include <type_traits>
9
11
24{
25public:
26
27 FStructView() = default;
28
30 : ScriptStruct(InScriptStruct)
31 , StructMemory(InStructMemory)
32 {}
33
34 FStructView(FInstancedStruct& InstancedStruct)
35 : FStructView(InstancedStruct.GetScriptStruct(), InstancedStruct.GetMutableMemory())
36 {}
37
38 FStructView(const FSharedStruct& SharedStruct)
39 : FStructView(SharedStruct.GetScriptStruct(), SharedStruct.GetMemory())
40 {}
41
43 template<typename T>
45 {
46 UE::StructUtils::CheckStructType<T>();
47 return FStructView(TBaseStructure<T>::Get(), reinterpret_cast<uint8*>(&InStruct));
48 }
49
51 template<typename T>
52 T& Get() const
53 {
54 return UE::StructUtils::GetStructRef<T>(ScriptStruct, StructMemory);
55 }
56
58 template<typename T>
59 T* GetPtr() const
60 {
61 return UE::StructUtils::GetStructPtr<T>(ScriptStruct, StructMemory);
62 }
63
66 {
67 return ScriptStruct;
68 }
69
72 {
73 return StructMemory;
74 }
75
77 void Reset()
78 {
79 StructMemory = nullptr;
80 ScriptStruct = nullptr;
81 }
82
84 bool IsValid() const
85 {
86 return StructMemory != nullptr && ScriptStruct != nullptr;
87 }
88
90 template <typename OtherType>
91 bool operator==(const OtherType& Other) const
92 {
93 return ((ScriptStruct == Other.GetScriptStruct()) && (StructMemory == Other.GetMemory()));
94 }
95
96 template <typename OtherType>
97 bool operator!=(const OtherType& Other) const
98 {
99 return !operator==(Other);
100 }
101
102protected:
103 const UScriptStruct* ScriptStruct = nullptr;
104 uint8* StructMemory = nullptr;
105};
106
116template<typename BaseStructT>
118{
119public:
120
121 explicit TStructView() = default;
122
123 template<typename T = BaseStructT>
124 requires (std::is_base_of_v<BaseStructT, std::decay_t<T>>)
126 : FStructView(T::StaticStruct(), reinterpret_cast<uint8*>(&InStruct))
127 {
128 }
129
130 template<typename T = BaseStructT>
131 requires (std::is_base_of_v<BaseStructT, std::decay_t<T>>)
132 explicit TStructView(uint8* InStructMemory = nullptr)
133 : FStructView(T::StaticStruct(), InStructMemory)
134 {
135 }
136
137 template<typename T = BaseStructT>
138 requires (std::is_base_of_v<BaseStructT, std::decay_t<T>>)
141 {
142 checkf(!InScriptStruct || InScriptStruct->IsChildOf(TBaseStructure<T>::Get()), TEXT("Struct type must be a child of T!"));
143 }
144
145 template<typename T = BaseStructT>
146 requires (std::is_base_of_v<BaseStructT, std::decay_t<T>>)
148 : FStructView(InstancedStruct.GetScriptStruct(), InstancedStruct.GetMutableMemory())
149 {
150 }
151
152 template<typename T = BaseStructT>
153 requires (std::is_base_of_v<BaseStructT, std::decay_t<T>>)
154 TStructView(const TSharedStruct<T>& SharedStruct)
155 : FStructView(SharedStruct.GetScriptStruct(), SharedStruct.GetMemory())
156 {
157 }
158
160 template<typename T = BaseStructT>
161 requires (std::is_base_of_v<BaseStructT, std::decay_t<T>>)
162 T& Get() const
163 {
164 return UE::StructUtils::GetStructRef<T>(ScriptStruct, StructMemory);
165 }
166
168 template<typename T = BaseStructT>
169 requires (std::is_base_of_v<BaseStructT, std::decay_t<T>>)
170 T* GetPtr() const
171 {
172 return UE::StructUtils::GetStructPtr<T, BaseStructT>(ScriptStruct, StructMemory);
173 }
174
177 {
178 check(IsValid());
179 return GetPtr();
180 }
181
183 template<typename T = BaseStructT>
184 requires (std::is_base_of_v<BaseStructT, std::decay_t<T>>)
185 bool operator==(const TStructView<T>& Other) const
186 {
187 return ((ScriptStruct == Other.GetScriptStruct()) && (StructMemory == Other.GetMemory()));
188 }
189
190 template<typename T = BaseStructT>
191 requires (std::is_base_of_v<BaseStructT, std::decay_t<T>>)
192 bool operator!=(const TStructView<T>& Other) const
193 {
194 return !operator==(Other);
195 }
196};
197
199
217{
218public:
219
220 FConstStructView() = default;
221
223 : ScriptStruct(InScriptStruct)
224 , StructMemory(InStructMemory)
225 {}
226
227 FConstStructView(const FInstancedStruct& InstancedStruct)
228 : FConstStructView(InstancedStruct.GetScriptStruct(), InstancedStruct.GetMemory())
229 {}
230
231 FConstStructView(const FSharedStruct& SharedStruct)
232 : FConstStructView(SharedStruct.GetScriptStruct(), SharedStruct.GetMemory())
233 {}
234
236 : FConstStructView(SharedStruct.GetScriptStruct(), SharedStruct.GetMemory())
237 {}
238
240 : FConstStructView(StructView.GetScriptStruct(), StructView.GetMemory())
241
242 {}
243
245 template<typename T>
246 static FConstStructView Make(const T& Struct)
247 {
248 UE::StructUtils::CheckStructType<T>();
249 return FConstStructView(TBaseStructure<T>::Get(), reinterpret_cast<const uint8*>(&Struct));
250 }
251
253 template<typename T>
254 requires (std::is_const_v<T>)
255 constexpr T& Get() const
256 {
257 return UE::StructUtils::GetStructRef<T>(ScriptStruct, StructMemory);
258 }
259
261 template<typename T>
262 requires (std::is_const_v<T>)
263 constexpr T* GetPtr() const
264 {
265 return UE::StructUtils::GetStructPtr<T>(ScriptStruct, StructMemory);
266 }
267
270 {
271 return ScriptStruct;
272 }
273
275 const uint8* GetMemory() const
276 {
277 return StructMemory;
278 }
279
281 void Reset()
282 {
283 StructMemory = nullptr;
284 ScriptStruct = nullptr;
285 }
286
288 bool IsValid() const
289 {
290 return StructMemory != nullptr && ScriptStruct != nullptr;
291 }
292
294 template <typename OtherType>
295 bool operator==(const OtherType& Other) const
296 {
297 return ((ScriptStruct == Other.GetScriptStruct()) && (StructMemory == Other.GetMemory()));
298 }
299
300 template <typename OtherType>
301 bool operator!=(const OtherType& Other) const
302 {
303 return !operator==(Other);
304 }
305
307 {
308 ScriptStruct = InScriptStruct;
309 StructMemory = InStructMemory;
310 }
311
312protected:
313 const UScriptStruct* ScriptStruct = nullptr;
314 const uint8* StructMemory = nullptr;
315};
316
326template<typename BaseStructT>
328{
329 explicit TConstStructView() = default;
330
331 template<typename T = BaseStructT>
332 requires (std::is_base_of_v<BaseStructT, std::decay_t<T>>)
334 : FConstStructView(T::StaticStruct(), reinterpret_cast<const uint8*>(&InStruct))
335 {
336 }
337
338 template<typename T = BaseStructT>
339 requires (std::is_base_of_v<BaseStructT, std::decay_t<T>>)
340 explicit TConstStructView(const uint8* InStructMemory = nullptr)
341 : FConstStructView(T::StaticStruct(), InStructMemory)
342 {
343 }
344
345 template<typename T = BaseStructT>
346 requires (std::is_base_of_v<BaseStructT, std::decay_t<T>>)
347 TConstStructView(const TInstancedStruct<T>& InstancedStruct)
348 : FConstStructView(InstancedStruct.GetScriptStruct(), InstancedStruct.GetMemory())
349 {
350 }
351
352 template<typename T = BaseStructT>
353 requires (std::is_base_of_v<BaseStructT, std::decay_t<T>>)
355 : FConstStructView(SharedStruct.GetScriptStruct(), SharedStruct.GetMemory())
356 {
357 }
358
359 template<typename T = BaseStructT>
360 requires (std::is_base_of_v<BaseStructT, std::decay_t<T>>)
362 : FConstStructView(SharedStruct.GetScriptStruct(), SharedStruct.GetMemory())
363 {
364 }
365
366 template<typename T = BaseStructT>
367 requires (std::is_base_of_v<BaseStructT, std::decay_t<T>>)
369 : FConstStructView(StructView.GetScriptStruct(), StructView.GetMemory())
370 {
371 }
372
374 template<typename T = BaseStructT>
375 requires (std::is_base_of_v<BaseStructT, std::decay_t<T>>)
376 constexpr const T& Get() const
377 {
378 return UE::StructUtils::GetStructRef<T>(ScriptStruct, StructMemory);
379 }
380
382 template<typename T = BaseStructT>
383 requires (std::is_base_of_v<BaseStructT, std::decay_t<T>>)
384 constexpr const T* GetPtr() const
385 {
386 return UE::StructUtils::GetStructPtr<T, BaseStructT>(ScriptStruct, StructMemory);
387 }
388
391 {
392 check(IsValid());
393 return GetPtr();
394 }
395
397 template<typename T = BaseStructT>
398 requires (std::is_base_of_v<BaseStructT, std::decay_t<T>>)
399 bool operator==(const TConstStructView<T>& Other) const
400 {
401 return ((ScriptStruct == Other.GetScriptStruct()) && (StructMemory == Other.GetMemory()));
402 }
403
404 template<typename T = BaseStructT>
405 requires (std::is_base_of_v<BaseStructT, std::decay_t<T>>)
406 bool operator!=(const TConstStructView<T>& Other) const
407 {
408 return !operator==(Other);
409 }
410};
#define check(expr)
Definition AssertionMacros.h:314
#define checkf(expr, format,...)
Definition AssertionMacros.h:315
#define TEXT(x)
Definition Platform.h:1272
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
UE_FORCEINLINE_HINT uint32 GetPtr() const
Definition LockFreeList.h:15
uint8_t uint8
Definition binka_ue_file_header.h:8
Definition Class.h:1720
Definition SharedStruct.h:538
Definition StructView.h:217
void Reset()
Definition StructView.h:281
bool IsValid() const
Definition StructView.h:288
bool operator==(const OtherType &Other) const
Definition StructView.h:295
const UScriptStruct * GetScriptStruct() const
Definition StructView.h:269
FConstStructView(const FConstSharedStruct &SharedStruct)
Definition StructView.h:235
FConstStructView(const FSharedStruct &SharedStruct)
Definition StructView.h:231
FConstStructView(const FInstancedStruct &InstancedStruct)
Definition StructView.h:227
const uint8 * GetMemory() const
Definition StructView.h:275
void SetStructData(const UScriptStruct *InScriptStruct, const uint8 *InStructMemory)
Definition StructView.h:306
FConstStructView(const FStructView StructView)
Definition StructView.h:239
constexpr T * GetPtr() const
Definition StructView.h:263
bool operator!=(const OtherType &Other) const
Definition StructView.h:301
constexpr T & Get() const
Definition StructView.h:255
FConstStructView(const UScriptStruct *InScriptStruct, const uint8 *InStructMemory=nullptr)
Definition StructView.h:222
static FConstStructView Make(const T &Struct)
Definition StructView.h:246
FConstStructView()=default
Definition InstancedStruct.h:32
Definition SharedStruct.h:161
Definition StructView.h:24
FStructView()=default
FStructView(const FSharedStruct &SharedStruct)
Definition StructView.h:38
FStructView(FInstancedStruct &InstancedStruct)
Definition StructView.h:34
bool operator==(const OtherType &Other) const
Definition StructView.h:91
const UScriptStruct * GetScriptStruct() const
Definition StructView.h:65
void Reset()
Definition StructView.h:77
T * GetPtr() const
Definition StructView.h:59
T & Get() const
Definition StructView.h:52
uint8 * GetMemory() const
Definition StructView.h:71
static FStructView Make(T &InStruct)
Definition StructView.h:44
bool operator!=(const OtherType &Other) const
Definition StructView.h:97
FStructView(const UScriptStruct *InScriptStruct, uint8 *InStructMemory=nullptr)
Definition StructView.h:29
bool IsValid() const
Definition StructView.h:84
Definition Class.h:5288
Definition SharedStruct.h:740
const uint8 * GetMemory() const
Definition SharedStruct.h:794
Definition StructView.h:328
TConstStructView(const uint8 *InStructMemory=nullptr)
Definition StructView.h:340
TConstStructView(const TStructView< T > StructView)
Definition StructView.h:368
TConstStructView(const TConstSharedStruct< T > &SharedStruct)
Definition StructView.h:361
constexpr const T & Get() const
Definition StructView.h:376
BaseStructT * operator->() const
Definition StructView.h:390
constexpr const T * GetPtr() const
Definition StructView.h:384
TConstStructView(const T &InStruct)
Definition StructView.h:333
TConstStructView(const TInstancedStruct< T > &InstancedStruct)
Definition StructView.h:347
TConstStructView()=default
TConstStructView(const TSharedStruct< T > &SharedStruct)
Definition StructView.h:354
Definition InstancedStruct.h:307
const uint8 * GetMemory() const
Definition InstancedStruct.h:411
uint8 * GetMutableMemory()
Definition InstancedStruct.h:437
const UScriptStruct * GetScriptStruct() const
Definition InstancedStruct.h:405
Definition SharedStruct.h:349
const UScriptStruct * GetScriptStruct() const
Definition SharedStruct.h:391
uint8 * GetMemory() const
Definition SharedStruct.h:402
Definition StructView.h:118
BaseStructT * operator->() const
Definition StructView.h:176
TStructView(const TSharedStruct< T > &SharedStruct)
Definition StructView.h:154
TStructView(TInstancedStruct< T > &InstancedStruct)
Definition StructView.h:147
TStructView(const UScriptStruct *InScriptStruct, uint8 *InStructMemory=nullptr)
Definition StructView.h:139
TStructView(uint8 *InStructMemory=nullptr)
Definition StructView.h:132
TStructView(T &InStruct)
Definition StructView.h:125
T * GetPtr() const
Definition StructView.h:170
T & Get() const
Definition StructView.h:162
TStructView()=default