From c311a69c7bf820b57226ddc02baccc05ba5c8d7f Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Thu, 9 May 2019 23:43:16 -0700 Subject: [PATCH] ircd::m::room: Add sounding iteration. --- include/ircd/m/room/messages.h | 6 ++++-- ircd/m_room.cc | 22 ++++++++++++++++++++++ modules/console.cc | 17 +++++++++-------- 3 files changed, 35 insertions(+), 10 deletions(-) diff --git a/include/ircd/m/room/messages.h b/include/ircd/m/room/messages.h index b9a5b5575..c37108600 100644 --- a/include/ircd/m/room/messages.h +++ b/include/ircd/m/room/messages.h @@ -29,8 +29,10 @@ namespace ircd::m bool for_each_depth_gap(const room &, const depth_range_closure &); bool rfor_each_depth_gap(const room &, const depth_range_closure &); - std::pair surface(const room &); // First missing - std::pair sounding(const room &); // Last missing + bool sounding(const room &, const depth_range_closure &); // Last missing (all) + + std::pair surface(const room &); // First missing (one) + std::pair sounding(const room &); // Last missing (one) std::pair twain(const room &); } diff --git a/ircd/m_room.cc b/ircd/m_room.cc index 451cc0919..f0986257d 100644 --- a/ircd/m_room.cc +++ b/ircd/m_room.cc @@ -763,6 +763,28 @@ ircd::m::surface(const room &room) return ret; } +bool +ircd::m::sounding(const room &room, + const depth_range_closure &closure) +{ + bool ret(true); + int64_t depth(-1); + rfor_each_depth_gap(room, [&depth, &ret, &closure] + (const auto &range, const auto &event_idx) + { + if(depth != -1 && depth != range.second) + return false; + + depth = range.second; + if(!closure(range, event_idx)) + return false; + + return true; + }); + + return ret; +} + bool ircd::m::rfor_each_depth_gap(const room &room, const depth_range_closure &closure) diff --git a/modules/console.cc b/modules/console.cc index d6ec0be49..b805c01f3 100644 --- a/modules/console.cc +++ b/modules/console.cc @@ -7541,19 +7541,20 @@ console_cmd__room__sounding(opt &out, const string_view &line) m::surface(room) }; - const auto sound - { - m::sounding(room) - }; - const auto twain { m::twain(room) }; - out << "sounding: " << std::setw(8) << sound.first - << " " << m::event_id(sound.second) << " (" << sound.second << ")" - << std::endl; + m::sounding(room, [&out] + (const auto &range, const auto &event_idx) + { + out << "sounding: " << std::setw(8) << range.second + << " " << m::event_id(event_idx) << " (" << event_idx << ")" + << std::endl; + + return true; + }); out << "twain: " << std::setw(8) << twain.first << std::endl;