mirror of
https://github.com/matrix-construct/construct
synced 2024-09-27 11:18:51 +02:00
ircd:Ⓜ️:vm::eval: Minor static interface reorg.
This commit is contained in:
parent
69cd2608ac
commit
13003986bc
2 changed files with 65 additions and 65 deletions
|
@ -93,10 +93,6 @@ struct ircd::m::vm::eval
|
|||
vm::phase phase {vm::phase(0)};
|
||||
bool room_internal {false};
|
||||
|
||||
static bool for_each_pdu(const std::function<bool (const event &)> &);
|
||||
static const event *find_pdu(const eval &, const event::id &);
|
||||
static const event *find_pdu(const event::id &);
|
||||
|
||||
void mfetch_keys() const;
|
||||
|
||||
public:
|
||||
|
@ -120,11 +116,16 @@ struct ircd::m::vm::eval
|
|||
~eval() noexcept;
|
||||
|
||||
static bool for_each(const ctx::ctx *const &, const std::function<bool (eval &)> &);
|
||||
static bool for_each(const std::function<bool (eval &)> &);
|
||||
static size_t count(const ctx::ctx *const &);
|
||||
|
||||
static bool for_each(const std::function<bool (eval &)> &);
|
||||
static bool for_each_pdu(const std::function<bool (const event &)> &);
|
||||
static const event *find_pdu(const eval &, const event::id &);
|
||||
static const event *find_pdu(const event::id &);
|
||||
static size_t count(const event::id &);
|
||||
static eval *find(const event::id &);
|
||||
static eval &get(const event::id &);
|
||||
|
||||
static bool sequnique(const uint64_t &seq);
|
||||
static eval *seqnext(const uint64_t &seq);
|
||||
static eval *seqmax();
|
||||
|
|
|
@ -197,16 +197,60 @@ ircd::m::vm::eval::count(const event::id &event_id)
|
|||
return ret;
|
||||
}
|
||||
|
||||
size_t
|
||||
ircd::m::vm::eval::count(const ctx::ctx *const &c)
|
||||
const ircd::m::event *
|
||||
ircd::m::vm::eval::find_pdu(const event::id &event_id)
|
||||
{
|
||||
return std::count_if(begin(eval::list), end(eval::list), [&c]
|
||||
(const eval *const &eval)
|
||||
const m::event *ret{nullptr};
|
||||
for_each_pdu([&ret, &event_id]
|
||||
(const m::event &event)
|
||||
{
|
||||
return eval->ctx == c;
|
||||
if(event.event_id != event_id)
|
||||
return true;
|
||||
|
||||
ret = std::addressof(event);
|
||||
return false;
|
||||
});
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
const ircd::m::event *
|
||||
ircd::m::vm::eval::find_pdu(const eval &eval,
|
||||
const event::id &event_id)
|
||||
{
|
||||
const m::event *ret{nullptr};
|
||||
for(const auto &event : eval.pdus)
|
||||
{
|
||||
if(event.event_id != event_id)
|
||||
continue;
|
||||
|
||||
ret = std::addressof(event);
|
||||
break;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool
|
||||
ircd::m::vm::eval::for_each_pdu(const std::function<bool (const event &)> &closure)
|
||||
{
|
||||
return for_each([&closure](eval &e)
|
||||
{
|
||||
if(!empty(e.pdus))
|
||||
{
|
||||
for(const auto &pdu : e.pdus)
|
||||
if(!closure(pdu))
|
||||
return false;
|
||||
}
|
||||
else if(e.event_)
|
||||
{
|
||||
if(!closure(*e.event_))
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
});
|
||||
}
|
||||
bool
|
||||
ircd::m::vm::eval::for_each(const std::function<bool (eval &)> &closure)
|
||||
{
|
||||
|
@ -217,6 +261,16 @@ ircd::m::vm::eval::for_each(const std::function<bool (eval &)> &closure)
|
|||
return true;
|
||||
}
|
||||
|
||||
size_t
|
||||
ircd::m::vm::eval::count(const ctx::ctx *const &c)
|
||||
{
|
||||
return std::count_if(begin(eval::list), end(eval::list), [&c]
|
||||
(const eval *const &eval)
|
||||
{
|
||||
return eval->ctx == c;
|
||||
});
|
||||
}
|
||||
|
||||
bool
|
||||
ircd::m::vm::eval::for_each(const ctx::ctx *const &c,
|
||||
const std::function<bool (eval &)> &closure)
|
||||
|
@ -411,58 +465,3 @@ const
|
|||
this->pdus.size(),
|
||||
};
|
||||
}
|
||||
|
||||
const ircd::m::event *
|
||||
ircd::m::vm::eval::find_pdu(const event::id &event_id)
|
||||
{
|
||||
const m::event *ret{nullptr};
|
||||
for_each_pdu([&ret, &event_id]
|
||||
(const m::event &event)
|
||||
{
|
||||
if(event.event_id != event_id)
|
||||
return true;
|
||||
|
||||
ret = std::addressof(event);
|
||||
return false;
|
||||
});
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
const ircd::m::event *
|
||||
ircd::m::vm::eval::find_pdu(const eval &eval,
|
||||
const event::id &event_id)
|
||||
{
|
||||
const m::event *ret{nullptr};
|
||||
for(const auto &event : eval.pdus)
|
||||
{
|
||||
if(event.event_id != event_id)
|
||||
continue;
|
||||
|
||||
ret = std::addressof(event);
|
||||
break;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool
|
||||
ircd::m::vm::eval::for_each_pdu(const std::function<bool (const event &)> &closure)
|
||||
{
|
||||
return for_each([&closure](eval &e)
|
||||
{
|
||||
if(!empty(e.pdus))
|
||||
{
|
||||
for(const auto &pdu : e.pdus)
|
||||
if(!closure(pdu))
|
||||
return false;
|
||||
}
|
||||
else if(e.event_)
|
||||
{
|
||||
if(!closure(*e.event_))
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue