UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
VVMPersistence.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2#pragma once
3
7#include "VerseVM/VVMValue.h"
8
9class FJsonValue;
10class FJsonObject;
11
12namespace Verse
13{
15
16template <typename TShortName>
17FString ShortNameToFieldName(TShortName&& ShortName)
18{
19 return "x_" + FString{::Forward<TShortName>(ShortName)};
20}
21
22template <typename TArg>
24{
26 // Remove everything up to and including the 'x' of "__verse_0x".
27 if (!PropertyName.FindChar('x', Index))
28 {
29 return {};
30 }
31 PropertyName.RightChopInline(Index + 1);
32 // Remove the hash followed by '_' that follows "__verse_0x".
33 if (!PropertyName.FindChar('_', Index))
34 {
35 return {};
36 }
37 return PropertyName.RightChop(Index + 1);
38}
39
40struct VPersistentMap;
41
43{
44 // Verse path of the update persistent `var` `weak_map`
45 FString Path;
46 // Key of the updated value in the map.
47 void* Key;
48 // Updated value in the map.
50
51#if WITH_VERSE_BPVM
52 // `FProperty` of the related persistent `var` `weak_map`
54 // Updated value in the map. The structure of the value can be found in
55 // `MapProperty->ValueProp`.
56 void* RawValue;
57#else
58 VValue RawValue;
59#endif
60};
61
62// Represents an update to a persistent `var` `weak_map`. A range of
63// `FUpdatedPair`s is broadcast by `Updated`.
65{
66 // Verse path of the update persistent `var` `weak_map`
67 FString Path;
68#if WITH_VERSE_BPVM
69 // `FProperty` of the related persistent `var` `weak_map`
71 // Key of the updated value in the map.
72 void* Key;
73 // Updated value in the map. The structure of the value can be found in
74 // `MapProperty->ValueProp`.
75 void* Value;
76#else
77 // Key of the updated value in the map.
78 VValue Key;
79 // Updated value in the map.
80 VValue Value;
81#endif
82
83#if WITH_VERSE_BPVM
84 FUpdatedPersistentPairVM(FString Path, const FMapProperty* MapProperty, void* Key, void* Value)
85 : Path(::MoveTemp(Path))
87 , Key(Key)
88 , Value(Value)
89 {
90 }
91#else
92 FUpdatedPersistentPairVM(FString Path, VValue Key, VValue Value)
93 : Path(::MoveTemp(Path))
94 , Key(Key)
95 , Value(Value)
96 {
97 }
98#endif
99
101 {
102#if WITH_VERSE_BPVM
103 return Left.Key == Right.Key && FCString::Strcmp(*Left.Path, *Right.Path) == 0;
104#else
105 return Left.Key.GetEncodedBits() == Right.Key.GetEncodedBits() && FCString::Strcmp(*Left.Path, *Right.Path) == 0;
106#endif
107 }
108
110 {
111 return FCrc::StrCrc32(*Arg.Path);
112 }
113
115 {
116#if WITH_VERSE_BPVM
117 if (Left.Key < Right.Key)
118#else
119 if (Left.Key.GetEncodedBits() < Right.Key.GetEncodedBits())
120#endif
121 {
122 return true;
123 }
124#if WITH_VERSE_BPVM
125 if (Right.Key < Left.Key)
126#else
127 if (Right.Key.GetEncodedBits() < Left.Key.GetEncodedBits())
128#endif
129 {
130 return false;
131 }
132 return FCString::Strcmp(*Left.Path, *Right.Path) < 0;
133 }
134};
135
137{
138protected:
139 virtual ~IVersePersistence() = default;
140
141public:
143#if WITH_VERSE_BPVM
144 using TPersistablePredicateVM = TFunction<bool(const FProperty*, void*)>;
145#else
147#endif
148
153
158
159#if WITH_VERSE_BPVM
163 virtual void AddPersistentMap(const FString& Path, const FMapProperty*, UObject* Container) = 0;
164#else
168 virtual void AddPersistentMap(const FString& Path, VPersistentMap& Map) = 0;
169#endif
170
175
181
184
187
195
203
207 virtual void AddPersistentPair(const FString& Path, const void* Key, const TSharedRef<const FJsonValue>& Value) = 0;
208
209#if WITH_VERSE_BPVM
213 virtual void AddPersistentPair(const FString& Path, const void* Key, const void* Data) = 0;
214#else
218 virtual void AddPersistentPair(const FString& Path, const void* Key, VValue Value) = 0;
219#endif
220
224 virtual void RemovePersistentPairs(const void* Key) = 0;
225
232 virtual void ResetWeakMaps() = 0;
233};
234} // namespace Verse
FPlatformTypes::int32 int32
A 32-bit signed integer.
Definition Platform.h:1125
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
const bool
Definition NetworkReplayStreaming.h:178
UE_INTRINSIC_CAST UE_REWRITE constexpr std::remove_reference_t< T > && MoveTemp(T &&Obj) noexcept
Definition UnrealTemplate.h:520
uint32_t uint32
Definition binka_ue_file_header.h:6
Definition JsonObject.h:23
Definition JsonValue.h:22
Definition UnrealType.h:3843
Definition UnrealType.h:174
Definition Array.h:670
Definition AndroidPlatformMisc.h:14
Definition SharedPointer.h:692
Definition SharedPointer.h:153
Definition Object.h:95
Definition VVMPersistence.h:137
DECLARE_EVENT_OneParam(IVersePersistence, FOnPersistentMapKeyRemoved, void *)
DECLARE_EVENT_OneParam(IVersePersistence, FOnPersistentMapKeyAdded, void *)
virtual void RemovePersistentPairs(const void *Key)=0
virtual void AddPersistentPair(const FString &Path, const void *Key, VValue Value)=0
virtual FOnPersistentMapKeyRemoved & OnPersistentMapKeyRemoved()=0
virtual FOnPersistentMapConstructed & OnPersistentMapConstructed()=0
virtual void AddPersistentMap(const FString &Path, VPersistentMap &Map)=0
virtual void ResetWeakMaps()=0
virtual FOnPersistentMapsReleased & OnPersistentMapsReleased()=0
virtual FOnPersistentPairsUpdated & OnPersistentPairsUpdated()=0
virtual void UpdatePersistentPairs(const FUpdatedPersistentPairVM *, const FUpdatedPersistentPairVM *)=0
virtual void AddPersistentPair(const FString &Path, const void *Key, const TSharedRef< const FJsonValue > &Value)=0
DECLARE_EVENT(IVersePersistence, FOnPersistentMapsReleased)
virtual void SetPersistablePredicate(TPersistablePredicateSave)=0
virtual FOnPersistentMapKeyAdded & OnPersistentMapKeyAdded()=0
DECLARE_EVENT_OneParam(IVersePersistence, FOnPersistentPairsUpdated, const TArray< FUpdatedPersistentPairSave > &)
virtual const TPersistablePredicateVM GetPersistablePredicate() const =0
virtual ~IVersePersistence()=default
DECLARE_EVENT_OneParam(IVersePersistence, FOnPersistentMapConstructed, const FString &Path)
Definition Archive.h:36
FString ShortNameToFieldName(TShortName &&ShortName)
Definition VVMPersistence.h:17
TOptional< TArg > NameToShortName(TArg PropertyName)
Definition VVMPersistence.h:23
TOptional< TMap< FString, TSharedPtr< FJsonValue > > > MapFromPersistentJson(const FJsonObject &JsonObject)
Definition VVMPersistence.cpp:9
U16 Index
Definition radfft.cpp:71
static uint32 StrCrc32(const CharType *Data, uint32 CRC=0)
Definition Crc.h:45
static UE_FORCEINLINE_HINT int32 Strcmp(const CharType *String1, const CharType *String2)
Definition CString.h:1018
Definition Optional.h:131
Definition VVMPersistence.h:43
void * Key
Definition VVMPersistence.h:47
FString Path
Definition VVMPersistence.h:45
TSharedPtr< FJsonValue > Value
Definition VVMPersistence.h:49
VValue RawValue
Definition VVMPersistence.h:58
Definition VVMPersistence.h:65
friend bool operator<(const FUpdatedPersistentPairVM &Left, const FUpdatedPersistentPairVM &Right)
Definition VVMPersistence.h:114
FUpdatedPersistentPairVM(FString Path, VValue Key, VValue Value)
Definition VVMPersistence.h:92
VValue Key
Definition VVMPersistence.h:78
friend uint32 GetTypeHash(const FUpdatedPersistentPairVM &Arg)
Definition VVMPersistence.h:109
friend bool operator==(const FUpdatedPersistentPairVM &Left, const FUpdatedPersistentPairVM &Right)
Definition VVMPersistence.h:100
FString Path
Definition VVMPersistence.h:67
VValue Value
Definition VVMPersistence.h:80