From fd953d4b108c4b798f900d0145a569e6c4f008f0 Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Tue, 20 Aug 2019 18:48:35 -0700 Subject: [PATCH] ircd::m::events::type: Add has()/has_prefix() to interface. --- include/ircd/m/events.h | 4 ++++ modules/m_events.cc | 30 ++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/include/ircd/m/events.h b/include/ircd/m/events.h index 60f6a4b17..4a717c65a 100644 --- a/include/ircd/m/events.h +++ b/include/ircd/m/events.h @@ -40,6 +40,10 @@ namespace ircd::m::events::type // Iterate the events for a specific type. bool for_each_in(const string_view &, const closure &); + + // Test if type name is known to the server. + bool has_prefix(const string_view &); + bool has(const string_view &); } /// Interface to the senders of all events known to the server. diff --git a/modules/m_events.cc b/modules/m_events.cc index fa33ee150..2b44dda88 100644 --- a/modules/m_events.cc +++ b/modules/m_events.cc @@ -259,6 +259,36 @@ ircd::m::events::for_each(const range &range, // events::type // +bool +IRCD_MODULE_EXPORT +ircd::m::events::type::has(const string_view &type) +{ + bool ret{false}; + for_each(type, [&ret, &type] + (const string_view &type_) + { + ret = type == type_; + return false; // uncond break out of loop after first result + }); + + return ret; +} + +bool +IRCD_MODULE_EXPORT +ircd::m::events::type::has_prefix(const string_view &type) +{ + bool ret{false}; + for_each(type, [&ret, &type] + (const string_view &type_) + { + ret = startswith(type_, type); + return false; // uncond break out of loop after first result + }); + + return ret; +} + bool IRCD_MODULE_EXPORT ircd::m::events::type::for_each_in(const string_view &type,