UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
DelegateInstancesImpl.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3/*================================================================================
4 DelegateInstancesImpl.h: Inline implementation of delegate bindings.
5
6 The types declared in this file are for internal use only.
7================================================================================*/
8
9#pragma once
10
11// HEADER_UNIT_SKIP - Not included directly
12
13#include "CoreTypes.h"
20#include "Templates/Tuple.h"
22#include "UObject/NameTypes.h"
24
25#if UE_DELEGATE_CHECK_LIFETIME
26# ifdef UE_MODULE_NAME
27# define INSTRUMENT_DELEGATE_MODULE() FTrackedDelegateInstanceExtras::SetModuleName(UE_MODULE_NAME)
28# else
29# define INSTRUMENT_DELEGATE_MODULE()
30# endif // UE_MODULE_NAME
31# define INSTRUMENT_DELEGATE_FUNCTION(Function) FTrackedDelegateInstanceExtras::SetBoundFunctionName(Function)
32#else
33# define INSTRUMENT_DELEGATE_MODULE()
34# define INSTRUMENT_DELEGATE_FUNCTION(Function)
35#endif // UE_DELEGATE_CHECK_LIFETIME
36
38{
39 constexpr bool IsUObjectPtr(const volatile UObjectBase*) { return true; }
40 constexpr bool IsUObjectPtr(...) { return false; }
41}
42
43template <typename FuncType, typename UserPolicy, typename... VarTypes>
44class TCommonDelegateInstanceState : protected IBaseDelegateInstance<FuncType, UserPolicy>
45{
46public:
47 template <typename... InVarTypes>
50 , Handle (FDelegateHandle::GenerateNewHandle)
51 {
52 }
53
55 {
56 return Handle;
57 }
58
59protected:
60 // Payload member variables (if any).
62
63 // The handle of this delegate
65};
66
67/* Delegate binding types
68 *****************************************************************************/
69
70template <class UserClass, typename RetValType, typename... ParamTypes, typename UserPolicy, typename... VarTypes>
71class TBaseUFunctionDelegateInstance<UserClass, RetValType(ParamTypes...), UserPolicy, VarTypes...> : public TCommonDelegateInstanceState<RetValType(ParamTypes...), UserPolicy, VarTypes...>
72{
73private:
74 using Super = TCommonDelegateInstanceState<RetValType(ParamTypes...), UserPolicy, VarTypes...>;
75 using DelegateBaseType = typename UserPolicy::FDelegateExtras;
76
77 static_assert(UE::Delegates::Private::IsUObjectPtr((UserClass*)nullptr), "You cannot use UFunction delegates with non UObject classes.");
78
79public:
80 template <typename... InVarTypes>
83 , FunctionName (InFunctionName)
84 , UserObjectPtr(InUserObject)
85 {
87
89 INSTRUMENT_DELEGATE_FUNCTION(*UserClass::StaticClass()->GetName());
90
91 if (InUserObject != nullptr)
92 {
93 CachedFunction = UserObjectPtr->FindFunctionChecked(InFunctionName);
94 }
95 }
96
97 // IDelegateInstance interface
98
99#if USE_DELEGATE_TRYGETBOUNDFUNCTIONNAME
100
101 FName TryGetBoundFunctionName() const final
102 {
103 return FunctionName;
104 }
105
106#endif
107
108 UObject* GetUObject() const final
109 {
110 return (UObject*)UserObjectPtr.Get();
111 }
112
113 const void* GetObjectForTimerManager() const final
114 {
115 return UserObjectPtr.Get();
116 }
117
119 {
120 return 0;
121 }
122
123 // Deprecated
125 {
126#if UE_WITH_REMOTE_OBJECT_HANDLE
127 if (InUserObject.IsUObject())
128 {
129 return UserObjectPtr.HasSameObject(InUserObject.GetUObject());
130 }
131#endif
132 return UserObjectPtr.Get() == InUserObject;
133 }
134
135 bool IsCompactable() const final
136 {
137#if UE_WITH_REMOTE_OBJECT_HANDLE
138 return !UserObjectPtr.IsValid(true);
139#else
140 return !UserObjectPtr.Get(true);
141#endif
142 }
143
144 bool IsSafeToExecute() const final
145 {
146 return UserObjectPtr.IsValid();
147 }
148
149public:
150
151 // IBaseDelegateInstance interface
152
157
162
167
168 RetValType Execute(ParamTypes... Params) const final
169 {
170 using FParmsWithPayload = TPayload<RetValType(std::decay_t<ParamTypes>..., std::decay_t<VarTypes>...)>;
171
172 checkSlow(IsSafeToExecute());
173
175 this->Payload.ApplyAfter(PayloadAndParams, Forward<ParamTypes>(Params)...);
176 UserObjectPtr->ProcessEvent(CachedFunction, &PayloadAndParams);
177 return PayloadAndParams->GetResult();
178 }
179
180 bool ExecuteIfSafe(ParamTypes... Params) const final
181 {
182 TStrongObjectPtr<UserClass> PinnedObject = IsInGameThread() ? nullptr : this->UserObjectPtr.Pin();
183 if (UserClass* ActualUserObject = this->UserObjectPtr.Get())
184 {
185 using FParmsWithPayload = TPayload<RetValType(std::decay_t<ParamTypes>..., std::decay_t<VarTypes>...)>;
186
188 this->Payload.ApplyAfter(PayloadAndParams, Forward<ParamTypes>(Params)...);
189 ActualUserObject->ProcessEvent(CachedFunction, &PayloadAndParams);
190 return true;
191 }
192
193 return false;
194 }
195
196public:
197
198 // Holds the cached UFunction to call.
200
201 // Holds the name of the function to call.
203
204 // The user object to call the function on.
206};
207
208
209template <bool bConst, class UserClass, ESPMode SPMode, typename RetValType, typename... ParamTypes, typename UserPolicy, typename... VarTypes>
210class TBaseSPMethodDelegateInstance<bConst, UserClass, SPMode, RetValType(ParamTypes...), UserPolicy, VarTypes...> : public TCommonDelegateInstanceState<RetValType(ParamTypes...), UserPolicy, VarTypes...>
211{
212private:
213 using Super = TCommonDelegateInstanceState<RetValType(ParamTypes...), UserPolicy, VarTypes...>;
214 using DelegateBaseType = typename UserPolicy::FDelegateExtras;
215
216public:
217 using FMethodPtr = typename TMemFunPtrType<bConst, UserClass, RetValType(ParamTypes..., VarTypes...)>::Type;
218
219 template <typename... InVarTypes>
222 , UserObject(InUserObject)
223 , MethodPtr (InMethodPtr)
224 {
225 // NOTE: Shared pointer delegates are allowed to have a null incoming object pointer. Weak pointers can expire,
226 // an it is possible for a copy of a delegate instance to end up with a null pointer.
227 checkSlow(MethodPtr != nullptr);
228
231 }
232
233 // IDelegateInstance interface
234
235#if USE_DELEGATE_TRYGETBOUNDFUNCTIONNAME
236
237 FName TryGetBoundFunctionName() const final
238 {
239 return NAME_None;
240 }
241
242#endif
243
244 UObject* GetUObject() const final
245 {
246 return nullptr;
247 }
248
249 const void* GetObjectForTimerManager() const final
250 {
251 return UserObject.Pin().Get();
252 }
253
255 {
256#if PLATFORM_64BITS
257 return *((uint64*)&MethodPtr);
258#else
259 return *((uint32*)&MethodPtr);
260#endif
261 }
262
263 // Deprecated
265 {
266 return UserObject.HasSameObject(InUserObject);
267 }
268
269 bool IsSafeToExecute() const final
270 {
271 return UserObject.IsValid();
272 }
273
274public:
275
276 // IBaseDelegateInstance interface
277
282
287
292
293 RetValType Execute(ParamTypes... Params) const final
294 {
295 using MutableUserClass = std::remove_const_t<UserClass>;
296
297 // Verify that the user object is still valid. We only have a weak reference to it.
299 checkSlow(SharedUserObject.IsValid());
300
301 // Safely remove const to work around a compiler issue with instantiating template permutations for
302 // overloaded functions that take a function pointer typedef as a member of a templated class. In
303 // all cases where this code is actually invoked, the UserClass will already be a const pointer.
305
306 checkSlow(MethodPtr != nullptr);
307
308 return this->Payload.ApplyAfter(MethodPtr, MutableUserObject, Forward<ParamTypes>(Params)...);
309 }
310
311 bool ExecuteIfSafe(ParamTypes... Params) const final
312 {
313 // Verify that the user object is still valid. We only have a weak reference to it.
314 if (TSharedPtr<UserClass, SPMode> SharedUserObject = this->UserObject.Pin())
315 {
316 using MutableUserClass = std::remove_const_t<UserClass>;
317
318 // Safely remove const to work around a compiler issue with instantiating template permutations for
319 // overloaded functions that take a function pointer typedef as a member of a templated class. In
320 // all cases where this code is actually invoked, the UserClass will already be a const pointer.
322
323 checkSlow(MethodPtr != nullptr);
324
325 (void)this->Payload.ApplyAfter(MethodPtr, MutableUserObject, Forward<ParamTypes>(Params)...);
326
327 return true;
328 }
329
330 return false;
331 }
332
333protected:
334
335 // Weak reference to an instance of the user's class which contains a method we would like to call.
337
338 // C++ member function pointer.
340};
341
342
343template <ESPMode SPMode, typename RetValType, typename... ParamTypes, typename UserPolicy, typename FunctorType, typename... VarTypes>
344class TBaseSPLambdaDelegateInstance<SPMode, RetValType(ParamTypes...), UserPolicy, FunctorType, VarTypes...> : public TCommonDelegateInstanceState<RetValType(ParamTypes...), UserPolicy, VarTypes...>
345{
346private:
347 static_assert(std::is_same_v<FunctorType, std::remove_reference_t<FunctorType>>, "FunctorType cannot be a reference");
348
349 using Super = TCommonDelegateInstanceState<RetValType(ParamTypes...), UserPolicy, VarTypes...>;
350 using DelegateBaseType = typename UserPolicy::FDelegateExtras;
351
352 using UserClass = const void;
353
354public:
355 template <typename InFunctorType, typename... InVarTypes>
364
365 // IDelegateInstance interface
366
367#if USE_DELEGATE_TRYGETBOUNDFUNCTIONNAME
368
369 FName TryGetBoundFunctionName() const final
370 {
371 return NAME_None;
372 }
373
374#endif
375
376 UObject* GetUObject() const final
377 {
378 return nullptr;
379 }
380
381 const void* GetObjectForTimerManager() const final
382 {
383 return ContextObject.Pin().Get();
384 }
385
387 {
388 return 0;
389 }
390
391 // Deprecated
393 {
394 return ContextObject.Pin().Get() == InContextObject;
395 }
396
397 bool IsSafeToExecute() const final
398 {
399 return ContextObject.IsValid();
400 }
401
402public:
403
404public:
405 // IBaseDelegateInstance interface
410
415
420
421 RetValType Execute(ParamTypes... Params) const final
422 {
423 return this->Payload.ApplyAfter(Functor, Forward<ParamTypes>(Params)...);
424 }
425
426 bool ExecuteIfSafe(ParamTypes... Params) const final
427 {
428 if (ContextObject.IsValid())
429 {
430 (void)this->Payload.ApplyAfter(Functor, Forward<ParamTypes>(Params)...);
431 return true;
432 }
433
434 return false;
435 }
436
437private:
438
439 // Weak reference to an instance of the user's class that controls the validity of the lambda.
440 TWeakPtr<UserClass, SPMode> ContextObject;
441
442 // We make this mutable to allow mutable lambdas to be bound and executed.
443 mutable std::remove_const_t<FunctorType> Functor;
444};
445
446
447template <bool bConst, class UserClass, typename RetValType, typename... ParamTypes, typename UserPolicy, typename... VarTypes>
448class TBaseRawMethodDelegateInstance<bConst, UserClass, RetValType(ParamTypes...), UserPolicy, VarTypes...> : public TCommonDelegateInstanceState<RetValType(ParamTypes...), UserPolicy, VarTypes...>
449{
450private:
451 static_assert(!UE::Delegates::Private::IsUObjectPtr((UserClass*)nullptr), "You cannot use raw method delegates with UObjects.");
452
453 using Super = TCommonDelegateInstanceState<RetValType(ParamTypes...), UserPolicy, VarTypes...>;
454 using DelegateBaseType = typename UserPolicy::FDelegateExtras;
455
456public:
457 using FMethodPtr = typename TMemFunPtrType<bConst, UserClass, RetValType(ParamTypes..., VarTypes...)>::Type;
458
465 template <typename... InVarTypes>
468 , UserObject(InUserObject)
469 , MethodPtr (InMethodPtr)
470 {
471 // Non-expirable delegates must always have a non-null object pointer on creation (otherwise they could never execute.)
472 check(InUserObject != nullptr && MethodPtr != nullptr);
473
476 }
477
478 // IDelegateInstance interface
479
480#if USE_DELEGATE_TRYGETBOUNDFUNCTIONNAME
481
482 FName TryGetBoundFunctionName() const final
483 {
484 return NAME_None;
485 }
486
487#endif
488
489 UObject* GetUObject() const final
490 {
491 return nullptr;
492 }
493
494 const void* GetObjectForTimerManager() const final
495 {
496 return UserObject;
497 }
498
500 {
501#if PLATFORM_64BITS
502 return *((uint64*)&MethodPtr);
503#else
504 return *((uint32*)&MethodPtr);
505#endif
506 }
507
508 // Deprecated
510 {
511 return UserObject == InUserObject;
512 }
513
514 bool IsSafeToExecute() const final
515 {
516 // We never know whether or not it is safe to deference a C++ pointer, but we have to
517 // trust the user in this case. Prefer using a shared-pointer based delegate type instead!
518 return true;
519 }
520
521public:
522
523 // IBaseDelegateInstance interface
524
529
534
539
540 RetValType Execute(ParamTypes... Params) const final
541 {
542 using MutableUserClass = std::remove_const_t<UserClass>;
543
544 // Safely remove const to work around a compiler issue with instantiating template permutations for
545 // overloaded functions that take a function pointer typedef as a member of a templated class. In
546 // all cases where this code is actually invoked, the UserClass will already be a const pointer.
547 MutableUserClass* MutableUserObject = const_cast<MutableUserClass*>(UserObject);
548
549 checkSlow(MethodPtr != nullptr);
550
551 return this->Payload.ApplyAfter(MethodPtr, MutableUserObject, Forward<ParamTypes>(Params)...);
552 }
553
554
555 bool ExecuteIfSafe(ParamTypes... Params) const final
556 {
557 using MutableUserClass = std::remove_const_t<UserClass>;
558
559 // Safely remove const to work around a compiler issue with instantiating template permutations for
560 // overloaded functions that take a function pointer typedef as a member of a templated class. In
561 // all cases where this code is actually invoked, the UserClass will already be a const pointer.
562 MutableUserClass* MutableUserObject = const_cast<MutableUserClass*>(UserObject);
563
564 checkSlow(MethodPtr != nullptr);
565
566 (void)this->Payload.ApplyAfter(MethodPtr, MutableUserObject, Forward<ParamTypes>(Params)...);
567
568 return true;
569 }
570
571protected:
572
573 // Pointer to the user's class which contains a method we would like to call.
574 UserClass* UserObject;
575
576 // C++ member function pointer.
578};
579
580
581template <bool bConst, class UserClass, typename RetValType, typename... ParamTypes, typename UserPolicy, typename... VarTypes>
582class TBaseUObjectMethodDelegateInstance<bConst, UserClass, RetValType(ParamTypes...), UserPolicy, VarTypes...> : public TCommonDelegateInstanceState<RetValType(ParamTypes...), UserPolicy, VarTypes...>
583{
584private:
585 using Super = TCommonDelegateInstanceState<RetValType(ParamTypes...), UserPolicy, VarTypes...>;
586 using DelegateBaseType = typename UserPolicy::FDelegateExtras;
587
588 static_assert(UE::Delegates::Private::IsUObjectPtr((UserClass*)nullptr), "You cannot use UObject method delegates with raw pointers.");
589
590public:
591 using FMethodPtr = typename TMemFunPtrType<bConst, UserClass, RetValType(ParamTypes..., VarTypes...)>::Type;
592
593 template <typename... InVarTypes>
596 , UserObject(InUserObject)
597 , MethodPtr (InMethodPtr)
598 {
599 // NOTE: UObject delegates are allowed to have a null incoming object pointer. UObject weak pointers can expire,
600 // an it is possible for a copy of a delegate instance to end up with a null pointer.
601 checkSlow(MethodPtr != nullptr);
602
604 INSTRUMENT_DELEGATE_FUNCTION(*UserClass::StaticClass()->GetName());
605 }
606
607 // IDelegateInstance interface
608
609#if USE_DELEGATE_TRYGETBOUNDFUNCTIONNAME
610
611 FName TryGetBoundFunctionName() const final
612 {
613 return NAME_None;
614 }
615
616#endif
617
618 UObject* GetUObject() const final
619 {
620 return (UObject*)UserObject.Get();
621 }
622
623 const void* GetObjectForTimerManager() const final
624 {
625 return UserObject.Get();
626 }
627
629 {
630#if PLATFORM_64BITS
631 return *((uint64*)&MethodPtr);
632#else
633 return *((uint32*)&MethodPtr);
634#endif
635 }
636
637 // Deprecated
639 {
640#if UE_WITH_REMOTE_OBJECT_HANDLE
641 if (InUserObject.IsUObject())
642 {
643 return UserObject.HasSameObject(InUserObject.GetUObject());
644 }
645#endif
646 return (UserObject.Get() == InUserObject);
647 }
648
649 bool IsCompactable() const final
650 {
651#if UE_WITH_REMOTE_OBJECT_HANDLE
652 return !UserObject.IsValid(true);
653#else
654 return !UserObject.Get(true);
655#endif
656 }
657
658 bool IsSafeToExecute() const final
659 {
660 return !!UserObject.Get();
661 }
662
663public:
664
665 // IBaseDelegateInstance interface
666
671
676
681
682 RetValType Execute(ParamTypes... Params) const final
683 {
684 using MutableUserClass = std::remove_const_t<UserClass>;
685
686 // Verify that the user object is still valid. We only have a weak reference to it.
687 checkSlow(UserObject.IsValid());
688
689 // Safely remove const to work around a compiler issue with instantiating template permutations for
690 // overloaded functions that take a function pointer typedef as a member of a templated class. In
691 // all cases where this code is actually invoked, the UserClass will already be a const pointer.
692 MutableUserClass* MutableUserObject = const_cast<MutableUserClass*>(UserObject.Get());
693
694 checkSlow(MethodPtr != nullptr);
695
696 return this->Payload.ApplyAfter(MethodPtr, MutableUserObject, Forward<ParamTypes>(Params)...);
697 }
698
699 bool ExecuteIfSafe(ParamTypes... Params) const final
700 {
701 TStrongObjectPtr<UserClass> PinnedObject = IsInGameThread() ? nullptr : this->UserObject.Pin();
702 if (UserClass* ActualUserObject = this->UserObject.Get())
703 {
704 using MutableUserClass = std::remove_const_t<UserClass>;
705
706 // Safely remove const to work around a compiler issue with instantiating template permutations for
707 // overloaded functions that take a function pointer typedef as a member of a templated class. In
708 // all cases where this code is actually invoked, the UserClass will already be a const pointer.
710
711 checkSlow(MethodPtr != nullptr);
712
713 (void)this->Payload.ApplyAfter(MethodPtr, MutableUserObject, Forward<ParamTypes>(Params)...);
714
715 return true;
716 }
717 return false;
718 }
719
720protected:
721
722 // Pointer to the user's class which contains a method we would like to call.
724
725 // C++ member function pointer.
727};
728
729
730template <typename RetValType, typename... ParamTypes, typename UserPolicy, typename... VarTypes>
731class TBaseStaticDelegateInstance<RetValType(ParamTypes...), UserPolicy, VarTypes...> : public TCommonDelegateInstanceState<RetValType(ParamTypes...), UserPolicy, VarTypes...>
732{
733private:
734 using Super = TCommonDelegateInstanceState<RetValType(ParamTypes...), UserPolicy, VarTypes...>;
735 using DelegateBaseType = typename UserPolicy::FDelegateExtras;
736
737public:
738 using FFuncPtr = RetValType(*)(ParamTypes..., VarTypes...);
739
740 template <typename... InVarTypes>
743 , StaticFuncPtr(InStaticFuncPtr)
744 {
745 check(StaticFuncPtr != nullptr);
746
748 }
749
750 // IDelegateInstance interface
751
752#if USE_DELEGATE_TRYGETBOUNDFUNCTIONNAME
753
754 FName TryGetBoundFunctionName() const final
755 {
756 return NAME_None;
757 }
758
759#endif
760
761 UObject* GetUObject() const final
762 {
763 return nullptr;
764 }
765
766 const void* GetObjectForTimerManager() const final
767 {
768 return nullptr;
769 }
770
772 {
773#if PLATFORM_64BITS
774 return *((uint64*)&StaticFuncPtr);
775#else
776 return *((uint32*)&StaticFuncPtr);
777#endif
778 }
779
780 // Deprecated
781 bool HasSameObject(FDelegateUserObjectConst UserObject) const final
782 {
783 // Raw Delegates aren't bound to an object so they can never match
784 return false;
785 }
786
787 bool IsSafeToExecute() const final
788 {
789 // Static functions are always safe to execute!
790 return true;
791 }
792
793public:
794
795 // IBaseDelegateInstance interface
796
801
806
811
812 RetValType Execute(ParamTypes... Params) const final
813 {
814 // Call the static function
815 checkSlow(StaticFuncPtr != nullptr);
816
817 return this->Payload.ApplyAfter(StaticFuncPtr, Forward<ParamTypes>(Params)...);
818 }
819
820 bool ExecuteIfSafe(ParamTypes... Params) const final
821 {
822 // Call the static function
823 checkSlow(StaticFuncPtr != nullptr);
824
825 (void)this->Payload.ApplyAfter(StaticFuncPtr, Forward<ParamTypes>(Params)...);
826
827 return true;
828 }
829
830private:
831
832 // C++ function pointer.
833 FFuncPtr StaticFuncPtr;
834};
835
836
837template <typename RetValType, typename... ParamTypes, typename UserPolicy, typename FunctorType, typename... VarTypes>
838class TBaseFunctorDelegateInstance<RetValType(ParamTypes...), UserPolicy, FunctorType, VarTypes...> : public TCommonDelegateInstanceState<RetValType(ParamTypes...), UserPolicy, VarTypes...>
839{
840private:
841 static_assert(std::is_same_v<FunctorType, std::remove_reference_t<FunctorType>>, "FunctorType cannot be a reference");
842
843 using Super = TCommonDelegateInstanceState<RetValType(ParamTypes...), UserPolicy, VarTypes...>;
844 using DelegateBaseType = typename UserPolicy::FDelegateExtras;
845
846public:
847 template <typename InFunctorType, typename... InVarTypes>
854
855 // IDelegateInstance interface
856
857#if USE_DELEGATE_TRYGETBOUNDFUNCTIONNAME
858
859 FName TryGetBoundFunctionName() const final
860 {
861 return NAME_None;
862 }
863
864#endif
865
866 UObject* GetUObject() const final
867 {
868 return nullptr;
869 }
870
871 const void* GetObjectForTimerManager() const final
872 {
873 return nullptr;
874 }
875
877 {
878 return 0;
879 }
880
881 // Deprecated
882 bool HasSameObject(FDelegateUserObjectConst UserObject) const final
883 {
884 // Functor Delegates aren't bound to a user object so they can never match
885 return false;
886 }
887
888 bool IsSafeToExecute() const final
889 {
890 // Functors are always considered safe to execute!
891 return true;
892 }
893
894public:
895 // IBaseDelegateInstance interface
900
905
910
911 RetValType Execute(ParamTypes... Params) const final
912 {
913 return this->Payload.ApplyAfter(Functor, Forward<ParamTypes>(Params)...);
914 }
915
916 bool ExecuteIfSafe(ParamTypes... Params) const final
917 {
918 // Functors are always considered safe to execute!
919 (void)this->Payload.ApplyAfter(Functor, Forward<ParamTypes>(Params)...);
920
921 return true;
922 }
923
924private:
925 // C++ functor
926 // We make this mutable to allow mutable lambdas to be bound and executed. We don't really want to
927 // model the Functor as being a direct subobject of the delegate (which would maintain transivity of
928 // const - because the binding doesn't affect the substitutability of a copied delegate.
929 mutable std::remove_const_t<FunctorType> Functor;
930};
931
932
933template <typename RetValType, typename... ParamTypes, typename UserPolicy, typename FunctorType, typename... VarTypes>
934class TWeakBaseFunctorDelegateInstance<RetValType(ParamTypes...), UserPolicy, FunctorType, VarTypes...> : public TCommonDelegateInstanceState<RetValType(ParamTypes...), UserPolicy, VarTypes...>
935{
936private:
937 static_assert(std::is_same_v<FunctorType, std::remove_reference_t<FunctorType>>, "FunctorType cannot be a reference");
938
939 using Super = TCommonDelegateInstanceState<RetValType(ParamTypes...), UserPolicy, VarTypes...>;
940 using DelegateBaseType = typename UserPolicy::FDelegateExtras;
941
942 // A dependency on the template parameter is required here to stop early instantiation of types which are
943 // defined in CoreUObject.
944 using UserClass = std::conditional_t<sizeof...(ParamTypes) == 0, const UObject, const UObject>;
945
946public:
947 template <typename InFunctorType, typename... InVarTypes>
956
957 // IDelegateInstance interface
958
959#if USE_DELEGATE_TRYGETBOUNDFUNCTIONNAME
960
961 FName TryGetBoundFunctionName() const final
962 {
963 return NAME_None;
964 }
965
966#endif
967
968 UObject* GetUObject() const final
969 {
970 return (UObject*)ContextObject.Get();
971 }
972
973 const void* GetObjectForTimerManager() const final
974 {
975 return ContextObject.Get();
976 }
977
979 {
980 return 0;
981 }
982
983 // Deprecated
985 {
986#if UE_WITH_REMOTE_OBJECT_HANDLE
987 if (InContextObject.IsUObject())
988 {
989 return ContextObject.HasSameObject(InContextObject.GetUObject());
990 }
991#endif
992 return GetUObject() == InContextObject;
993 }
994
995 bool IsCompactable() const final
996 {
997#if UE_WITH_REMOTE_OBJECT_HANDLE
998 return !ContextObject.IsValid(true);
999#else
1000 return !ContextObject.Get(true);
1001#endif
1002 }
1003
1004 bool IsSafeToExecute() const final
1005 {
1006 return ContextObject.IsValid();
1007 }
1008
1009public:
1010 // IBaseDelegateInstance interface
1015
1020
1025
1026 RetValType Execute(ParamTypes... Params) const final
1027 {
1028 return this->Payload.ApplyAfter(Functor, Forward<ParamTypes>(Params)...);
1029 }
1030
1031 bool ExecuteIfSafe(ParamTypes... Params) const final
1032 {
1033 TStrongObjectPtr<UserClass> PinnedObject = IsInGameThread() ? nullptr : ContextObject.Pin();
1034 if (ContextObject.IsValid())
1035 {
1036 (void)this->Payload.ApplyAfter(Functor, Forward<ParamTypes>(Params)...);
1037 return true;
1038 }
1039
1040 return false;
1041 }
1042
1043private:
1044 // Context object - the validity of this object controls the validity of the lambda
1045 TWeakObjectPtr<UserClass> ContextObject;
1046
1047 // C++ functor
1048 // We make this mutable to allow mutable lambdas to be bound and executed. We don't really want to
1049 // model the Functor as being a direct subobject of the delegate (which would maintain transivity of
1050 // const - because the binding doesn't affect the substitutability of a copied delegate.
1051 mutable std::remove_const_t<FunctorType> Functor;
1052};
1053
1054#if UE_ENABLE_INCLUDE_ORDER_DEPRECATED_IN_5_7
1056#endif
OODEFFUNC typedef void(OODLE_CALLBACK t_fp_OodleCore_Plugin_Free)(void *ptr)
#define checkSlow(expr)
Definition AssertionMacros.h:332
#define check(expr)
Definition AssertionMacros.h:314
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
#define INSTRUMENT_DELEGATE_FUNCTION(Function)
Definition DelegateInstancesImpl.h:34
#define INSTRUMENT_DELEGATE_MODULE()
Definition DelegateInstancesImpl.h:33
const void * FDelegateUserObjectConst
Definition IDelegateInstance.h:108
ESPMode
Definition SharedPointerFwd.h:12
CORE_API bool IsInGameThread()
Definition ThreadingBase.cpp:185
uint32_t uint32
Definition binka_ue_file_header.h:6
Definition IDelegateInstance.h:14
Definition NameTypes.h:617
UObject * GetUObject() const final
Definition DelegateInstancesImpl.h:866
uint64 GetBoundProgramCounterForTimerManager() const final
Definition DelegateInstancesImpl.h:876
void CreateCopy(TDelegateBase< FNotThreadSafeNotCheckedDelegateMode > &Base) const final
Definition DelegateInstancesImpl.h:906
bool HasSameObject(FDelegateUserObjectConst UserObject) const final
Definition DelegateInstancesImpl.h:882
void CreateCopy(TDelegateBase< FNotThreadSafeDelegateMode > &Base) const final
Definition DelegateInstancesImpl.h:901
TBaseFunctorDelegateInstance(InFunctorType &&InFunctor, InVarTypes &&... Vars)
Definition DelegateInstancesImpl.h:848
const void * GetObjectForTimerManager() const final
Definition DelegateInstancesImpl.h:871
void CreateCopy(TDelegateBase< FThreadSafeDelegateMode > &Base) const final
Definition DelegateInstancesImpl.h:896
bool ExecuteIfSafe(ParamTypes... Params) const final
Definition DelegateInstancesImpl.h:916
RetValType Execute(ParamTypes... Params) const final
Definition DelegateInstancesImpl.h:911
Definition DelegateInstancesImplFwd.h:53
void CreateCopy(TDelegateBase< FThreadSafeDelegateMode > &Base) const final
Definition DelegateInstancesImpl.h:525
bool ExecuteIfSafe(ParamTypes... Params) const final
Definition DelegateInstancesImpl.h:555
uint64 GetBoundProgramCounterForTimerManager() const final
Definition DelegateInstancesImpl.h:499
RetValType Execute(ParamTypes... Params) const final
Definition DelegateInstancesImpl.h:540
const void * GetObjectForTimerManager() const final
Definition DelegateInstancesImpl.h:494
void CreateCopy(TDelegateBase< FNotThreadSafeDelegateMode > &Base) const final
Definition DelegateInstancesImpl.h:530
TBaseRawMethodDelegateInstance(UserClass *InUserObject, FMethodPtr InMethodPtr, InVarTypes &&... Vars)
Definition DelegateInstancesImpl.h:466
typename TMemFunPtrType< bConst, UserClass, RetValType(ParamTypes..., VarTypes...)>::Type FMethodPtr
Definition DelegateInstancesImpl.h:457
bool HasSameObject(FDelegateUserObjectConst InUserObject) const final
Definition DelegateInstancesImpl.h:509
void CreateCopy(TDelegateBase< FNotThreadSafeNotCheckedDelegateMode > &Base) const final
Definition DelegateInstancesImpl.h:535
Definition DelegateInstancesImplFwd.h:35
uint64 GetBoundProgramCounterForTimerManager() const final
Definition DelegateInstancesImpl.h:386
bool ExecuteIfSafe(ParamTypes... Params) const final
Definition DelegateInstancesImpl.h:426
TBaseSPLambdaDelegateInstance(const TWeakPtr< UserClass, SPMode > &InContextObject, InFunctorType &&InFunctor, InVarTypes &&... Vars)
Definition DelegateInstancesImpl.h:356
void CreateCopy(TDelegateBase< FNotThreadSafeDelegateMode > &Base) const final
Definition DelegateInstancesImpl.h:411
RetValType Execute(ParamTypes... Params) const final
Definition DelegateInstancesImpl.h:421
const void * GetObjectForTimerManager() const final
Definition DelegateInstancesImpl.h:381
void CreateCopy(TDelegateBase< FThreadSafeDelegateMode > &Base) const final
Definition DelegateInstancesImpl.h:406
bool HasSameObject(FDelegateUserObjectConst InContextObject) const final
Definition DelegateInstancesImpl.h:392
void CreateCopy(TDelegateBase< FNotThreadSafeNotCheckedDelegateMode > &Base) const final
Definition DelegateInstancesImpl.h:416
Definition DelegateInstancesImplFwd.h:29
RetValType Execute(ParamTypes... Params) const final
Definition DelegateInstancesImpl.h:293
bool ExecuteIfSafe(ParamTypes... Params) const final
Definition DelegateInstancesImpl.h:311
TBaseSPMethodDelegateInstance(const TSharedPtr< UserClass, SPMode > &InUserObject, FMethodPtr InMethodPtr, InVarTypes &&... Vars)
Definition DelegateInstancesImpl.h:220
void CreateCopy(TDelegateBase< FNotThreadSafeNotCheckedDelegateMode > &Base) const final
Definition DelegateInstancesImpl.h:288
typename TMemFunPtrType< bConst, UserClass, RetValType(ParamTypes..., VarTypes...)>::Type FMethodPtr
Definition DelegateInstancesImpl.h:217
void CreateCopy(TDelegateBase< FNotThreadSafeDelegateMode > &Base) const final
Definition DelegateInstancesImpl.h:283
void CreateCopy(TDelegateBase< FThreadSafeDelegateMode > &Base) const final
Definition DelegateInstancesImpl.h:278
bool HasSameObject(FDelegateUserObjectConst InUserObject) const final
Definition DelegateInstancesImpl.h:264
Definition DelegateInstancesImplFwd.h:23
void CreateCopy(TDelegateBase< FNotThreadSafeNotCheckedDelegateMode > &Base) const final
Definition DelegateInstancesImpl.h:807
UObject * GetUObject() const final
Definition DelegateInstancesImpl.h:761
RetValType(*)(ParamTypes..., VarTypes...) FFuncPtr
Definition DelegateInstancesImpl.h:738
bool ExecuteIfSafe(ParamTypes... Params) const final
Definition DelegateInstancesImpl.h:820
uint64 GetBoundProgramCounterForTimerManager() const final
Definition DelegateInstancesImpl.h:771
RetValType Execute(ParamTypes... Params) const final
Definition DelegateInstancesImpl.h:812
void CreateCopy(TDelegateBase< FThreadSafeDelegateMode > &Base) const final
Definition DelegateInstancesImpl.h:797
const void * GetObjectForTimerManager() const final
Definition DelegateInstancesImpl.h:766
bool HasSameObject(FDelegateUserObjectConst UserObject) const final
Definition DelegateInstancesImpl.h:781
bool IsSafeToExecute() const final
Definition DelegateInstancesImpl.h:787
void CreateCopy(TDelegateBase< FNotThreadSafeDelegateMode > &Base) const final
Definition DelegateInstancesImpl.h:802
TBaseStaticDelegateInstance(FFuncPtr InStaticFuncPtr, InVarTypes &&... Vars)
Definition DelegateInstancesImpl.h:741
Definition DelegateInstancesImplFwd.h:47
bool HasSameObject(FDelegateUserObjectConst InUserObject) const final
Definition DelegateInstancesImpl.h:124
void CreateCopy(TDelegateBase< FThreadSafeDelegateMode > &Base) const final
Definition DelegateInstancesImpl.h:153
const void * GetObjectForTimerManager() const final
Definition DelegateInstancesImpl.h:113
uint64 GetBoundProgramCounterForTimerManager() const final
Definition DelegateInstancesImpl.h:118
void CreateCopy(TDelegateBase< FNotThreadSafeNotCheckedDelegateMode > &Base) const final
Definition DelegateInstancesImpl.h:163
UObject * GetUObject() const final
Definition DelegateInstancesImpl.h:108
TBaseUFunctionDelegateInstance(UserClass *InUserObject, const FName &InFunctionName, InVarTypes &&... Vars)
Definition DelegateInstancesImpl.h:81
RetValType Execute(ParamTypes... Params) const final
Definition DelegateInstancesImpl.h:168
void CreateCopy(TDelegateBase< FNotThreadSafeDelegateMode > &Base) const final
Definition DelegateInstancesImpl.h:158
TWeakObjectPtr< UserClass > UserObjectPtr
Definition DelegateInstancesImpl.h:205
bool ExecuteIfSafe(ParamTypes... Params) const final
Definition DelegateInstancesImpl.h:180
Definition DelegateInstancesImplFwd.h:17
void CreateCopy(TDelegateBase< FNotThreadSafeNotCheckedDelegateMode > &Base) const final
Definition DelegateInstancesImpl.h:677
TBaseUObjectMethodDelegateInstance(UserClass *InUserObject, FMethodPtr InMethodPtr, InVarTypes &&... Vars)
Definition DelegateInstancesImpl.h:594
const void * GetObjectForTimerManager() const final
Definition DelegateInstancesImpl.h:623
typename TMemFunPtrType< bConst, UserClass, RetValType(ParamTypes..., VarTypes...)>::Type FMethodPtr
Definition DelegateInstancesImpl.h:591
bool ExecuteIfSafe(ParamTypes... Params) const final
Definition DelegateInstancesImpl.h:699
bool HasSameObject(FDelegateUserObjectConst InUserObject) const final
Definition DelegateInstancesImpl.h:638
RetValType Execute(ParamTypes... Params) const final
Definition DelegateInstancesImpl.h:682
void CreateCopy(TDelegateBase< FNotThreadSafeDelegateMode > &Base) const final
Definition DelegateInstancesImpl.h:672
void CreateCopy(TDelegateBase< FThreadSafeDelegateMode > &Base) const final
Definition DelegateInstancesImpl.h:667
Definition DelegateInstancesImplFwd.h:41
Definition DelegateInstancesImpl.h:45
TTuple< VarTypes... > Payload
Definition DelegateInstancesImpl.h:61
FDelegateHandle Handle
Definition DelegateInstancesImpl.h:64
TCommonDelegateInstanceState(InVarTypes &&... Vars)
Definition DelegateInstancesImpl.h:48
FDelegateHandle GetHandle() const final
Definition DelegateInstancesImpl.h:54
Definition DelegateBase.h:226
Definition SharedPointer.h:692
Definition StrongObjectPtrTemplates.h:26
uint64 GetBoundProgramCounterForTimerManager() const final
Definition DelegateInstancesImpl.h:978
void CreateCopy(TDelegateBase< FNotThreadSafeDelegateMode > &Base) const final
Definition DelegateInstancesImpl.h:1016
const void * GetObjectForTimerManager() const final
Definition DelegateInstancesImpl.h:973
bool HasSameObject(FDelegateUserObjectConst InContextObject) const final
Definition DelegateInstancesImpl.h:984
TWeakBaseFunctorDelegateInstance(UserClass *InContextObject, InFunctorType &&InFunctor, InVarTypes &&... Vars)
Definition DelegateInstancesImpl.h:948
void CreateCopy(TDelegateBase< FThreadSafeDelegateMode > &Base) const final
Definition DelegateInstancesImpl.h:1011
RetValType Execute(ParamTypes... Params) const final
Definition DelegateInstancesImpl.h:1026
bool ExecuteIfSafe(ParamTypes... Params) const final
Definition DelegateInstancesImpl.h:1031
void CreateCopy(TDelegateBase< FNotThreadSafeNotCheckedDelegateMode > &Base) const final
Definition DelegateInstancesImpl.h:1021
Definition DelegateInstancesImplFwd.h:59
Definition SharedPointer.h:1295
Definition Class.h:2476
Definition UObjectBase.h:59
Definition Object.h:95
Definition DelegateHandle.cpp:9
constexpr bool IsUObjectPtr(const volatile UObjectBase *)
Definition DelegateInstancesImpl.h:39
Definition DelegateInstanceInterface.h:12
Definition DelegateInstanceInterface.h:49
Definition DelegateInstanceInterface.h:67
Definition DelegateInstanceInterface.h:104
Definition Tuple.h:652
Definition WeakObjectPtrTemplates.h:25
Definition DelegateBase.h:205