/** Declare user's dynamic delegate, with wrapper proxy method for executing the delegate */ #define FUNC_DECLARE_DYNAMIC_DELEGATE(TWeakPtr, DynamicDelegateName, ExecFunction, FuncParamList, FuncParamPassThru, ...) \ class DynamicDelegateName : public TBaseDynamicDelegate<TWeakPtr, __VA_ARGS__> \ { \ public: \ /** Default constructor */ \ DynamicDelegateName() \ { \ } \ \ /** Construction from an FScriptDelegate must be explicit. This is really only used by UObject system internals. */ \ explicit DynamicDelegateName(const TScriptDelegate<>& InScriptDelegate ) \ : TBaseDynamicDelegate<TWeakPtr, __VA_ARGS__>(InScriptDelegate) \ { \ } \ \ /** Execute the delegate. If the function pointer is not valid, an error will occur. */ \ inline void Execute(FuncParamList) const \ { \ /* Verify that the user object is still valid. We only have a weak reference to it. */ \ checkSlow(IsBound() ); \ ExecFunction(FuncParamPassThru); \ } \ /** Execute the delegate, but only if the function pointer is still valid */ \ inline bool ExecuteIfBound(FuncParamList) const \ { \ if(IsBound() ) \ { \ ExecFunction(FuncParamPassThru); \ return true; \ } \ return false; \ } \ };
/** Declare user's dynamic multi-cast delegate, with wrapper proxy method for executing the delegate */ #define FUNC_DECLARE_DYNAMIC_MULTICAST_DELEGATE(TWeakPtr, DynamicMulticastDelegateName, ExecFunction, FuncParamList, FuncParamPassThru, ...) \ class DynamicMulticastDelegateName : public TBaseDynamicMulticastDelegate<TWeakPtr, __VA_ARGS__> \ { \ public: \ /** Default constructor */ \ DynamicMulticastDelegateName() \ { \ } \ \ /** Construction from an FMulticastScriptDelegate must be explicit. This is really only used by UObject system internals. */ \ explicit DynamicMulticastDelegateName(const TMulticastScriptDelegate<>& InMulticastScriptDelegate ) \ : TBaseDynamicMulticastDelegate<TWeakPtr, __VA_ARGS__>(InMulticastScriptDelegate) \ { \ } \ \ /** Broadcasts this delegate to all bound objects, except to those that may have expired */ \ void Broadcast(FuncParamList) const \ { \ ExecFunction(FuncParamPassThru); \ } \ };
FUNC_CONCT宏只是简单的拼接:
1 2
/** Helper macro that enables passing comma-separated arguments as a single macro parameter */ #define FUNC_CONCAT(...) __VA_ARGS__