diff options
| author | 2020-11-10 22:23:26 +0000 | |
|---|---|---|
| committer | 2020-11-10 22:23:26 +0000 | |
| commit | c7690513cdf317f9221cedf4892facdd100ef74d (patch) | |
| tree | 68ef30e051e99dcd2d9855e410806f2630e86f55 /include | |
| parent | Only use libc++ when building with AppleClang. (diff) | |
Convert FIRST_MOD_RESULT_CUSTOM to a variadic function.
Diffstat (limited to 'include')
| -rw-r--r-- | include/event.h | 49 | ||||
| -rw-r--r-- | include/modules/exemption.h | 4 |
2 files changed, 28 insertions, 25 deletions
diff --git a/include/event.h b/include/event.h index e41011914..af75f4495 100644 --- a/include/event.h +++ b/include/event.h @@ -32,7 +32,9 @@ namespace Events * to the macro. * Event providers are identified using a unique identifier string. */ -class Events::ModuleEventProvider : public ServiceProvider, private dynamic_reference_base::CaptureHook +class Events::ModuleEventProvider + : public ServiceProvider + , private dynamic_reference_base::CaptureHook { public: struct Comp @@ -81,6 +83,13 @@ class Events::ModuleEventProvider : public ServiceProvider, private dynamic_refe OnUnsubscribe(subscriber); } + /** + * Run the given hook provided by a module until some module returns MOD_RES_ALLOW or MOD_RES_DENY. + * If no module does that, result is set to MOD_RES_PASSTHRU. + */ + template<typename Class, typename... FunArgs, typename... FwdArgs> + inline ModResult FirstResult(ModResult (Class::*function)(FunArgs...), FwdArgs&&... args) const; + private: void OnCapture() override { @@ -191,24 +200,20 @@ inline bool Events::ModuleEventProvider::ElementComp::operator()(Events::ModuleE } \ } while (0); -/** - * Run the given hook provided by a module until some module returns MOD_RES_ALLOW or MOD_RES_DENY. - * If no module does that, result is set to MOD_RES_PASSTHRU. - * - * Example: ModResult MOD_RESULT; - * FIRST_MOD_RESULT_CUSTOM(httpevprov, HTTPRequestEventListener, OnHTTPRequest, MOD_RESULT, (request)); - */ -#define FIRST_MOD_RESULT_CUSTOM(prov, listenerclass, func, result, params) do { \ - result = MOD_RES_PASSTHRU; \ - const ::Events::ModuleEventProvider::SubscriberList& _handlers = (prov).GetSubscribers(); \ - for (::Events::ModuleEventProvider::SubscriberList::const_iterator _i = _handlers.begin(); _i != _handlers.end(); ++_i) \ - { \ - listenerclass* _t = static_cast<listenerclass*>(*_i); \ - const Module* _m = _t->GetModule(); \ - if (!_m || _m->dying) \ - continue; \ - result = _t->func params ; \ - if (result != MOD_RES_PASSTHRU) \ - break; \ - } \ -} while (0); +template<typename Class, typename... FunArgs, typename... FwdArgs> +inline ModResult Events::ModuleEventProvider::FirstResult(ModResult (Class::*function)(FunArgs...), FwdArgs&&... args) const +{ + ModResult result; + for (ModuleEventListener* subscriber : subscribers) + { + const Module* mod = subscriber->GetModule(); + if (!mod || mod->dying) + continue; + + Class* klass = static_cast<Class*>(subscriber); + result = (klass->*function)(std::forward<FwdArgs>(args)...); + if (result != MOD_RES_PASSTHRU) + break; + } + return result; +} diff --git a/include/modules/exemption.h b/include/modules/exemption.h index 9319c4737..a0e32e9e0 100644 --- a/include/modules/exemption.h +++ b/include/modules/exemption.h @@ -69,7 +69,5 @@ class CheckExemption::EventProvider inline ModResult CheckExemption::Call(const CheckExemption::EventProvider& prov, User* user, Channel* chan, const std::string& restriction) { - ModResult result; - FIRST_MOD_RESULT_CUSTOM(prov, CheckExemption::EventListener, OnCheckExemption, result, (user, chan, restriction)); - return result; + return prov.FirstResult(&CheckExemption::EventListener::OnCheckExemption, user, chan, restriction); } |
