33#ifndef __H__UG__message_hub_impl__
34#define __H__UG__message_hub_impl__
47 typedef void (*FuncCallback)(
const IMessage&);
49 return register_callback_impl<TMsg>((FuncCallback)callback, autoFree);
53template <
class TMsg,
class TClass>
56 void (TClass::*callback)(const TMsg&),
59 typedef void (TClass::*ClassCallback)(
const IMessage&);
61 return register_callback_impl<TMsg>(
63 [callback, cls](
const IMessage& msg) {
64 auto const& derived =
static_cast<const TMsg&
>(msg);
65 (cls->*callback)(derived);
76 size_t id = GetUniqueTypeID<TMsg>();
79 for(CallbackEntryList::iterator iter = callbacks.begin();
80 iter != callbacks.end(); ++iter)
82 iter->m_callback(msg);
92 size_t id = GetUniqueTypeID<TMsg>();
99 cbIter->m_callbackId = cbId;
The callback-id allows to deregister previously registered callbacks.
Definition message_hub.h:147
This is the base class of all messages, which may be passed to callbacks.
Definition message_hub.h:132
SPCallbackId register_callback_impl(std::function< void(const IMessage &)> callback, bool autoFree)
registers a callback given a message-id.
Definition message_hub_impl.hpp:89
CallbackEntryList::iterator CallbackEntryIterator
Definition message_hub.h:102
CallbackMap m_callbackMap
given a msg-type-id, this map returns a list of associated callbacks
Definition message_hub.h:245
std::list< CallbackEntry > CallbackEntryList
Definition message_hub.h:101
void post_message(const TMsg &msg)
Posts a message to all callbacks which are registered for the given message tpye.
Definition message_hub_impl.hpp:73
SmartPtr< CallbackId > SPCallbackId
Definition message_hub.h:165
SPCallbackId register_class_callback(TClass *cls, void(TClass::*callback)(const TMsg &), bool autoFree=true)
registers a method callback given a message-type.
Definition message_hub_impl.hpp:55
SPCallbackId register_function_callback(void(*callback)(const TMsg &), bool autoFree=false)
registers a function callback given a message-type.
Definition message_hub_impl.hpp:44
The CallbackEntry holds the actual callback and the associated callback-id.
Definition message_hub.h:95