0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-09-29 20:28:52 +02:00

ircd:Ⓜ️:state: Add an unconditional for_each.

This commit is contained in:
Jason Volk 2018-02-10 00:26:15 -08:00
parent 5236a7d129
commit 9405166a7a
2 changed files with 25 additions and 2 deletions

View file

@ -61,6 +61,10 @@ namespace ircd::m::state
bool test(const string_view &root, const iter_bool_closure &);
bool test(const string_view &root, const string_view &type, const iter_bool_closure &);
void for_each(const string_view &root, const iter_closure &);
void for_each(const string_view &root, const string_view &type, const iter_closure &);
size_t count(const string_view &root, const iter_bool_closure &);
size_t count(const string_view &root);

View file

@ -107,16 +107,35 @@ ircd::m::state::count(const string_view &root,
const iter_bool_closure &closure)
{
size_t ret{0};
test(root, [&ret, &closure]
for_each(root, [&ret, &closure]
(const json::array &key, const string_view &val)
{
ret += closure(key, val);
return false;
});
return ret;
}
void
ircd::m::state::for_each(const string_view &root,
const iter_closure &closure)
{
for_each(root, string_view{}, closure);
}
void
ircd::m::state::for_each(const string_view &root,
const string_view &type,
const iter_closure &closure)
{
test(root, type, [&closure]
(const json::array &key, const string_view &val)
{
closure(key, val);
return false;
});
}
bool
ircd::m::state::test(const string_view &root,
const iter_bool_closure &closure)