0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-06-09 13:38:55 +02:00

ircd:Ⓜ️🪝 Add callsite overloads which maintain pointer to current hfn.

This commit is contained in:
Jason Volk 2020-05-12 16:12:48 -07:00
parent 38a12ec0f7
commit adde714df4
2 changed files with 48 additions and 4 deletions

View file

@ -132,6 +132,7 @@ final
void call(hook<void> &, const event &);
public:
void operator()(base **const &, const event &);
void operator()(const event &);
site(const json::members &feature);
@ -164,6 +165,7 @@ struct ircd::m::hook::site
void call(hook<data> &hfn, const event &event, data d);
public:
void operator()(base **const &, const event &event, data d);
void operator()(const event &event, data d);
site(const json::members &feature)
@ -176,10 +178,32 @@ void
ircd::m::hook::site<data>::operator()(const event &event,
data d)
{
match(event, [this, &event, &d]
base *cur {nullptr};
operator()(&cur, event, std::forward<data>(d));
}
template<class data>
void
ircd::m::hook::site<data>::operator()(base **const &cur,
const event &event,
data d)
{
// Iterate all matching hooks
match(event, [this, &cur, &event, &d]
(base &base)
{
call(dynamic_cast<hook<data> &>(base), event, d);
// Indicate which hook we're entering
const scope_restore entered
{
*cur, std::addressof(base)
};
auto &hfn
{
dynamic_cast<hook<data> &>(base)
};
call(hfn, event, d);
return true;
});
}

View file

@ -507,10 +507,30 @@ ircd::m::hook::site<void>::site(const json::members &feature)
void
ircd::m::hook::site<void>::operator()(const event &event)
{
match(event, [this, &event]
base *cur {nullptr};
operator()(&cur, event);
}
void
ircd::m::hook::site<void>::operator()(base **const &cur,
const event &event)
{
// Iterate all matching hooks
match(event, [this, &cur, &event]
(base &base)
{
call(dynamic_cast<hook<void> &>(base), event);
// Indicate which hook we're entering
const scope_restore entered
{
*cur, std::addressof(base)
};
auto &hfn
{
dynamic_cast<hook<void> &>(base)
};
call(hfn, event);
return true;
});
}