From 7c09123a3c7990249f40372d867a52eec5958ad8 Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Wed, 20 Feb 2019 13:07:40 -0800 Subject: [PATCH] ircd::m::room::state: Add a type prefix-domain iteration to state interface. --- include/ircd/m/room/state.h | 2 ++ ircd/m_room.cc | 20 ++++++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/include/ircd/m/room/state.h b/include/ircd/m/room/state.h index aeacac149..c0319737b 100644 --- a/include/ircd/m/room/state.h +++ b/include/ircd/m/room/state.h @@ -28,6 +28,7 @@ struct ircd::m::room::state using keys_bool = std::function; using types = std::function; using types_bool = std::function; + IRCD_STRONG_TYPEDEF(string_view, type_prefix) static conf::item disable_history; static conf::item readahead_size; @@ -45,6 +46,7 @@ struct ircd::m::room::state // Iterate the state bool for_each(const types_bool &) const; void for_each(const types &) const; + bool for_each(const type_prefix &pref, const types_bool &) const; bool for_each(const string_view &type, const keys_bool &view) const; void for_each(const string_view &type, const keys &) const; bool for_each(const string_view &type, const string_view &lower_bound, const keys_bool &view) const; diff --git a/ircd/m_room.cc b/ircd/m_room.cc index 31b6ff7f9..f2d3b0b8d 100644 --- a/ircd/m_room.cc +++ b/ircd/m_room.cc @@ -1468,6 +1468,26 @@ const return true; } +bool +ircd::m::room::state::for_each(const type_prefix &prefix, + const types_bool &closure) +const +{ + bool ret(true), cont(true); + for_each(types_bool([&prefix, &closure, &ret, &cont] + (const string_view &type) + { + if(!startswith(type, string_view(prefix))) + return cont; + + cont = false; + ret = closure(type); + return ret; + })); + + return ret; +} + void ircd::m::room::state::for_each(const types &closure) const