14#include "comms/details/dispatch_impl.h"
16#include "comms/details/tag.h"
18COMMS_MSVC_WARNING_PUSH
19COMMS_MSVC_WARNING_DISABLE(4100)
36 typename TAllMessages,
41 details::MessageInterfaceDispatchRetType<
42 typename std::decay<
decltype(handler)>::type>
44 using MsgType =
typename std::decay<
decltype(msg)>::type;
45 static_assert(comms::isMessage<MsgType>(),
"msg param must be a valid message");
47 details::DispatchMsgPolymorphicHelper<>::template
48 dispatch<TAllMessages>(std::forward<TId>(
id), msg, handler);
64 typename TAllMessages,
69 details::MessageInterfaceDispatchRetType<
70 typename std::decay<
decltype(handler)>::type>
72 using MsgType =
typename std::decay<
decltype(msg)>::type;
73 static_assert(comms::isMessage<MsgType>(),
"msg param must be a valid message");
75 details::DispatchMsgPolymorphicHelper<>::template
76 dispatch<TAllMessages>(std::forward<TId>(
id), index, msg, handler);
90 typename TAllMessages,
94 details::MessageInterfaceDispatchRetType<
95 typename std::decay<
decltype(handler)>::type>
97 using MsgType =
typename std::decay<
decltype(msg)>::type;
98 static_assert(comms::isMessage<MsgType>(),
"msg param must be a valid message");
100 details::DispatchMsgPolymorphicHelper<>::template
101 dispatch<TAllMessages>(msg, handler);
116 typename TAllMessages,
122 details::DispatchMsgTypePolymorphicHelper<>::template
123 dispatch<TAllMessages>(std::forward<TId>(
id), handler);
139 typename TAllMessages,
145 details::DispatchMsgTypePolymorphicHelper<>::template
146 dispatch<TAllMessages>(std::forward<TId>(
id), index, handler);
162 typename TAllMessages,
167 details::MessageInterfaceDispatchRetType<
168 typename std::decay<
decltype(handler)>::type>
170 static_assert(details::allMessagesHaveStaticNumId<TAllMessages>(),
171 "All messages in the provided tuple must statically define their numeric ID");
174 details::DispatchMsgStaticBinSearchHelper<>::template dispatch<TAllMessages>(
175 std::forward<TId>(
id),
193 typename TAllMessages,
198 details::MessageInterfaceDispatchRetType<
199 typename std::decay<
decltype(handler)>::type>
201 static_assert(details::allMessagesHaveStaticNumId<TAllMessages>(),
202 "All messages in the provided tuple must statically define their numeric ID");
205 details::DispatchMsgStaticBinSearchHelper<>::template dispatch<TAllMessages>(
206 std::forward<TId>(
id),
222 typename TAllMessages,
226 details::MessageInterfaceDispatchRetType<
227 typename std::decay<
decltype(handler)>::type>
229 static_assert(details::allMessagesHaveStaticNumId<TAllMessages>(),
230 "All messages in the provided tuple must statically define their numeric ID");
231 using MsgType =
typename std::decay<
decltype(msg)>::type;
232 static_assert(MsgType::hasGetId(),
233 "The used message object must provide polymorphic ID retrieval function");
236 details::DispatchMsgStaticBinSearchHelper<>::template dispatch<TAllMessages>(
253 typename TAllMessages,
258 static_assert(details::allMessagesHaveStaticNumId<TAllMessages>(),
259 "All messages in the provided tuple must statically define their numeric ID");
262 details::DispatchMsgStaticBinSearchHelper<>::template
263 dispatchType<TAllMessages>(std::forward<TId>(
id), handler);
279 typename TAllMessages,
284 static_assert(details::allMessagesHaveStaticNumId<TAllMessages>(),
285 "All messages in the provided tuple must statically define their numeric ID");
288 details::DispatchMsgStaticBinSearchHelper<>::template
289 dispatchType<TAllMessages>(std::forward<TId>(
id), index, handler);
298template <
typename TAllMessages,
typename TId>
301 static_assert(details::allMessagesHaveStaticNumId<TAllMessages>(),
302 "All messages in the provided tuple must statically define their numeric ID");
305 details::DispatchMsgStaticBinSearchHelper<>::template
306 dispatchTypeCount<TAllMessages>(std::forward<TId>(
id));
321 typename TAllMessages,
326 details::MessageInterfaceDispatchRetType<
327 typename std::decay<
decltype(handler)>::type>
329 static_assert(details::allMessagesHaveStaticNumId<TAllMessages>(),
330 "All messages in the provided tuple must statically define their numeric ID");
333 details::DispatchMsgLinearSwitchHelper<>::template dispatch<TAllMessages>(
334 std::forward<TId>(
id),
352 typename TAllMessages,
357 details::MessageInterfaceDispatchRetType<
358 typename std::decay<
decltype(handler)>::type>
360 static_assert(details::allMessagesHaveStaticNumId<TAllMessages>(),
361 "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:166
bool dispatchMsgTypePolymorphic(TId &&id, THandler &handler)
Dispatch message id into appropriate handle() function in the provided handler using polymorphic beha...
Definition dispatch.h:119
std::size_t dispatchMsgTypeCountStaticBinSearch(TId &&id)
Count number of message types in the provided tuple that have the requested numeric ID.
Definition dispatch.h:299
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:40
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:325
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:256
Replacement to some types from standard type_traits.