4#ifndef MALENA_HOOKABLE_H
5#define MALENA_HOOKABLE_H
17 template<
typename C,
typename R,
typename A>
18 struct cb_arg<R(C::*)(A) const> {
using type = std::decay_t<A>; };
19 template<
typename C,
typename R,
typename A>
20 struct cb_arg<R(C::*)(A)> {
using type = std::decay_t<A>; };
46 template<
typename Enum>
51 template<
typename Enum,
typename Callback>
55 [cb = std::forward<Callback>(cb)](
Hookable* w) {
56 if constexpr (std::is_same_v<T, Hookable>) {
59 if (
auto* p =
dynamic_cast<T*
>(w))
Trait that adds typed, enum-keyed message sending and receiving to any class.
void sendMessage(Enum event, const DataType &data)
Publish a typed message to all current subscribers.
void onMessage(Enum event, std::function< void(const DataType &)> callback)
Register a callback to receive a typed message.
std::function< void()> Callback
Callback type for no-argument event handlers.
typename detail::cb_arg< decltype(&std::decay_t< F >::operator())>::type cb_arg_t
Trait that layers a hook system on top of ml::Messenger.
virtual ~Hookable()=default
void onHook(Enum hook, Callback &&cb)