Ark Server API (ASA) - Wiki
Loading...
Searching...
No Matches
CustomVersion.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3#pragma once
4
5#include "Containers/Array.h"
6#include "Containers/Set.h"
7#include "Containers/UnrealString.h"
8#include "CoreTypes.h"
9#include "HAL/PlatformCrt.h"
10#include "Misc/Crc.h"
11#include "Misc/Guid.h"
12#include "Misc/Optional.h"
13#include "Serialization/StructuredArchive.h"
14#include "Templates/UnrealTemplate.h"
15#include "UObject/NameTypes.h"
16
17class FArchive;
19struct FCustomVersion;
20
22{
23 enum Type
24 {
25 Unknown,
26 Guids,
27 Enums,
28 Optimized,
29
30 // Add new versions above this comment
31 CustomVersion_Automatic_Plus_One,
32 Latest = CustomVersion_Automatic_Plus_One - 1
33 };
34};
35
37typedef bool (*CustomVersionValidatorFunc)(const FCustomVersion& Version, const FCustomVersionArray& AllVersions, const TCHAR* DebugContext);
38
39/**
40 * Structure to hold unique custom key with its version.
41 */
43{
45
46 /** Unique custom key. */
48
49 /** Custom version. */
50 int32 Version;
51
52 /** Number of times this GUID has been registered */
54
55 /** An optional validator that will be called if a package has a given version that can prevent it from loading */
57
58 /** Constructor. */
60 : Validator(nullptr)
61 {
62 }
63
64 /** Helper constructor. */
65 FORCEINLINE FCustomVersion(FGuid InKey, int32 InVersion, FName InFriendlyName, CustomVersionValidatorFunc InValidatorFunc = nullptr)
66 : Key (InKey)
67 , Version (InVersion)
69 , Validator (InValidatorFunc)
70 , FriendlyName (InFriendlyName)
71 {
72 }
73
74 /** Equality comparison operator for Key */
75 FORCEINLINE bool operator==(FGuid InKey) const
76 {
77 return Key == InKey;
78 }
79
80 /** Inequality comparison operator for Key */
81 FORCEINLINE bool operator!=(FGuid InKey) const
82 {
83 return Key != InKey;
84 }
85
86 friend FArchive& operator<<(FArchive& Ar, FCustomVersion& Version);
87 friend void operator<<(FStructuredArchive::FSlot Slot, FCustomVersion& Version);
88
89 /** Gets the friendly name for error messages or whatever */
90 const FName GetFriendlyName() const;
91
92private:
93
94 /** Friendly name for error messages or whatever. Lazy initialized for serialized versions */
96};
97
99
100/**
101 * Container for all available/serialized custom versions.
102 */
104{
105 friend struct FStaticCustomVersionRegistry;
106
107public:
108 /** Gets available custom versions in this container. */
110 {
111 return Versions;
112 }
113
114 /**
115 * Gets a custom version from the container.
116 *
117 * @param CustomKey Custom key for which to retrieve the version.
118 * @return The FCustomVersion for the specified custom key, or nullptr if the key doesn't exist in the container.
119 */
120 const FCustomVersion* GetVersion(FGuid CustomKey) const;
121
122 /**
123 * Gets a custom version friendly name from the container.
124 *
125 * @param CustomKey Custom key for which to retrieve the version.
126 * @return The friendly name for the specified custom key, or NAME_None if the key doesn't exist in the container.
127 */
128 const FName GetFriendlyName(FGuid CustomKey) const;
129
130 /**
131 * Sets a specific custom version in the container.
132 *
133 * @param CustomKey Custom key for which to retrieve the version.
134 * @param Version The version number for the specified custom key
135 * @param FriendlyName A friendly name to assign to this version
136 */
137 void SetVersion(FGuid CustomKey, int32 Version, FName FriendlyName);
138
139 /** Serialization. */
142
143 /**
144 * Gets a singleton with the registered versions.
145 *
146 * @return The registered version container.
147 */
148 UE_DEPRECATED(4.24, "Use one of the thread-safe FCurrentCustomVersions methods instead")
150
151 /**
152 * Empties the custom version container.
153 */
154 void Empty();
155
156 /**
157 * Sorts the custom version container by key.
158 */
159 void SortByKey();
160
161 /** Return a string representation of custom versions. Used for debug. */
162 FString ToString(const FString& Indent) const;
163
164private:
165
166 /** Array containing custom versions. */
168
169};
170
172
174{
177};
178
179/** Provides access to code-defined custom versions registered via FCustomVersionRegistration. */
181{
182public:
183 /** Get a copy of all versions that has been statically registered so far in the module loading process. */
185
186 /** Get a copy of a single statically registered version if it exists. */
187 static TOptional<FCustomVersion> Get(const FGuid& Guid);
188
189 /** Compare a number of versions to current ones and return potential differences. */
191
192private:
194
195 static void Register(const FGuid& Key, int32 Version, const TCHAR* FriendlyName, CustomVersionValidatorFunc ValidatorFunc);
196 static void Unregister(const FGuid& Key);
197};
198
199
200/**
201 * This class will cause the registration of a custom version number and key with the global
202 * FCustomVersionContainer when instantiated, and unregister when destroyed. It should be
203 * instantiated as a global variable somewhere in the module which needs a custom version number.
204 */
206{
207public:
208 /** @param InFriendlyName must be a string literal */
209 template<int N>
210 FCustomVersionRegistration(FGuid InKey, int32 Version, const TCHAR(&InFriendlyName)[N], CustomVersionValidatorFunc InValidatorFunc = nullptr)
211 : Key(InKey)
212 {
214 }
215
217 {
219 }
220
221private:
223};
#define UE_DEPRECATED(Version, Message)
bool(* CustomVersionValidatorFunc)(const FCustomVersion &Version, const FCustomVersionArray &AllVersions, const TCHAR *DebugContext)
TArray< FCustomVersion > FCustomVersionArray
ECustomVersionDifference
Definition Enums.h:20447
#define FORCEINLINE
Definition Platform.h:644
static void Register(const FGuid &Key, int32 Version, const TCHAR *FriendlyName, CustomVersionValidatorFunc ValidatorFunc)
static TOptional< FCustomVersion > Get(const FGuid &Guid)
static void Unregister(const FGuid &Key)
static FCustomVersionContainer GetAll()
static TArray< FCustomVersionDifference > Compare(const FCustomVersionArray &CompareVersions, const TCHAR *DebugContext)
FCustomVersionArray Versions
static const FCustomVersionContainer & GetRegistered()
FString ToString(const FString &Indent) const
const FCustomVersion * GetVersion(FGuid CustomKey) const
const FName GetFriendlyName(FGuid CustomKey) const
FORCEINLINE const FCustomVersionArray & GetAllVersions() const
void Serialize(FStructuredArchive::FSlot Slot, ECustomVersionSerializationFormat::Type Format=ECustomVersionSerializationFormat::Latest)
void Serialize(FArchive &Ar, ECustomVersionSerializationFormat::Type Format=ECustomVersionSerializationFormat::Latest)
void SetVersion(FGuid CustomKey, int32 Version, FName FriendlyName)
FCustomVersionRegistration(FGuid InKey, int32 Version, const TCHAR(&InFriendlyName)[N], CustomVersionValidatorFunc InValidatorFunc=nullptr)
ECustomVersionDifference Type
const FCustomVersion * Version
const FName GetFriendlyName() const
FORCEINLINE FCustomVersion()
CustomVersionValidatorFunc Validator
FORCEINLINE bool operator!=(FGuid InKey) const
friend void operator<<(FStructuredArchive::FSlot Slot, FCustomVersion &Version)
FORCEINLINE bool operator==(FGuid InKey) const
FORCEINLINE FCustomVersion(FGuid InKey, int32 InVersion, FName InFriendlyName, CustomVersionValidatorFunc InValidatorFunc=nullptr)
Definition Guid.h:108
friend bool operator==(const FGuid &X, const FGuid &Y)
Definition Guid.h:148
friend bool operator!=(const FGuid &X, const FGuid &Y)
Definition Guid.h:160