0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-11-12 13:01:07 +01:00

ircd::json: Add non-const iov::at(); minor cleanup.

This commit is contained in:
Jason Volk 2018-05-25 17:45:49 -07:00
parent d4c2ec6b22
commit b69848b620
2 changed files with 29 additions and 7 deletions

View file

@ -55,6 +55,7 @@ struct ircd::json::iov
public: public:
bool has(const string_view &key) const; bool has(const string_view &key) const;
const value &at(const string_view &key) const; const value &at(const string_view &key) const;
value &at(const string_view &key);
iov() = default; iov() = default;

View file

@ -987,15 +987,25 @@ ircd::json::serialized(const iov &iov)
}); });
} }
bool ircd::json::value &
ircd::json::iov::has(const string_view &key) ircd::json::iov::at(const string_view &key)
const
{ {
return std::any_of(std::begin(*this), std::end(*this), [&key] const auto it
(const auto &member)
{ {
return string_view{member.first} == key; std::find_if(std::begin(*this), std::end(*this), [&key]
}); (const auto &member)
{
return string_view{member.first} == key;
})
};
if(it == std::end(*this))
throw not_found
{
"key '%s' not found", key
};
return it->second;
} }
const ircd::json::value & const ircd::json::value &
@ -1020,6 +1030,17 @@ const
return it->second; return it->second;
} }
bool
ircd::json::iov::has(const string_view &key)
const
{
return std::any_of(std::begin(*this), std::end(*this), [&key]
(const auto &member)
{
return string_view{member.first} == key;
});
}
ircd::json::iov::add::add(iov &iov, ircd::json::iov::add::add(iov &iov,
member member) member member)
:node :node