11#include "comms/details/dispatch_impl.h"
12#include "comms/details/tag.h"
19COMMS_MSVC_WARNING_PUSH
20COMMS_MSVC_WARNING_DISABLE(4100)
37 typename TAllMessages,
42 details::MessageInterfaceDispatchRetType<
43 typename std::decay<
decltype(handler)>::type>
45 using MsgType =
typename std::decay<
decltype(msg)>::type;
46 static_assert(comms::isMessage<MsgType>(),
"msg param must be a valid message");
48 details::DispatchMsgPolymorphicHelper<>::template
49 dispatch<TAllMessages>(std::forward<TId>(
id), msg, handler);
65 typename TAllMessages,
70 details::MessageInterfaceDispatchRetType<
71 typename std::decay<
decltype(handler)>::type>
73 using MsgType =
typename std::decay<
decltype(msg)>::type;
74 static_assert(comms::isMessage<MsgType>(),
"msg param must be a valid message");
76 details::DispatchMsgPolymorphicHelper<>::template
77 dispatch<TAllMessages>(std::forward<TId>(
id), index, msg, handler);
91 typename TAllMessages,
95 details::MessageInterfaceDispatchRetType<
96 typename std::decay<
decltype(handler)>::type>
98 using MsgType =
typename std::decay<
decltype(msg)>::type;
99 static_assert(comms::isMessage<MsgType>(),
"msg param must be a valid message");
101 details::DispatchMsgPolymorphicHelper<>::template
102 dispatch<TAllMessages>(msg, handler);
117 typename TAllMessages,
123 details::DispatchMsgTypePolymorphicHelper<>::template
124 dispatch<TAllMessages>(std::forward<TId>(
id), handler);
140 typename TAllMessages,
146 details::DispatchMsgTypePolymorphicHelper<>::template
147 dispatch<TAllMessages>(std::forward<TId>(
id), index, handler);
163 typename TAllMessages,
168 details::MessageInterfaceDispatchRetType<
169 typename std::decay<
decltype(handler)>::type>
171 static_assert(details::allMessagesHaveStaticNumId<TAllMessages>(),
172 "All messages in the provided tuple must statically define their numeric ID");
175 details::DispatchMsgStaticBinSearchHelper<>::template dispatch<TAllMessages>(
176 std::forward<TId>(
id),
194 typename TAllMessages,
199 details::MessageInterfaceDispatchRetType<
200 typename std::decay<
decltype(handler)>::type>
202 static_assert(details::allMessagesHaveStaticNumId<TAllMessages>(),
203 "All messages in the provided tuple must statically define their numeric ID");
206 details::DispatchMsgStaticBinSearchHelper<>::template dispatch<TAllMessages>(
207 std::forward<TId>(
id),
223 typename TAllMessages,
227 details::MessageInterfaceDispatchRetType<
228 typename std::decay<
decltype(handler)>::type>
230 static_assert(details::allMessagesHaveStaticNumId<TAllMessages>(),
231 "All messages in the provided tuple must statically define their numeric ID");
232 using MsgType =
typename std::decay<
decltype(msg)>::type;
233 static_assert(MsgType::hasGetId(),
234 "The used message object must provide polymorphic ID retrieval function");
237 details::DispatchMsgStaticBinSearchHelper<>::template dispatch<TAllMessages>(
254 typename TAllMessages,
259 static_assert(details::allMessagesHaveStaticNumId<TAllMessages>(),
260 "All messages in the provided tuple must statically define their numeric ID");
263 details::DispatchMsgStaticBinSearchHelper<>::template
264 dispatchType<TAllMessages>(std::forward<TId>(
id), handler);
280 typename TAllMessages,
285 static_assert(details::allMessagesHaveStaticNumId<TAllMessages>(),
286 "All messages in the provided tuple must statically define their numeric ID");
289 details::DispatchMsgStaticBinSearchHelper<>::template
290 dispatchType<TAllMessages>(std::forward<TId>(
id), index, handler);
299template <
typename TAllMessages,
typename TId>
302 static_assert(details::allMessagesHaveStaticNumId<TAllMessages>(),
303 "All messages in the provided tuple must statically define their numeric ID");
306 details::DispatchMsgStaticBinSearchHelper<>::template
307 dispatchTypeCount<TAllMessages>(std::forward<TId>(
id));
322 typename TAllMessages,
327 details::MessageInterfaceDispatchRetType<
328 typename std::decay<
decltype(handler)>::type>
330 static_assert(details::allMessagesHaveStaticNumId<TAllMessages>(),
331 "All messages in the provided tuple must statically define their numeric ID");
334 details::DispatchMsgLinearSwitchHelper<>::template dispatch<TAllMessages>(
335 std::forward<TId>(
id),
353 typename TAllMessages,
358 details::MessageInterfaceDispatchRetType<
359 typename std::decay<
decltype(handler)>::type>
361 static_assert(details::allMessagesHaveStaticNumId<TAllMessages>(),
362 "All messages in the provided tuple must statically define their numeric ID");
365 details::DispatchMsgLinearSwitchHelper<>::template dispatch<TAllMessages>(
366 std::forward<TId>(
id),
383 typename TAllMessages,
387 details::MessageInterfaceDispatchRetType<
388 typename std::decay<
decltype(handler)>::type>
390 static_assert(details::allMessagesHaveStaticNumId<TAllMessages>(),
391 "All messages in the provided tuple must statically define their numeric ID");
392 using MsgType =
typename std::decay<
decltype(msg)>::type;
393 static_assert(MsgType::hasGetId(),
394 "The used message object must provide polymorphic ID retrieval function");
397 details::DispatchMsgLinearSwitchHelper<>::template dispatch<TAllMessages>(
414 typename TAllMessages,
419 static_assert(details::allMessagesHaveStaticNumId<TAllMessages>(),
420 "All messages in the provided tuple must statically define their numeric ID");
423 details::DispatchMsgLinearSwitchHelper<>::template
424 dispatchType<TAllMessages>(std::forward<TId>(
id), handler);
440 typename TAllMessages,
445 static_assert(details::allMessagesHaveStaticNumId<TAllMessages>(),
446 "All messages in the provided tuple must statically define their numeric ID");
449 details::DispatchMsgLinearSwitchHelper<>::template
450 dispatchType<TAllMessages>(std::forward<TId>(
id), index, handler);
459template <
typename TMsg,
typename THandler>
462 return details::dispatchMsgPolymorphicIsCompatibleHandler<typename std::decay<TMsg>::type,
typename std::decay<THandler>::type>();
472template <
typename TMsg,
typename THandler>
475 return dispatchMsgIsDirect<
typename std::decay<
decltype(msg)>::type,
typename std::decay<
decltype(handler)>::type>();
480template <
typename TAllMessages>
481class DispatchMsgHelper
484 template <
typename TMsg,
typename THandler>
485 static auto dispatchMsg(TMsg& msg, THandler& handler) ->
486 MessageInterfaceDispatchRetType<
487 typename std::decay<
decltype(handler)>::type>
489 return dispatchMsgInternal(msg, handler, HandlerAdjustedTag<TMsg, THandler>());
492 template <
typename TId,
typename TMsg,
typename THandler>
493 static auto dispatchMsg(TId&&
id, TMsg& msg, THandler& handler) ->
494 MessageInterfaceDispatchRetType<
495 typename std::decay<
decltype(handler)>::type>
497 return dispatchMsgInternal(std::forward<TId>(
id), msg, handler, HandlerAdjustedTag<TMsg, THandler>());
500 template <
typename TId,
typename TMsg,
typename THandler>
501 static auto dispatchMsg(TId&&
id, std::size_t index, TMsg& msg, THandler& handler) ->
502 MessageInterfaceDispatchRetType<
503 typename std::decay<
decltype(handler)>::type>
505 return dispatchMsgInternal(std::forward<TId>(
id), index, msg, handler, HandlerAdjustedTag<TMsg, THandler>());
508 template <
typename TId,
typename THandler>
511 return dispatchMsgTypeInternal(std::forward<TId>(
id), handler, Tag<>());
514 template <
typename TId,
typename THandler>
515 static bool dispatchMsgType(TId&&
id, std::size_t index, THandler& handler)
517 return dispatchMsgTypeInternal(std::forward<TId>(
id), index, handler, Tag<>());
520 static constexpr bool isPolymorphic()
522 return std::is_same<Tag<>, PolymorphicTag<> >::value;
525 static constexpr bool isStaticBinSearch()
527 return std::is_same<Tag<>, StaticBinSearchTag<> >::value;
530 template <
typename TMsg,
typename THandler>
531 static constexpr bool isDirect()
533 return dispatchMsgIsDirect<TMsg, THandler>();
536 template <
typename TMsg,
typename THandler>
537 static constexpr bool isDirect(TMsg&& msg, THandler&& handler)
539 return isDirect<
typename std::decay<
decltype(msg)>::type,
typename std::decay<
decltype(handler)>::type>();
543 template <
typename... TParams>
544 using PolymorphicTag = comms::details::tag::Tag1<>;
546 template <
typename... TParams>
547 using StaticBinSearchTag = comms::details::tag::Tag2<>;
549 template <
typename...>
551 typename comms::util::LazyShallowConditional<
552 dispatchMsgPolymorphicIsDirectSuitable<TAllMessages>() || (!allMessagesHaveStaticNumId<TAllMessages>())
558 template <
typename TMsgBase,
typename THandler>
559 using HandlerAdjustedTag =
560 typename comms::util::LazyShallowConditional<
561 dispatchMsgIsDirect<TMsgBase, THandler>()
567 template <
typename TMsg,
typename THandler,
typename... TParams>
568 static auto dispatchMsgInternal(TMsg& msg, THandler& handler, PolymorphicTag<TParams...>) ->
569 MessageInterfaceDispatchRetType<
570 typename std::decay<
decltype(handler)>::type>
572 return comms::dispatchMsgPolymorphic<TAllMessages>(msg, handler);
575 template <
typename TMsg,
typename THandler,
typename... TParams>
576 static auto dispatchMsgInternal(TMsg& msg, THandler& handler, StaticBinSearchTag<TParams...>) ->
577 MessageInterfaceDispatchRetType<
578 typename std::decay<
decltype(handler)>::type>
580 return comms::dispatchMsgStaticBinSearch<TAllMessages>(msg, handler);
583 template <
typename TId,
typename TMsg,
typename THandler,
typename... TParams>
584 static auto dispatchMsgInternal(TId&&
id, TMsg& msg, THandler& handler, PolymorphicTag<TParams...>) ->
585 MessageInterfaceDispatchRetType<
586 typename std::decay<
decltype(handler)>::type>
588 return comms::dispatchMsgPolymorphic<TAllMessages>(std::forward<TId>(
id), msg, handler);
591 template <
typename TId,
typename TMsg,
typename THandler,
typename... TParams>
592 static auto dispatchMsgInternal(TId&&
id, TMsg& msg, THandler& handler, StaticBinSearchTag<TParams...>) ->
593 MessageInterfaceDispatchRetType<
594 typename std::decay<
decltype(handler)>::type>
596 return comms::dispatchMsgStaticBinSearch<TAllMessages>(std::forward<TId>(
id), msg, handler);
599 template <
typename TId,
typename TMsg,
typename THandler,
typename... TParams>
600 static auto dispatchMsgInternal(TId&&
id, std::size_t index, TMsg& msg, THandler& handler, PolymorphicTag<TParams...>) ->
601 MessageInterfaceDispatchRetType<
602 typename std::decay<
decltype(handler)>::type>
604 return comms::dispatchMsgPolymorphic<TAllMessages>(std::forward<TId>(
id), index, msg, handler);
607 template <
typename TId,
typename TMsg,
typename THandler,
typename... TParams>
608 static auto dispatchMsgInternal(TId&&
id, std::size_t index, TMsg& msg, THandler& handler, StaticBinSearchTag<TParams...>) ->
609 MessageInterfaceDispatchRetType<
610 typename std::decay<
decltype(handler)>::type>
612 return comms::dispatchMsgStaticBinSearch<TAllMessages>(std::forward<TId>(
id), index, msg, handler);
615 template <
typename TId,
typename THandler,
typename... TParams>
616 static bool dispatchMsgTypeInternal(TId&&
id, THandler& handler, PolymorphicTag<TParams...>)
618 return comms::dispatchMsgTypePolymorphic<TAllMessages>(std::forward<TId>(
id), handler);
621 template <
typename TId,
typename THandler,
typename... TParams>
622 static bool dispatchMsgTypeInternal(TId&&
id, THandler& handler, StaticBinSearchTag<TParams...>)
624 return comms::dispatchMsgTypeStaticBinSearch<TAllMessages>(std::forward<TId>(
id), handler);
627 template <
typename TId,
typename THandler,
typename... TParams>
628 static bool dispatchMsgTypeInternal(TId&&
id, std::size_t index, THandler& handler, PolymorphicTag<TParams...>)
630 return comms::dispatchMsgTypePolymorphic<TAllMessages>(std::forward<TId>(
id), index, handler);
633 template <
typename TId,
typename THandler,
typename... TParams>
634 static bool dispatchMsgTypeInternal(TId&&
id, std::size_t index, THandler& handler, StaticBinSearchTag<TParams...>)
636 return comms::dispatchMsgTypeStaticBinSearch<TAllMessages>(std::forward<TId>(
id), index, handler);
660 typename TAllMessages,
665 details::MessageInterfaceDispatchRetType<
666 typename std::decay<
decltype(handler)>::type>
668 return details::DispatchMsgHelper<TAllMessages>::dispatchMsg(std::forward<TId>(
id), msg, handler);
690 typename TAllMessages,
694auto dispatchMsg(TId&&
id, std::size_t index, TMsg& msg, THandler& handler) ->
695 details::MessageInterfaceDispatchRetType<
696 typename std::decay<
decltype(handler)>::type>
698 return details::DispatchMsgHelper<TAllMessages>::dispatchMsg(std::forward<TId>(
id), index, msg, handler);
718 typename TAllMessages,
722 details::MessageInterfaceDispatchRetType<
723 typename std::decay<
decltype(handler)>::type>
725 return details::DispatchMsgHelper<TAllMessages>::dispatchMsg(msg, handler);
744template <
typename TAllMessages,
typename TId,
typename THandler>
747 return details::DispatchMsgHelper<TAllMessages>::dispatchMsgType(std::forward<TId>(
id), handler);
767template <
typename TAllMessages,
typename TId,
typename THandler>
770 return details::DispatchMsgHelper<TAllMessages>::dispatchMsgType(std::forward<TId>(
id), index, handler);
779template <
typename TAllMessages>
782 return details::DispatchMsgHelper<TAllMessages>::isPolymorphic();
794template <
typename TAllMessages,
typename TMsg,
typename THandler>
797 return dispatchMsgIsDirect<TMsg, THandler>() || dispatchMsgTypeIsPolymorphic<TAllMessages>();
807template <
typename TAllMessages,
typename TMsg,
typename THandler>
810 return dispatchMsgIsPolymorphic<TAllMessages,
typename std::decay<
decltype(msg)>::type,
typename std::decay<
decltype(handler)>::type>();
819template <
typename TAllMessages>
822 return details::DispatchMsgHelper<TAllMessages>::isStaticBinSearch();
834template <
typename TAllMessages,
typename TMsg,
typename THandler>
837 return (!dispatchMsgIsDirect<TMsg, THandler>()) &&
838 dispatchMsgTypeIsStaticBinSearch<TAllMessages>();
848template <
typename TAllMessages,
typename TMsg,
typename THandler>
851 return dispatchMsgIsStaticBinSearch<TAllMessages,
typename std::decay<
decltype(msg)>::type,
typename std::decay<
decltype(handler)>::type>();
856COMMS_MSVC_WARNING_POP
Contains various compiler related definitions.
Contains definition of Message object interface and various base classes for custom messages.
Main namespace for all classes / functions of COMMS library.
constexpr bool dispatchMsgIsPolymorphic()
Compile time check whether the dispatchMsg() will use "polymorphic" (including "direct") dispatch for...
Definition dispatch.h:795
constexpr bool dispatchMsgIsDirect()
Compile time check whether the message object can use its own polymorphic dispatch() (see Polymorphic...
Definition dispatch.h:460
auto dispatchMsg(TId &&id, TMsg &msg, THandler &handler) -> details::MessageInterfaceDispatchRetType< typename std::decay< decltype(handler)>::type >
Dispatch message object into appropriate handle() function in the provided handler using either "poly...
Definition dispatch.h:664
auto dispatchMsgStaticBinSearch(TId &&id, std::size_t index, TMsg &msg, THandler &handler) -> details::MessageInterfaceDispatchRetType< typename std::decay< decltype(handler)>::type >
Dispatch message object into appropriate handle() function in the provided handler using static binar...
Definition dispatch.h:167
bool dispatchMsgTypePolymorphic(TId &&id, THandler &handler)
Dispatch message id into appropriate handle() function in the provided handler using polymorphic beha...
Definition dispatch.h:120
std::size_t dispatchMsgTypeCountStaticBinSearch(TId &&id)
Count number of message types in the provided tuple that have the requested numeric ID.
Definition dispatch.h:300
bool dispatchMsgTypeLinearSwitch(TId &&id, THandler &handler)
Dispatch message id into appropriate handle() function in the provided handler using linear switch be...
Definition dispatch.h:417
constexpr bool dispatchMsgIsStaticBinSearch()
Compile time check whether the dispatchMsg() will use "static binary search" dispatch for provided tu...
Definition dispatch.h:835
constexpr bool dispatchMsgTypeIsPolymorphic()
Compile time check whether the dispatchMsgType() will use "polymorphic" dispatch for provided tuple o...
Definition dispatch.h:780
constexpr bool dispatchMsgTypeIsStaticBinSearch()
Compile time check whether the dispatchMsgType() or dispatchMsgType() will use "static binary search"...
Definition dispatch.h:820
auto dispatchMsgPolymorphic(TId &&id, TMsg &msg, THandler &handler) -> details::MessageInterfaceDispatchRetType< typename std::decay< decltype(handler)>::type >
Dispatch message object into appropriate handle() function in the provided handler using polymorphic ...
Definition dispatch.h:41
auto dispatchMsgLinearSwitch(TId &&id, TMsg &msg, THandler &handler) -> details::MessageInterfaceDispatchRetType< typename std::decay< decltype(handler)>::type >
Dispatch message object into appropriate handle() function in the provided handler using linear switc...
Definition dispatch.h:326
bool dispatchMsgType(TId &&id, THandler &handler)
Dispatch message id into appropriate handle() function in the provided handler using either "polymorp...
Definition dispatch.h:745
bool dispatchMsgTypeStaticBinSearch(TId &&id, THandler &handler)
Dispatch message id into appropriate handle() function in the provided handler using static binary se...
Definition dispatch.h:257
Replacement to some types from standard type_traits.