5#include <Foundation/Basics.h>
6#include <Foundation/Reflection/Implementation/RTTI.h>
16 PL_ALWAYS_INLINE
void operator()(
void* pInstance,
plMessage& ref_msg) { (*m_DispatchFunc)(
this, pInstance, ref_msg); }
18 PL_FORCE_INLINE
void operator()(
const void* pInstance,
plMessage& ref_msg)
20 PL_ASSERT_DEV(m_bIsConst,
"Calling a non const message handler with a const instance.");
21 (*m_ConstDispatchFunc)(
this, pInstance, ref_msg);
24 PL_ALWAYS_INLINE plMessageId GetMessageId()
const {
return m_Id; }
26 PL_ALWAYS_INLINE
bool IsConst()
const {
return m_bIsConst; }
34 DispatchFunc m_DispatchFunc =
nullptr;
35 ConstDispatchFunc m_ConstDispatchFunc;
37 plMessageId m_Id = plSmallInvalidIndex;
38 bool m_bIsConst =
false;
44 const plRTTI* m_pMessageType;
49 template <
typename Class,
typename MessageType>
52 static plCompileTimeTrueType IsConst(
void (Class::*)(MessageType&)
const);
53 static plCompileTimeFalseType IsConst(...);
56 template <
bool bIsConst>
59 template <
typename Class,
typename MessageType,
void (Class::*Method)(MessageType&)>
65 m_DispatchFunc = &Dispatch;
66 m_Id = MessageType::GetTypeMsgId();
72 Class* pTargetInstance =
static_cast<Class*
>(pInstance);
73 (pTargetInstance->*Method)(
static_cast<MessageType&
>(ref_msg));
81 template <
typename Class,
typename MessageType,
void (Class::*Method)(MessageType&) const>
87 m_ConstDispatchFunc = &Dispatch;
88 m_Id = MessageType::GetTypeMsgId();
95 const Class* pTargetInstance =
static_cast<const Class*
>(pInstance);
96 (pTargetInstance->*Method)(
static_cast<MessageType&
>(ref_msg));
102#define PL_IS_CONST_MESSAGE_HANDLER(Class, MessageType, Method) \
103 (sizeof(plInternal::MessageHandlerTraits<Class, MessageType>::IsConst(Method)) == sizeof(plCompileTimeTrueType))
The base class for all message handlers that a type provides.
Definition MessageHandler.h:12
Definition MessageHandler.h:61
Definition MessageHandler.h:83
static void Dispatch(plAbstractMessageHandler *pSelf, const void *pInstance, plMessage &ref_msg)
Casts the given message to the type of this message handler, then passes that to the class instance.
Definition MessageHandler.h:93
Base class for all message types. Each message type has it's own id which is used to dispatch message...
Definition Message.h:22
This class holds information about reflected types. Each instance represents one type that is known t...
Definition RTTI.h:30
Definition MessageHandler.h:58
Definition MessageHandler.h:51
Definition MessageHandler.h:42