diff --git a/include/ircd/m/event/get.h b/include/ircd/m/event/get.h index b8c49b856..c81db8056 100644 --- a/include/ircd/m/event/get.h +++ b/include/ircd/m/event/get.h @@ -13,21 +13,24 @@ namespace ircd::m { - // Fetch the value for a single property of an event into the closure + // Fetch the value for a single property of an event into the closure. bool get(std::nothrow_t, const event::idx &, const string_view &key, const event::fetch::view_closure &); bool get(std::nothrow_t, const event::id &, const string_view &key, const event::fetch::view_closure &); - - // Throws if event or property in that event not found void get(const event::idx &, const string_view &key, const event::fetch::view_closure &); void get(const event::id &, const string_view &key, const event::fetch::view_closure &); - // Copies value into buffer returning view (empty for not found) + // Copies value into buffer returning view. const_buffer get(std::nothrow_t, const event::idx &, const string_view &key, const mutable_buffer &out); const_buffer get(std::nothrow_t, const event::id &, const string_view &key, const mutable_buffer &out); - const_buffer get(const event::idx &, const string_view &key, const mutable_buffer &out); const_buffer get(const event::id &, const string_view &key, const mutable_buffer &out); + // Allocates and copies into string. + std::string get(std::nothrow_t, const event::idx &, const string_view &key); + std::string get(std::nothrow_t, const event::id &, const string_view &key); + std::string get(const event::idx &, const string_view &key); + std::string get(const event::id &, const string_view &key); + template typename std::enable_if::value, bool>::type get(const event::idx &, const string_view &key, T &ret); diff --git a/ircd/m_event.cc b/ircd/m_event.cc index 9aa598bf2..729074cac 100644 --- a/ircd/m_event.cc +++ b/ircd/m_event.cc @@ -521,6 +521,64 @@ ircd::m::cached(const event::idx &event_idx, // event/get.h // +std::string +ircd::m::get(const event::id &event_id, + const string_view &key) +{ + std::string ret; + get(event_id, key, [&ret] + (const string_view &value) + { + ret = value; + }); + + return ret; +} + +std::string +ircd::m::get(const event::idx &event_idx, + const string_view &key) +{ + std::string ret; + get(event_idx, key, [&ret] + (const string_view &value) + { + ret = value; + }); + + return ret; +} + +std::string +ircd::m::get(std::nothrow_t, + const event::id &event_id, + const string_view &key) +{ + std::string ret; + get(std::nothrow, event_id, key, [&ret] + (const string_view &value) + { + ret = value; + }); + + return ret; +} + +std::string +ircd::m::get(std::nothrow_t, + const event::idx &event_idx, + const string_view &key) +{ + std::string ret; + get(std::nothrow, event_idx, key, [&ret] + (const string_view &value) + { + ret = value; + }); + + return ret; +} + ircd::const_buffer ircd::m::get(const event::id &event_id, const string_view &key,