13#include "comms/details/dispatch_impl.h"
14#include "comms/details/tag.h"
22COMMS_MSVC_WARNING_PUSH
23COMMS_MSVC_WARNING_DISABLE(4100)
40 typename TAllMessages,
45 details::MessageInterfaceDispatchRetType<
46 typename std::decay<
decltype(handler)>::type>
48 using MsgType =
typename std::decay<
decltype(msg)>::type;
49 static_assert(comms::isMessage<MsgType>(),
"msg param must be a valid message");
51 details::DispatchMsgPolymorphicHelper<>::template
52 dispatch<TAllMessages>(std::forward<TId>(
id), msg, handler);
68 typename TAllMessages,
73 details::MessageInterfaceDispatchRetType<
74 typename std::decay<
decltype(handler)>::type>
76 using MsgType =
typename std::decay<
decltype(msg)>::type;
77 static_assert(comms::isMessage<MsgType>(),
"msg param must be a valid message");
79 details::DispatchMsgPolymorphicHelper<>::template
80 dispatch<TAllMessages>(std::forward<TId>(
id), index, msg, handler);
94 typename TAllMessages,
98 details::MessageInterfaceDispatchRetType<
99 typename std::decay<
decltype(handler)>::type>
101 using MsgType =
typename std::decay<
decltype(msg)>::type;
102 static_assert(comms::isMessage<MsgType>(),
"msg param must be a valid message");
104 details::DispatchMsgPolymorphicHelper<>::template
105 dispatch<TAllMessages>(msg, handler);
120 typename TAllMessages,
126 details::DispatchMsgTypePolymorphicHelper<>::template
127 dispatch<TAllMessages>(std::forward<TId>(
id), handler);
143 typename TAllMessages,
149 details::DispatchMsgTypePolymorphicHelper<>::template
150 dispatch<TAllMessages>(std::forward<TId>(
id), index, handler);
166 typename TAllMessages,
171 details::MessageInterfaceDispatchRetType<
172 typename std::decay<
decltype(handler)>::type>
174 static_assert(details::allMessagesHaveStaticNumId<TAllMessages>(),
175 "All messages in the provided tuple must statically define their numeric ID");
178 details::DispatchMsgStaticBinSearchHelper<>::template dispatch<TAllMessages>(
179 std::forward<TId>(
id),
197 typename TAllMessages,
202 details::MessageInterfaceDispatchRetType<
203 typename std::decay<
decltype(handler)>::type>
205 static_assert(details::allMessagesHaveStaticNumId<TAllMessages>(),
206 "All messages in the provided tuple must statically define their numeric ID");
209 details::DispatchMsgStaticBinSearchHelper<>::template dispatch<TAllMessages>(
210 std::forward<TId>(
id),
226 typename TAllMessages,
230 details::MessageInterfaceDispatchRetType<
231 typename std::decay<
decltype(handler)>::type>
233 static_assert(details::allMessagesHaveStaticNumId<TAllMessages>(),
234 "All messages in the provided tuple must statically define their numeric ID");
235 using MsgType =
typename std::decay<
decltype(msg)>::type;
236 static_assert(MsgType::hasGetId(),
237 "The used message object must provide polymorphic ID retrieval function");
240 details::DispatchMsgStaticBinSearchHelper<>::template dispatch<TAllMessages>(
257 typename TAllMessages,
262 static_assert(details::allMessagesHaveStaticNumId<TAllMessages>(),
263 "All messages in the provided tuple must statically define their numeric ID");
266 details::DispatchMsgStaticBinSearchHelper<>::template
267 dispatchType<TAllMessages>(std::forward<TId>(
id), handler);
283 typename TAllMessages,
288 static_assert(details::allMessagesHaveStaticNumId<TAllMessages>(),
289 "All messages in the provided tuple must statically define their numeric ID");
292 details::DispatchMsgStaticBinSearchHelper<>::template
293 dispatchType<TAllMessages>(std::forward<TId>(
id), index, handler);
302template <
typename TAllMessages,
typename TId>
305 static_assert(details::allMessagesHaveStaticNumId<TAllMessages>(),
306 "All messages in the provided tuple must statically define their numeric ID");
309 details::DispatchMsgStaticBinSearchHelper<>::template
310 dispatchTypeCount<TAllMessages>(std::forward<TId>(
id));
325 typename TAllMessages,
330 details::MessageInterfaceDispatchRetType<
331 typename std::decay<
decltype(handler)>::type>
333 static_assert(details::allMessagesHaveStaticNumId<TAllMessages>(),
334 "All messages in the provided tuple must statically define their numeric ID");
337 details::DispatchMsgLinearSwitchHelper<>::template dispatch<TAllMessages>(
338 std::forward<TId>(
id),
356 typename TAllMessages,
361 details::MessageInterfaceDispatchRetType<
362 typename std::decay<
decltype(handler)>::type>
364 static_assert(details::allMessagesHaveStaticNumId<TAllMessages>(),
365 "All messages in the provided tuple must statically define their numeric ID");
368 details::DispatchMsgLinearSwitchHelper<>::template dispatch<TAllMessages>(
369 std::forward<TId>(
id),
386 typename TAllMessages,
390 details::MessageInterfaceDispatchRetType<
391 typename std::decay<
decltype(handler)>::type>
393 static_assert(details::allMessagesHaveStaticNumId<TAllMessages>(),
394 "All messages in the provided tuple must statically define their numeric ID");
395 using MsgType =
typename std::decay<
decltype(msg)>::type;
396 static_assert(MsgType::hasGetId(),
397 "The used message object must provide polymorphic ID retrieval function");
400 details::DispatchMsgLinearSwitchHelper<>::template dispatch<TAllMessages>(
417 typename TAllMessages,
422 static_assert(details::allMessagesHaveStaticNumId<TAllMessages>(),
423 "All messages in the provided tuple must statically define their numeric ID");
426 details::DispatchMsgLinearSwitchHelper<>::template
427 dispatchType<TAllMessages>(std::forward<TId>(
id), handler);
443 typename TAllMessages,
448 static_assert(details::allMessagesHaveStaticNumId<TAllMessages>(),
449 "All messages in the provided tuple must statically define their numeric ID");
452 details::DispatchMsgLinearSwitchHelper<>::template
453 dispatchType<TAllMessages>(std::forward<TId>(
id), index, handler);
462template <
typename TMsg,
typename THandler>
465 return details::dispatchMsgPolymorphicIsCompatibleHandler<typename std::decay<TMsg>::type,
typename std::decay<THandler>::type>();
475template <
typename TMsg,
typename THandler>
478 return dispatchMsgIsDirect<
typename std::decay<
decltype(msg)>::type,
typename std::decay<
decltype(handler)>::type>();
483template <
typename TAllMessages>
484class DispatchMsgHelper
487 template <
typename TMsg,
typename THandler>
488 static auto dispatchMsg(TMsg& msg, THandler& handler) ->
489 MessageInterfaceDispatchRetType<
490 typename std::decay<
decltype(handler)>::type>
492 return dispatchMsgInternal(msg, handler, HandlerAdjustedTag<TMsg, THandler>());
495 template <
typename TId,
typename TMsg,
typename THandler>
496 static auto dispatchMsg(TId&&
id, TMsg& msg, THandler& handler) ->
497 MessageInterfaceDispatchRetType<
498 typename std::decay<
decltype(handler)>::type>
500 return dispatchMsgInternal(std::forward<TId>(
id), msg, handler, HandlerAdjustedTag<TMsg, THandler>());
503 template <
typename TId,
typename TMsg,
typename THandler>
504 static auto dispatchMsg(TId&&
id, std::size_t index, TMsg& msg, THandler& handler) ->
505 MessageInterfaceDispatchRetType<
506 typename std::decay<
decltype(handler)>::type>
508 return dispatchMsgInternal(std::forward<TId>(
id), index, msg, handler, HandlerAdjustedTag<TMsg, THandler>());
511 template <
typename TId,
typename THandler>
514 return dispatchMsgTypeInternal(std::forward<TId>(
id), handler, Tag<>());
517 template <
typename TId,
typename THandler>
518 static bool dispatchMsgType(TId&&
id, std::size_t index, THandler& handler)
520 return dispatchMsgTypeInternal(std::forward<TId>(
id), index, handler, Tag<>());
523 static constexpr bool isPolymorphic()
525 return std::is_same<Tag<>, PolymorphicTag<> >::value;
528 static constexpr bool isStaticBinSearch()
530 return std::is_same<Tag<>, StaticBinSearchTag<> >::value;
533 template <
typename TMsg,
typename THandler>
534 static constexpr bool isDirect()
536 return dispatchMsgIsDirect<TMsg, THandler>();
539 template <
typename TMsg,
typename THandler>
540 static constexpr bool isDirect(TMsg&& msg, THandler&& handler)
542 return isDirect<
typename std::decay<
decltype(msg)>::type,
typename std::decay<
decltype(handler)>::type>();
546 template <
typename... TParams>
547 using PolymorphicTag = comms::details::tag::Tag1<>;
549 template <
typename... TParams>
550 using StaticBinSearchTag = comms::details::tag::Tag2<>;
552 template <
typename...>
554 typename comms::util::LazyShallowConditional<
555 dispatchMsgPolymorphicIsDirectSuitable<TAllMessages>() || (!allMessagesHaveStaticNumId<TAllMessages>())
561 template <
typename TMsgBase,
typename THandler>
562 using HandlerAdjustedTag =
563 typename comms::util::LazyShallowConditional<
564 dispatchMsgIsDirect<TMsgBase, THandler>()
570 template <
typename TMsg,
typename THandler,
typename... TParams>
571 static auto dispatchMsgInternal(TMsg& msg, THandler& handler, PolymorphicTag<TParams...>) ->
572 MessageInterfaceDispatchRetType<
573 typename std::decay<
decltype(handler)>::type>
575 return comms::dispatchMsgPolymorphic<TAllMessages>(msg, handler);
578 template <
typename TMsg,
typename THandler,
typename... TParams>
579 static auto dispatchMsgInternal(TMsg& msg, THandler& handler, StaticBinSearchTag<TParams...>) ->
580 MessageInterfaceDispatchRetType<
581 typename std::decay<
decltype(handler)>::type>
583 return comms::dispatchMsgStaticBinSearch<TAllMessages>(msg, handler);
586 template <
typename TId,
typename TMsg,
typename THandler,
typename... TParams>
587 static auto dispatchMsgInternal(TId&&
id, TMsg& msg, THandler& handler, PolymorphicTag<TParams...>) ->
588 MessageInterfaceDispatchRetType<
589 typename std::decay<
decltype(handler)>::type>
591 return comms::dispatchMsgPolymorphic<TAllMessages>(std::forward<TId>(
id), msg, handler);
594 template <
typename TId,
typename TMsg,
typename THandler,
typename... TParams>
595 static auto dispatchMsgInternal(TId&&
id, TMsg& msg, THandler& handler, StaticBinSearchTag<TParams...>) ->
596 MessageInterfaceDispatchRetType<
597 typename std::decay<
decltype(handler)>::type>
599 return comms::dispatchMsgStaticBinSearch<TAllMessages>(std::forward<TId>(
id), msg, handler);
602 template <
typename TId,
typename TMsg,
typename THandler,
typename... TParams>
603 static auto dispatchMsgInternal(TId&&
id, std::size_t index, TMsg& msg, THandler& handler, PolymorphicTag<TParams...>) ->
604 MessageInterfaceDispatchRetType<
605 typename std::decay<
decltype(handler)>::type>
607 return comms::dispatchMsgPolymorphic<TAllMessages>(std::forward<TId>(
id), index, msg, handler);
610 template <
typename TId,
typename TMsg,
typename THandler,
typename... TParams>
611 static auto dispatchMsgInternal(TId&&
id, std::size_t index, TMsg& msg, THandler& handler, StaticBinSearchTag<TParams...>) ->
612 MessageInterfaceDispatchRetType<
613 typename std::decay<
decltype(handler)>::type>
615 return comms::dispatchMsgStaticBinSearch<TAllMessages>(std::forward<TId>(
id), index, msg, handler);
618 template <
typename TId,
typename THandler,
typename... TParams>
619 static bool dispatchMsgTypeInternal(TId&&
id, THandler& handler, PolymorphicTag<TParams...>)
621 return comms::dispatchMsgTypePolymorphic<TAllMessages>(std::forward<TId>(
id), handler);
624 template <
typename TId,
typename THandler,
typename... TParams>
625 static bool dispatchMsgTypeInternal(TId&&
id, THandler& handler, StaticBinSearchTag<TParams...>)
627 return comms::dispatchMsgTypeStaticBinSearch<TAllMessages>(std::forward<TId>(
id), handler);
630 template <
typename TId,
typename THandler,
typename... TParams>
631 static bool dispatchMsgTypeInternal(TId&&
id, std::size_t index, THandler& handler, PolymorphicTag<TParams...>)
633 return comms::dispatchMsgTypePolymorphic<TAllMessages>(std::forward<TId>(
id), index, handler);
636 template <
typename TId,
typename THandler,
typename... TParams>
637 static bool dispatchMsgTypeInternal(TId&&
id, std::size_t index, THandler& handler, StaticBinSearchTag<TParams...>)
639 return comms::dispatchMsgTypeStaticBinSearch<TAllMessages>(std::forward<TId>(
id), index, handler);
663 typename TAllMessages,
668 details::MessageInterfaceDispatchRetType<
669 typename std::decay<
decltype(handler)>::type>
671 return details::DispatchMsgHelper<TAllMessages>::dispatchMsg(std::forward<TId>(
id), msg, handler);
693 typename TAllMessages,
697auto dispatchMsg(TId&&
id, std::size_t index, TMsg& msg, THandler& handler) ->
698 details::MessageInterfaceDispatchRetType<
699 typename std::decay<
decltype(handler)>::type>
701 return details::DispatchMsgHelper<TAllMessages>::dispatchMsg(std::forward<TId>(
id), index, msg, handler);
721 typename TAllMessages,
725 details::MessageInterfaceDispatchRetType<
726 typename std::decay<
decltype(handler)>::type>
728 return details::DispatchMsgHelper<TAllMessages>::dispatchMsg(msg, handler);
747template <
typename TAllMessages,
typename TId,
typename THandler>
750 return details::DispatchMsgHelper<TAllMessages>::dispatchMsgType(std::forward<TId>(
id), handler);
770template <
typename TAllMessages,
typename TId,
typename THandler>
773 return details::DispatchMsgHelper<TAllMessages>::dispatchMsgType(std::forward<TId>(
id), index, handler);
782template <
typename TAllMessages>
785 return details::DispatchMsgHelper<TAllMessages>::isPolymorphic();
797template <
typename TAllMessages,
typename TMsg,
typename THandler>
800 return dispatchMsgIsDirect<TMsg, THandler>() || dispatchMsgTypeIsPolymorphic<TAllMessages>();
810template <
typename TAllMessages,
typename TMsg,
typename THandler>
813 return dispatchMsgIsPolymorphic<TAllMessages,
typename std::decay<
decltype(msg)>::type,
typename std::decay<
decltype(handler)>::type>();
822template <
typename TAllMessages>
825 return details::DispatchMsgHelper<TAllMessages>::isStaticBinSearch();
837template <
typename TAllMessages,
typename TMsg,
typename THandler>
840 return (!dispatchMsgIsDirect<TMsg, THandler>()) &&
841 dispatchMsgTypeIsStaticBinSearch<TAllMessages>();
851template <
typename TAllMessages,
typename TMsg,
typename THandler>
854 return dispatchMsgIsStaticBinSearch<TAllMessages,
typename std::decay<
decltype(msg)>::type,
typename std::decay<
decltype(handler)>::type>();
859COMMS_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:798
constexpr bool dispatchMsgIsDirect()
Compile time check whether the message object can use its own polymorphic dispatch() (see Polymorphic...
Definition dispatch.h:463
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:667
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:170
bool dispatchMsgTypePolymorphic(TId &&id, THandler &handler)
Dispatch message id into appropriate handle() function in the provided handler using polymorphic beha...
Definition dispatch.h:123
std::size_t dispatchMsgTypeCountStaticBinSearch(TId &&id)
Count number of message types in the provided tuple that have the requested numeric ID.
Definition dispatch.h:303
bool dispatchMsgTypeLinearSwitch(TId &&id, THandler &handler)
Dispatch message id into appropriate handle() function in the provided handler using linear switch be...
Definition dispatch.h:420
constexpr bool dispatchMsgIsStaticBinSearch()
Compile time check whether the dispatchMsg() will use "static binary search" dispatch for provided tu...
Definition dispatch.h:838
constexpr bool dispatchMsgTypeIsPolymorphic()
Compile time check whether the dispatchMsgType() will use "polymorphic" dispatch for provided tuple o...
Definition dispatch.h:783
constexpr bool dispatchMsgTypeIsStaticBinSearch()
Compile time check whether the dispatchMsgType() or dispatchMsgType() will use "static binary search"...
Definition dispatch.h:823
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:44
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:329
bool dispatchMsgType(TId &&id, THandler &handler)
Dispatch message id into appropriate handle() function in the provided handler using either "polymorp...
Definition dispatch.h:748
bool dispatchMsgTypeStaticBinSearch(TId &&id, THandler &handler)
Dispatch message id into appropriate handle() function in the provided handler using static binary se...
Definition dispatch.h:260
Replacement to some types from standard type_traits.