UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
VersionedArchive.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3#pragma once
4
6
7// Use TVersionedReader/TVersionedWriter to create an FArchiveProxy derived class using the provided
8// Reader/Writer class that'll automatically serialize the CustomVersions that were used during serialization.
9
10template<class T>
12{
13 T Ar;
14
15 template <typename... ArgsType>
17 : Ar(Forward<ArgsType>(Args)...)
18 {
19 }
20};
21
22template<class T>
24{
25public:
26
27 template <typename... ArgsType>
28 explicit TVersionedReader(ArgsType&&... Args)
30 , FArchiveProxy(this->Ar)
31
32 {
33 FCustomVersionContainer CustomVersions;
34
35 // Serialize the offset to the CustomVersions
36 int64 VersionOffset = 0;
37 *this << VersionOffset;
38
39 // Preserve where we are so we can return and continue serializing after reading the CustomVersions
40 int64 ReturnOffset = this->Tell();
41 checkf(ReturnOffset != INDEX_NONE, TEXT("Underlying FArchive must support Seek/Tell to use TVersionnedReader"));
42
43 // Go to CustomVersions, serialize them and set them in the underlying archive
44 this->Seek(VersionOffset);
45 CustomVersions.Serialize(*this);
46 this->SetCustomVersions(CustomVersions);
47
48 // Return to where we seeked from to be able to continue serialization
49 this->Seek(ReturnOffset);
50 }
51};
52
53template<class T>
55{
56 int64 VersionOffset = 0;
57
58public:
59
60 template <typename... ArgsType>
61 explicit TVersionedWriter(ArgsType&&... Args)
63 , FArchiveProxy(this->Ar)
64 {
65 // Reserve space for version offset and remember where to write it
66 VersionOffset = this->Tell();
67 checkf(VersionOffset != INDEX_NONE, TEXT("Underlying FArchive must support Seek/Tell to use TVersionnedWriter"));
68 *this << VersionOffset;
69 }
70
72 {
73 // Acquire the current set of CustomVersions
74 FCustomVersionContainer CustomVersions;
75 CustomVersions = this->GetCustomVersions();
76
77 // Capture the offset where it'll be serialized, and then serialize the CustomVersion
78 int64 CurrentOffset = this->Tell();
79 CustomVersions.Serialize(*this);
80
81 // Go back to the initial offset and serialize the CustomVersions offset
82 this->Seek(VersionOffset);
83 *this << CurrentOffset;
84 }
85};
#define checkf(expr, format,...)
Definition AssertionMacros.h:315
@ INDEX_NONE
Definition CoreMiscDefines.h:150
#define TEXT(x)
Definition Platform.h:1272
FPlatformTypes::int64 int64
A 64-bit signed integer.
Definition Platform.h:1127
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
Definition ArchiveProxy.h:19
virtual const FCustomVersionContainer & GetCustomVersions() const override
Definition ArchiveProxy.h:204
virtual void SetCustomVersions(const FCustomVersionContainer &NewVersions) override
Definition ArchiveProxy.h:209
virtual int64 Tell() override
Definition ArchiveProxy.h:139
Definition CustomVersion.h:111
CORE_API void Serialize(FArchive &Ar, ECustomVersionSerializationFormat Format=ECustomVersionSerializationFormat::Latest)
Definition CustomVersion.cpp:315
Definition VersionedArchive.h:24
TVersionedReader(ArgsType &&... Args)
Definition VersionedArchive.h:28
Definition VersionedArchive.h:55
~TVersionedWriter()
Definition VersionedArchive.h:71
TVersionedWriter(ArgsType &&... Args)
Definition VersionedArchive.h:61
Definition VersionedArchive.h:12
TUnderlyingArchiveContainer(ArgsType &&... Args)
Definition VersionedArchive.h:16
T Ar
Definition VersionedArchive.h:13