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");
366 details::DispatchMsgLinearSwitchHelper<>::template dispatch<TAllMessages>(
367 std::forward<TId>(
id),
384 typename TAllMessages,
388 details::MessageInterfaceDispatchRetType<
389 typename std::decay<
decltype(handler)>::type>
391 static_assert(details::allMessagesHaveStaticNumId<TAllMessages>(),
392 "All messages in the provided tuple must statically define their numeric ID");
393 using MsgType =
typename std::decay<
decltype(msg)>::type;
394 static_assert(MsgType::hasGetId(),
395 "The used message object must provide polymorphic ID retrieval function");
398 details::DispatchMsgLinearSwitchHelper<>::template dispatch<TAllMessages>(
415 typename TAllMessages,
420 static_assert(details::allMessagesHaveStaticNumId<TAllMessages>(),
421 "All messages in the provided tuple must statically define their numeric ID");
424 details::DispatchMsgLinearSwitchHelper<>::template
425 dispatchType<TAllMessages>(std::forward<TId>(
id), handler);
441 typename TAllMessages,
446 static_assert(details::allMessagesHaveStaticNumId<TAllMessages>(),
447 "All messages in the provided tuple must statically define their numeric ID");
450 details::DispatchMsgLinearSwitchHelper<>::template
451 dispatchType<TAllMessages>(std::forward<TId>(
id), index, handler);
460template <
typename TMsg,
typename THandler>
463 return details::dispatchMsgPolymorphicIsCompatibleHandler<typename std::decay<TMsg>::type,
typename std::decay<THandler>::type>();
473template <
typename TMsg,
typename THandler>
476 return dispatchMsgIsDirect<
typename std::decay<
decltype(msg)>::type,
typename std::decay<
decltype(handler)>::type>();
481template <
typename TAllMessages>
482class DispatchMsgHelper
485 template <
typename TMsg,
typename THandler>
486 static auto dispatchMsg(TMsg& msg, THandler& handler) ->
487 MessageInterfaceDispatchRetType<
488 typename std::decay<
decltype(handler)>::type>
490 return dispatchMsgInternal(msg, handler, HandlerAdjustedTag<TMsg, THandler>());
493 template <
typename TId,
typename TMsg,
typename THandler>
494 static auto dispatchMsg(TId&&
id, TMsg& msg, THandler& handler) ->
495 MessageInterfaceDispatchRetType<
496 typename std::decay<
decltype(handler)>::type>
498 return dispatchMsgInternal(std::forward<TId>(
id), msg, handler, HandlerAdjustedTag<TMsg, THandler>());
501 template <
typename TId,
typename TMsg,
typename THandler>
502 static auto dispatchMsg(TId&&
id, std::size_t index, TMsg& msg, THandler& handler) ->
503 MessageInterfaceDispatchRetType<
504 typename std::decay<
decltype(handler)>::type>
506 return dispatchMsgInternal(std::forward<TId>(
id), index, msg, handler, HandlerAdjustedTag<TMsg, THandler>());
509 template <
typename TId,
typename THandler>
512 return dispatchMsgTypeInternal(std::forward<TId>(
id), handler, Tag<>());
515 template <
typename TId,
typename THandler>
516 static bool dispatchMsgType(TId&&
id, std::size_t index, THandler& handler)
518 return dispatchMsgTypeInternal(std::forward<TId>(
id), index, handler, Tag<>());
521 static constexpr bool isPolymorphic()
523 return std::is_same<Tag<>, PolymorphicTag<> >::value;
526 static constexpr bool isStaticBinSearch()
528 return std::is_same<Tag<>, StaticBinSearchTag<> >::value;
531 template <
typename TMsg,
typename THandler>
532 static constexpr bool isDirect()
534 return dispatchMsgIsDirect<TMsg, THandler>();
537 template <
typename TMsg,
typename THandler>
538 static constexpr bool isDirect(TMsg&& msg, THandler&& handler)
540 return isDirect<
typename std::decay<
decltype(msg)>::type,
typename std::decay<
decltype(handler)>::type>();
544 template <
typename... TParams>
545 using PolymorphicTag = comms::details::tag::Tag1<>;
547 template <
typename... TParams>
548 using StaticBinSearchTag = comms::details::tag::Tag2<>;
550 template <
typename...>
552 typename comms::util::LazyShallowConditional<
553 dispatchMsgPolymorphicIsDirectSuitable<TAllMessages>() || (!allMessagesHaveStaticNumId<TAllMessages>())
559 template <
typename TMsgBase,
typename THandler>
560 using HandlerAdjustedTag =
561 typename comms::util::LazyShallowConditional<
562 dispatchMsgIsDirect<TMsgBase, THandler>()
568 template <
typename TMsg,
typename THandler,
typename... TParams>
569 static auto dispatchMsgInternal(TMsg& msg, THandler& handler, PolymorphicTag<TParams...>) ->
570 MessageInterfaceDispatchRetType<
571 typename std::decay<
decltype(handler)>::type>
573 return comms::dispatchMsgPolymorphic<TAllMessages>(msg, handler);
576 template <
typename TMsg,
typename THandler,
typename... TParams>
577 static auto dispatchMsgInternal(TMsg& msg, THandler& handler, StaticBinSearchTag<TParams...>) ->
578 MessageInterfaceDispatchRetType<
579 typename std::decay<
decltype(handler)>::type>
581 return comms::dispatchMsgStaticBinSearch<TAllMessages>(msg, handler);
584 template <
typename TId,
typename TMsg,
typename THandler,
typename... TParams>
585 static auto dispatchMsgInternal(TId&&
id, TMsg& msg, THandler& handler, PolymorphicTag<TParams...>) ->
586 MessageInterfaceDispatchRetType<
587 typename std::decay<
decltype(handler)>::type>
589 return comms::dispatchMsgPolymorphic<TAllMessages>(std::forward<TId>(
id), msg, handler);
592 template <
typename TId,
typename TMsg,
typename THandler,
typename... TParams>
593 static auto dispatchMsgInternal(TId&&
id, TMsg& msg, THandler& handler, StaticBinSearchTag<TParams...>) ->
594 MessageInterfaceDispatchRetType<
595 typename std::decay<
decltype(handler)>::type>
597 return comms::dispatchMsgStaticBinSearch<TAllMessages>(std::forward<TId>(
id), msg, handler);
600 template <
typename TId,
typename TMsg,
typename THandler,
typename... TParams>
601 static auto dispatchMsgInternal(TId&&
id, std::size_t index, TMsg& msg, THandler& handler, PolymorphicTag<TParams...>) ->
602 MessageInterfaceDispatchRetType<
603 typename std::decay<
decltype(handler)>::type>
605 return comms::dispatchMsgPolymorphic<TAllMessages>(std::forward<TId>(
id), index, msg, handler);
608 template <
typename TId,
typename TMsg,
typename THandler,
typename... TParams>
609 static auto dispatchMsgInternal(TId&&
id, std::size_t index, TMsg& msg, THandler& handler, StaticBinSearchTag<TParams...>) ->
610 MessageInterfaceDispatchRetType<
611 typename std::decay<
decltype(handler)>::type>
613 return comms::dispatchMsgStaticBinSearch<TAllMessages>(std::forward<TId>(
id), index, msg, handler);
616 template <
typename TId,
typename THandler,
typename... TParams>
617 static bool dispatchMsgTypeInternal(TId&&
id, THandler& handler, PolymorphicTag<TParams...>)
619 return comms::dispatchMsgTypePolymorphic<TAllMessages>(std::forward<TId>(
id), handler);
622 template <
typename TId,
typename THandler,
typename... TParams>
623 static bool dispatchMsgTypeInternal(TId&&
id, THandler& handler, StaticBinSearchTag<TParams...>)
625 return comms::dispatchMsgTypeStaticBinSearch<TAllMessages>(std::forward<TId>(
id), handler);
628 template <
typename TId,
typename THandler,
typename... TParams>
629 static bool dispatchMsgTypeInternal(TId&&
id, std::size_t index, THandler& handler, PolymorphicTag<TParams...>)
631 return comms::dispatchMsgTypePolymorphic<TAllMessages>(std::forward<TId>(
id), index, handler);
634 template <
typename TId,
typename THandler,
typename... TParams>
635 static bool dispatchMsgTypeInternal(TId&&
id, std::size_t index, THandler& handler, StaticBinSearchTag<TParams...>)
637 return comms::dispatchMsgTypeStaticBinSearch<TAllMessages>(std::forward<TId>(
id), index, handler);
661 typename TAllMessages,
666 details::MessageInterfaceDispatchRetType<
667 typename std::decay<
decltype(handler)>::type>
669 return details::DispatchMsgHelper<TAllMessages>::dispatchMsg(std::forward<TId>(
id), msg, handler);
691 typename TAllMessages,
695auto dispatchMsg(TId&&
id, std::size_t index, TMsg& msg, THandler& handler) ->
696 details::MessageInterfaceDispatchRetType<
697 typename std::decay<
decltype(handler)>::type>
699 return details::DispatchMsgHelper<TAllMessages>::dispatchMsg(std::forward<TId>(
id), index, msg, handler);
719 typename TAllMessages,
723 details::MessageInterfaceDispatchRetType<
724 typename std::decay<
decltype(handler)>::type>
726 return details::DispatchMsgHelper<TAllMessages>::dispatchMsg(msg, handler);
745template <
typename TAllMessages,
typename TId,
typename THandler>
748 return details::DispatchMsgHelper<TAllMessages>::dispatchMsgType(std::forward<TId>(
id), handler);
768template <
typename TAllMessages,
typename TId,
typename THandler>
771 return details::DispatchMsgHelper<TAllMessages>::dispatchMsgType(std::forward<TId>(
id), index, handler);
780template <
typename TAllMessages>
783 return details::DispatchMsgHelper<TAllMessages>::isPolymorphic();
795template <
typename TAllMessages,
typename TMsg,
typename THandler>
798 return dispatchMsgIsDirect<TMsg, THandler>() || dispatchMsgTypeIsPolymorphic<TAllMessages>();
808template <
typename TAllMessages,
typename TMsg,
typename THandler>
811 return dispatchMsgIsPolymorphic<TAllMessages,
typename std::decay<
decltype(msg)>::type,
typename std::decay<
decltype(handler)>::type>();
820template <
typename TAllMessages>
823 return details::DispatchMsgHelper<TAllMessages>::isStaticBinSearch();
835template <
typename TAllMessages,
typename TMsg,
typename THandler>
838 return (!dispatchMsgIsDirect<TMsg, THandler>()) &&
839 dispatchMsgTypeIsStaticBinSearch<TAllMessages>();
849template <
typename TAllMessages,
typename TMsg,
typename THandler>
852 return dispatchMsgIsStaticBinSearch<TAllMessages,
typename std::decay<
decltype(msg)>::type,
typename std::decay<
decltype(handler)>::type>();
857COMMS_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:796
constexpr bool dispatchMsgIsDirect()
Compile time check whether the message object can use its own polymorphic dispatch() (see Polymorphic...
Definition dispatch.h:461
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:665
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:418
constexpr bool dispatchMsgIsStaticBinSearch()
Compile time check whether the dispatchMsg() will use "static binary search" dispatch for provided tu...
Definition dispatch.h:836
constexpr bool dispatchMsgTypeIsPolymorphic()
Compile time check whether the dispatchMsgType() will use "polymorphic" dispatch for provided tuple o...
Definition dispatch.h:781
constexpr bool dispatchMsgTypeIsStaticBinSearch()
Compile time check whether the dispatchMsgType() or dispatchMsgType() will use "static binary search"...
Definition dispatch.h:821
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:746
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.