UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
EventLoopHandle.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2#pragma once
3
4#include "CoreTypes.h"
6#include "Templates/Atomic.h"
7
8namespace UE::EventLoop {
9
10template <typename Traits>
11struct TResourceHandle final
12{
17
20 : ID(0)
21 {
22 }
23
26 : ID(GenerateNewID())
27 {
28 }
29
31 bool IsValid() const
32 {
33 return ID > 0;
34 }
35
38 {
39 ID = 0;
40 }
41
42 bool operator==(const TResourceHandle& Other) const
43 {
44 return ID == Other.ID;
45 }
46
47 bool operator!=(const TResourceHandle& Other) const
48 {
49 return ID != Other.ID;
50 }
51
53 {
54 return GetTypeHash(InHandle.ID);
55 }
56
57 FString ToString() const
58 {
59 return IsValid() ? FString::Printf(TEXT("%s:%llu"), Traits::Name, ID) : FString::Printf(TEXT("%s:<invalid>"), Traits::Name);
60 }
61
62 static const TCHAR* GetTypeName()
63 {
64 return Traits::Name;
65 }
66
67private:
73 static uint64 GenerateNewID()
74 {
75 // Just increment a counter to generate an ID.
76 uint64 Result = NextID++;
77
78 // Check for the next-to-impossible event that we wrap round to 0, because we reserve 0 for null delegates.
79 if (Result == 0)
80 {
81 // Increment it again - it might not be zero, so don't just assign it to 1.
82 Result = ++NextID;
83 }
84
85 return Result;
86 }
87
88 static TAtomic<uint64> NextID;
89
90 uint64 ID;
91};
92
93template <typename Traits>
94TAtomic<uint64> TResourceHandle<Traits>::NextID = 1;
95
96/* UE::EventLoop */ }
#define TEXT(x)
Definition Platform.h:1272
FPlatformTypes::TCHAR TCHAR
Either ANSICHAR or WIDECHAR, depending on whether the platform supports wide characters or the requir...
Definition Platform.h:1135
FPlatformTypes::uint64 uint64
A 64-bit unsigned integer.
Definition Platform.h:1117
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
uint32_t uint32
Definition binka_ue_file_header.h:6
Definition Atomic.h:538
Definition EventLoopLog.cpp:5
Definition EventLoopHandle.h:12
static const TCHAR * GetTypeName()
Definition EventLoopHandle.h:62
bool operator!=(const TResourceHandle &Other) const
Definition EventLoopHandle.h:47
void Invalidate()
Definition EventLoopHandle.h:37
bool IsValid() const
Definition EventLoopHandle.h:31
EGenerateNewHandleType
Definition EventLoopHandle.h:14
@ GenerateNewHandle
Definition EventLoopHandle.h:15
TResourceHandle()
Definition EventLoopHandle.h:19
TResourceHandle(EGenerateNewHandleType)
Definition EventLoopHandle.h:25
FString ToString() const
Definition EventLoopHandle.h:57
bool operator==(const TResourceHandle &Other) const
Definition EventLoopHandle.h:42
friend uint32 GetTypeHash(const TResourceHandle &InHandle)
Definition EventLoopHandle.h:52