mirror of
https://github.com/matrix-construct/construct
synced 2024-10-01 13:18:58 +02:00
ircd:Ⓜ️:vm: Add tools using the eval instance_list.
This commit is contained in:
parent
70c901a894
commit
93fb468ba2
2 changed files with 72 additions and 0 deletions
|
@ -80,6 +80,12 @@ struct ircd::m::vm::eval
|
|||
eval(eval &&) = delete;
|
||||
eval(const eval &) = delete;
|
||||
~eval() noexcept;
|
||||
|
||||
static bool for_each(const std::function<bool (eval &)> &);
|
||||
static eval *find(const event::id &);
|
||||
static eval &get(const event::id &);
|
||||
|
||||
static bool for_each_pdu(const std::function<bool (const json::object &)> &);
|
||||
};
|
||||
|
||||
/// Evaluation faults. These are reasons which evaluation has halted but may
|
||||
|
|
66
ircd/m.cc
66
ircd/m.cc
|
@ -972,6 +972,72 @@ decltype(ircd::m::vm::eval::id_ctr)
|
|||
ircd::m::vm::eval::id_ctr
|
||||
{};
|
||||
|
||||
bool
|
||||
ircd::m::vm::eval::for_each_pdu(const std::function<bool (const json::object &)> &closure)
|
||||
{
|
||||
return for_each([&closure](eval &e)
|
||||
{
|
||||
for(const json::object &pdu : e.pdus)
|
||||
if(!closure(pdu))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
ircd::m::vm::eval &
|
||||
ircd::m::vm::eval::get(const event::id &event_id)
|
||||
{
|
||||
auto *const ret
|
||||
{
|
||||
find(event_id)
|
||||
};
|
||||
|
||||
if(unlikely(!ret))
|
||||
throw std::out_of_range
|
||||
{
|
||||
"eval::get(): event_id not being evaluated."
|
||||
};
|
||||
|
||||
return *ret;
|
||||
}
|
||||
|
||||
ircd::m::vm::eval *
|
||||
ircd::m::vm::eval::find(const event::id &event_id)
|
||||
{
|
||||
eval *ret{nullptr};
|
||||
for_each([&event_id, &ret](eval &e)
|
||||
{
|
||||
if(e.event_)
|
||||
{
|
||||
if(json::get<"event_id"_>(*e.event_) == event_id)
|
||||
ret = &e;
|
||||
}
|
||||
else if(e.issue)
|
||||
{
|
||||
if(e.issue->has("event_id"))
|
||||
if(string_view{e.issue->at("event_id")} == event_id)
|
||||
ret = &e;
|
||||
}
|
||||
else if(e.event_id == event_id)
|
||||
ret = &e;
|
||||
|
||||
return ret == nullptr;
|
||||
});
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool
|
||||
ircd::m::vm::eval::for_each(const std::function<bool (eval &)> &closure)
|
||||
{
|
||||
for(eval *const &eval : eval::list)
|
||||
if(!closure(*eval))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
//
|
||||
// eval::eval
|
||||
//
|
||||
|
|
Loading…
Reference in a new issue