mirror of
https://github.com/matrix-construct/construct
synced 2024-11-17 15:30:52 +01:00
ircd:Ⓜ️:state: Add an unconditional for_each.
This commit is contained in:
parent
5236a7d129
commit
9405166a7a
2 changed files with 25 additions and 2 deletions
|
@ -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);
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue