6 #include "CatalogBinding.h"
7 #include "MessageQueue.h"
17 virtual void Dispatch() = 0;
20 template <
typename TMessageCatalog>
24 template <
typename TMessage>
29 TMessageCatalog& m_catalog;
31 TypedMessageInfo(
const TMessage& message, TMessageCatalog& catalog)
40 binding.Dispatch(m_message);
44 template<
typename TMessage>
47 typedef char (&NotHandled)[1];
48 typedef char (&Handled)[2];
50 static NotHandled CheckImplements(...);
51 static const bool IsHandled =
sizeof(CheckImplements(static_cast<TMessageCatalog*>(0))) ==
sizeof(Handled);
54 template<
bool Condition,
typename ReturnType =
void>
57 typedef ReturnType rt;
60 template<
typename ReturnType>
61 struct Conditional<false, ReturnType> { };
63 template<
typename TMessage>
64 typename Conditional<HandlesMessage<TMessage>::IsHandled>::rt EnqueueIfHandled(
const TMessage& message)
67 m_messages.Enqueue(
new TypedMessageInfo<TMessage>(message, m_catalog));
70 template<
typename TMessage>
71 typename Conditional<!HandlesMessage<TMessage>::IsHandled>::rt EnqueueIfHandled(
const TMessage& message)
76 TMessageCatalog m_catalog;
81 template <
typename TMessage>
82 void TryEnqueue(
const TMessage& message)
84 EnqueueIfHandled(message);
87 template <
typename TMessage>
91 binding.Subscribe(handler);
94 template <
typename TMessage>
98 binding.Unsubscribe(handler);
104 while (m_messages.TryDequeue(info))