UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
Archive.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3#pragma once
4
10
11namespace uLang
12{
13
14// Abstract archive base class, similar to UE FArchive
15// Assumes same endian on all platforms
17{
18public:
19 CArchive() = default;
20 ~CArchive() = default;
21
22 CArchive(const CArchive&) = delete;
24
25 // Whether this archive is for loading data
26 ULANG_FORCEINLINE bool IsLoading() const { return _bIsLoading; }
27
28 // The core serialization function - called for serialization of anything
29 virtual void Serialize(void* Data, int64_t NumBytes) = 0;
30
31 // Convenience operator for serializing integers and floats
32 template<class T>
33 ULANG_FORCEINLINE friend typename TEnableIf<TIsArithmetic<T>::Value, CArchive&>::Type operator<<(CArchive& Ar, T& Value) { Ar.Serialize(&Value, sizeof(Value)); return Ar; }
34
35 // Convenience operator for serializing a string
37 {
38 int32_t ByteLength = Value.ByteLen();
39 Ar << ByteLength;
40 if (Ar.IsLoading())
41 {
42 Value = CUTF8String(ByteLength, [&Ar, ByteLength](UTF8Char* Memory) { Ar.Serialize(Memory, ByteLength); });
43 }
44 else
45 {
46 Ar.Serialize((void*)Value.AsUTF8(), Value.ByteLen());
47 }
48 return Ar;
49 }
50
51 // Convenience operator for serializing an optional
52 template<class T>
54 {
55 EResult Result = Value.GetResult();
56 Ar << (int8_t&)Result;
57 if (Result == EResult::OK)
58 {
59 if (Ar.IsLoading())
60 {
61 Value.Emplace();
62 }
63 Ar << *Value;
64 }
65 return Ar;
66 }
67
68 // Convenience operator for serializing an array
69 template<class ElementType>
71 {
72 int32_t NumElements = Value.Num();
73 Ar << NumElements;
74 if (Ar.IsLoading())
75 {
76 Value.SetNum(NumElements);
77 }
78 for (ElementType& Element : Value)
79 {
80 Ar << Element;
81 }
82 return Ar;
83 }
84
85protected:
86
87 bool _bIsLoading = false;
88
89};
90
91}
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
#define ULANG_FORCEINLINE
Definition Common.h:188
Definition Archive.h:17
CArchive()=default
~CArchive()=default
ULANG_FORCEINLINE friend CArchive & operator<<(CArchive &Ar, CUTF8String &Value)
Definition Archive.h:36
CArchive(const CArchive &)=delete
ULANG_FORCEINLINE friend TEnableIf< TIsArithmetic< T >::Value, CArchive & >::Type operator<<(CArchive &Ar, T &Value)
Definition Archive.h:33
CArchive & operator=(const CArchive &ArchiveToCopy)=delete
ULANG_FORCEINLINE friend CArchive & operator<<(CArchive &Ar, TArray< ElementType > &Value)
Definition Archive.h:70
ULANG_FORCEINLINE friend CArchive & operator<<(CArchive &Ar, TOptional< T > &Value)
Definition Archive.h:53
ULANG_FORCEINLINE bool IsLoading() const
Definition Archive.h:26
bool _bIsLoading
Definition Archive.h:87
virtual void Serialize(void *Data, int64_t NumBytes)=0
Definition Array.h:51
Definition Conditionals.h:95
Definition VVMEngineEnvironment.h:23
EResult
Generic error codes.
Definition Common.h:352
@ OK
Success.
uLang::TUTF8String< CHeapRawAllocator > CUTF8String
A string allocated on the heap.
Definition UTF8String.h:269
uint8_t UTF8Char
UTF-8 octet.
Definition Unicode.h:20
Definition Optional.h:23