UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
Event.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3#pragma once
4
8
9namespace uLang
10{
12
26 template <typename... ParamTypes>
28 {
29 public:
30 using FunctionType = uLang::TFunction<void(ParamTypes...)>;
32
33 template <
34 typename FunctorType,
35 typename = typename TEnableIf<
36 TAnd<
38 Private::TFuncCanBindToFunctor<void(ParamTypes...), FunctorType>
39 >::Value
40 >::Type
41 >
43 {
45 return _NextId++;
46 }
47
49 {
50 _Listeners.Emplace(SRegisteredListener{ _NextId, Listener });
51 return _NextId++;
52 }
53
54 bool Unsubscribe(const SubscriberId ListenerId)
55 {
56 const int32_t FoundIndex = _Listeners.IndexOfByPredicate([ListenerId](const TEventRegistrar<ParamTypes ...>::SRegisteredListener& Listener)->bool
57 {
58 return (Listener._Id == ListenerId);
59 }
60 );
61
62 if (FoundIndex != uLang::IndexNone)
63 {
64 _Listeners.RemoveAtSwap(FoundIndex);
65 }
66 return (FoundIndex != uLang::IndexNone);
67 }
68
69 bool IsBound() const
70 {
71 return uLang::IndexNone != _Listeners.IndexOfByPredicate([](const TEventRegistrar<ParamTypes ...>::SRegisteredListener& Listener)->bool
72 {
73 return (bool)(Listener._Callback);
74 }
75 );
76 }
77
78 int32_t Num() const
79 {
80 return _Listeners.Num();
81 }
82
83 void Reset()
84 {
85 _Listeners.Empty();
86 }
87
88 private:
90 template <typename...> friend class TEvent;
91
92 protected:
100 };
101
107 template <typename... ParamTypes>
108 class TEvent : public TEventRegistrar<ParamTypes...>
109 {
110 public:
111 using Registrar = TEventRegistrar<ParamTypes...>;
112
113 void Broadcast(ParamTypes... Params)
114 {
115 for (const typename Registrar::SRegisteredListener& Listener : Registrar::_Listeners)
116 {
117 if (Listener._Callback)
118 {
119 Listener._Callback(Params...);
120 }
121 }
122 }
123 };
124
125} // namespace uLang
OODEFFUNC typedef void(OODLE_CALLBACK t_fp_OodleCore_Plugin_Free)(void *ptr)
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
Definition Array.h:51
Definition Conditionals.h:95
Definition Event.h:28
bool Unsubscribe(const SubscriberId ListenerId)
Definition Event.h:54
uLang::TFunction< void(ParamTypes...)> FunctionType
Definition Event.h:30
bool IsBound() const
Definition Event.h:69
SubscriberId _NextId
Definition Event.h:93
SubscriberId Subscribe(const FunctionType &Listener)
Definition Event.h:48
void Reset()
Definition Event.h:83
friend class TEvent
Definition Event.h:90
int32_t Num() const
Definition Event.h:78
EventSubscriberId SubscriberId
Definition Event.h:31
TArray< SRegisteredListener > _Listeners
Definition Event.h:99
SubscriberId Subscribe(FunctorType &&InFunc)
Definition Event.h:42
Definition Event.h:109
void Broadcast(ParamTypes... Params)
Definition Event.h:113
Definition VVMEngineEnvironment.h:23
uint32_t EventSubscriberId
Definition Event.h:11
@ IndexNone
Definition Common.h:381
Definition Function.h:659
Definition Conditionals.h:16
SubscriberId _Id
Definition Event.h:96
FunctionType _Callback
Definition Event.h:97
Definition Conditionals.h:75