UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
KeyHandle.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3#pragma once
4
5#include "CoreMinimal.h"
8#include "UObject/Class.h"
9#include "KeyHandle.generated.h"
10
15{
17
19
20 ENGINE_API bool IsValid() const;
21
22 operator bool() const { return IsValid(); }
23
24 bool operator ==(const FKeyHandle& Other) const
25 {
26 return Index == Other.Index;
27 }
28
29 bool operator !=(const FKeyHandle& Other) const
30 {
31 return Index != Other.Index;
32 }
33
35 {
36 return A.Index < B.Index;
37 }
38
40 {
41 return A.Index > B.Index;
42 }
43
45 {
46 return GetTypeHash(Handle.Index);
47 }
48
50 {
51 Ar << Handle.Index;
52 return Ar;
53 }
54
55private:
56
59
61};
62
63
67USTRUCT()
69{
71public:
73
74 // This struct is not copyable. This must be public or because derived classes are allowed to be copied
77
78 // Quickly initializes this map by clearing it and filling with KeyHandles in O(n) time, instead of O(n^2) if Add() was used in a loop.
80
82 void Add( const FKeyHandle& InHandle, int32 InIndex );
84 void Remove( const FKeyHandle& InHandle );
85 void Reserve(int32 NumElements);
86 const int32* Find(const FKeyHandle& InHandle) const { return KeyHandlesToIndices.Find(InHandle); }
87 const FKeyHandle* FindKey( int32 KeyIndex ) const;
88 int32 Num() const { return KeyHandlesToIndices.Num(); }
90 const TMap<FKeyHandle, int32>& GetMap() const { return KeyHandlesToIndices; }
91
92 void SetKeyHandles(int32 Num);
93
95 bool Serialize(FArchive& Ar);
96 bool operator==(const FKeyHandleMap& Other) const { return KeyHandles == Other.KeyHandles; }
97 bool operator!=(const FKeyHandleMap& Other) const { return !(*this==Other); }
98
100 {
101 P.Serialize(Ar);
102 return Ar;
103 }
104
105 // Ensures that all indices have a valid handle and that there are no handles left to invalid indices
106 void EnsureAllIndicesHaveHandles(int32 NumIndices);
107
108 // Ensures a handle exists for the specified Index
109 void EnsureIndexHasAHandle(int32 KeyIndex);
110
111private:
112
113 TMap<FKeyHandle, int32> KeyHandlesToIndices;
114 TArray<FKeyHandle> KeyHandles;
115};
116
117
118template<>
130
136USTRUCT()
138{
140public:
147 ENGINE_API int32 GetIndex(FKeyHandle KeyHandle);
148
155 ENGINE_API FKeyHandle FindOrAddKeyHandle(int32 Index);
156
163 ENGINE_API void MoveHandle(int32 OldIndex, int32 NewIndex);
164
171 ENGINE_API FKeyHandle AllocateHandle(int32 Index);
172
178 ENGINE_API void DeallocateHandle(int32 Index);
179
186 ENGINE_API void ReplaceHandle(int32 Index, FKeyHandle HandleToReplace);
187
191 ENGINE_API void Reset();
192
194 ENGINE_API bool Serialize(FArchive& Ar);
196 {
197 P.Serialize(Ar);
198 return Ar;
199 }
200
201private:
202
204 void RelocateKeyHandles(int32 StartAtIndex, int32 DeltaIndex);
205
206private:
208 TSparseArray<FKeyHandle> KeyHandles;
209
211 TMap<FKeyHandle, int32> KeyHandlesToIndices;
212
213};
214
215template<>
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
@ Num
Definition MetalRHIPrivate.h:234
const bool
Definition NetworkReplayStreaming.h:178
#define GENERATED_BODY(...)
Definition ObjectMacros.h:765
#define USTRUCT(...)
Definition ObjectMacros.h:746
EPropertyObjectReferenceType
Definition ObjectMacros.h:533
#define GENERATED_USTRUCT_BODY(...)
Definition ObjectMacros.h:767
uint32_t uint32
Definition binka_ue_file_header.h:6
Definition Archive.h:1208
Definition ArrayView.h:139
Definition Array.h:670
UE_NODEBUG TConstIterator CreateConstIterator() const
Definition Array.h:3365
Definition Array.h:64
Definition UnrealString.h.inl:34
Definition SparseArray.h:524
U16 Index
Definition radfft.cpp:71
Definition KeyHandle.h:138
friend FArchive & operator<<(FArchive &Ar, FKeyHandleLookupTable &P)
Definition KeyHandle.h:195
Definition KeyHandle.h:69
const TMap< FKeyHandle, int32 > & GetMap() const
Definition KeyHandle.h:90
friend FArchive & operator<<(FArchive &Ar, FKeyHandleMap &P)
Definition KeyHandle.h:99
bool operator!=(const FKeyHandleMap &Other) const
Definition KeyHandle.h:97
FKeyHandleMap(const FKeyHandleMap &Other)
Definition KeyHandle.h:75
void operator=(const FKeyHandleMap &Other)
Definition KeyHandle.h:76
int32 Num() const
Definition KeyHandle.h:88
const int32 * Find(const FKeyHandle &InHandle) const
Definition KeyHandle.h:86
bool operator==(const FKeyHandleMap &Other) const
Definition KeyHandle.h:96
TArray< FKeyHandle >::TConstIterator CreateConstIterator() const
Definition KeyHandle.h:89
FKeyHandleMap()
Definition KeyHandle.h:72
Definition KeyHandle.h:15
bool operator!=(const FKeyHandle &Other) const
Definition KeyHandle.h:29
friend bool operator>(FKeyHandle A, FKeyHandle B)
Definition KeyHandle.h:39
static ENGINE_API FKeyHandle Invalid()
Definition KeyHandle.cpp:37
ENGINE_API FKeyHandle()
Definition KeyHandle.cpp:9
ENGINE_API bool IsValid() const
Definition KeyHandle.cpp:42
friend FArchive & operator<<(FArchive &Ar, FKeyHandle &Handle)
Definition KeyHandle.h:49
bool operator==(const FKeyHandle &Other) const
Definition KeyHandle.h:24
friend uint32 GetTypeHash(const FKeyHandle &Handle)
Definition KeyHandle.h:44
friend bool operator<(FKeyHandle A, FKeyHandle B)
Definition KeyHandle.h:34
Definition StructOpsTypeTraits.h:11
@ WithIdenticalViaEquality
Definition StructOpsTypeTraits.h:18
@ WithCopy
Definition StructOpsTypeTraits.h:17
@ WithSerializer
Definition StructOpsTypeTraits.h:23
static constexpr EPropertyObjectReferenceType WithSerializerObjectReferences
Definition StructOpsTypeTraits.h:41
Definition StructOpsTypeTraits.h:46