12#include "comms/details/DispatchMsgHelperType.h"
14#include "comms/details/tag.h"
29template <DispatchMsgTypeEnum TType>
30class DispatchMsgStrongStaticBinSearchHelper
32 template <std::
size_t TFrom, std::
size_t TCount>
34 std::integral_constant<std::size_t, (TFrom + (TCount / 2))>;
36 template <
typename TAllMessages, std::
size_t TFrom, std::
size_t TCount>
38 typename std::tuple_element<
39 MidIdx<TFrom, TCount>::value,
53 typename TAllMessages,
59 static auto dispatch(TId&&
id, TMsg& msg, THandler& handler) ->
60 MessageInterfaceDispatchRetType<
61 typename std::decay<
decltype(handler)>::type>
64 MessageInterfaceDispatchRetType<
65 typename std::decay<
decltype(handler)>::type>;
67 static constexpr std::size_t Mid = MidIdx<TFrom, TCount>::value;
68 using MidElemType = MidElem<TAllMessages, TFrom, TCount>;
70 typename TMsg::MsgIdParamType midId = MidElemType::doGetId();
72 static constexpr auto NextCount = Mid - TFrom;
73 static constexpr auto HelperType = DispatchMsgHelperIntType<NextCount>::value;
75 DispatchMsgStrongStaticBinSearchHelper<HelperType>::template
76 dispatch<TAllMessages, TFrom, NextCount>(
81 static constexpr auto NextCount = TCount - (Mid - TFrom);
82 static constexpr auto HelperType = DispatchMsgHelperIntType<NextCount>::value;
84 DispatchMsgStrongStaticBinSearchHelper<HelperType>::template
85 dispatch<TAllMessages, Mid, NextCount>(
89 auto& castedMsg =
static_cast<MidElemType&
>(msg);
90 return static_cast<RetType
>(handler.handle(castedMsg));
94 typename TAllMessages,
99 static bool dispatchType(TId&&
id, THandler& handler)
101 static constexpr std::size_t Mid = MidIdx<TFrom, TCount>::value;
102 using MidElemType = MidElem<TAllMessages, TFrom, TCount>;
103 typename MidElemType::MsgIdParamType midId = MidElemType::doGetId();
105 static constexpr auto NextCount = Mid - TFrom;
106 static constexpr auto HelperType = DispatchMsgHelperIntType<NextCount>::value;
108 DispatchMsgStrongStaticBinSearchHelper<HelperType>::template
109 dispatchType<TAllMessages, TFrom, NextCount>(
id, handler);
113 static constexpr auto NextCount = TCount - (Mid - TFrom);
114 static constexpr auto HelperType = DispatchMsgHelperIntType<NextCount>::value;
116 DispatchMsgStrongStaticBinSearchHelper<HelperType>::template
117 dispatchType<TAllMessages, Mid, NextCount>(
id, handler);
120 handler.template handle<MidElemType>();
125 typename TAllMessages,
129 static std::size_t dispatchTypeCount(TId&&
id)
131 static constexpr std::size_t Mid = MidIdx<TFrom, TCount>::value;
132 using MidElemType = MidElem<TAllMessages, TFrom, TCount>;
133 typename MidElemType::MsgIdParamType midId = MidElemType::doGetId();
135 static constexpr auto NextCount = Mid - TFrom;
136 static constexpr auto HelperType = DispatchMsgHelperIntType<NextCount>::value;
138 DispatchMsgStrongStaticBinSearchHelper<HelperType>::template
139 dispatchTypeCount<TAllMessages, TFrom, NextCount>(
id);
143 static constexpr auto NextCount = TCount - (Mid - TFrom);
144 static constexpr auto HelperType = DispatchMsgHelperIntType<NextCount>::value;
146 DispatchMsgStrongStaticBinSearchHelper<HelperType>::template
147 dispatchTypeCount<TAllMessages, Mid, NextCount>(
id);
155class DispatchMsgStrongStaticBinSearchHelper<DispatchMsgTypeEnum::Single>
160 template <
typename TAllMessages, std::
size_t TFrom>
161 using Elem =
typename std::tuple_element<TFrom, TAllMessages>::type;
166 typename TAllMessages,
172 static auto dispatch(TId&&
id, TMsg& msg, THandler& handler) ->
173 MessageInterfaceDispatchRetType<
174 typename std::decay<
decltype(handler)>::type>
177 MessageInterfaceDispatchRetType<
178 typename std::decay<
decltype(handler)>::type>;
180 using ElemType = Elem<TAllMessages, TFrom>;
182 typename TMsg::MsgIdParamType elemId = ElemType::doGetId();
184 return static_cast<RetType
>(handler.handle(msg));
187 auto& castedMsg =
static_cast<ElemType&
>(msg);
188 return static_cast<RetType
>(handler.handle(castedMsg));
192 typename TAllMessages,
197 static bool dispatchType(TId&&
id, THandler& handler)
199 using ElemType = Elem<TAllMessages, TFrom>;
200 typename ElemType::MsgIdParamType elemId = ElemType::doGetId();
205 handler.template handle<ElemType>();
210 typename TAllMessages,
214 static std::size_t dispatchTypeCount(TId&&
id)
216 using ElemType = Elem<TAllMessages, TFrom>;
217 typename ElemType::MsgIdParamType elemId = ElemType::doGetId();
227class DispatchMsgStrongStaticBinSearchHelper<DispatchMsgTypeEnum::None>
231 typename TAllMessages,
237 static auto dispatch(TId&&
id, TMsg& msg, THandler& handler) ->
238 MessageInterfaceDispatchRetType<
239 typename std::decay<
decltype(handler)>::type>
241 static_cast<void>(id);
244 MessageInterfaceDispatchRetType<
245 typename std::decay<
decltype(handler)>::type>;
246 return static_cast<RetType
>(handler.handle(msg));
250 typename TAllMessages,
255 static bool dispatchType(TId&&
id, THandler& handler)
257 static_cast<void>(id);
258 static_cast<void>(handler);
263 typename TAllMessages,
267 static std::size_t dispatchTypeCount(TId&&
id)
269 static_cast<void>(id);
274template <
bool TFirst>
275class DispatchMsgWeakStartIdxFinder
277 template <
typename TAllMessages, std::
size_t TIdx>
278 using CurrMsgType =
typename std::tuple_element<TIdx, TAllMessages>::type;
280 template <
typename TAllMessages, std::
size_t TIdx>
281 using PrevMsgType =
typename std::tuple_element<TIdx - 1, TAllMessages>::type;
284 template <
typename TAllMessages, std::
size_t TIdx>
287 CurrMsgType<TAllMessages, TIdx>::doGetId() == PrevMsgType<TAllMessages, TIdx>::doGetId()
289 typename DispatchMsgWeakStartIdxFinder<(TIdx <= 1)>::template Type<TAllMessages, TIdx - 1U>,
290 std::integral_constant<std::size_t, TIdx>
295class DispatchMsgWeakStartIdxFinder<true>
298 template <
typename TAllMessages, std::
size_t TIdx>
299 using Type = std::integral_constant<std::size_t, TIdx>;
302template <
bool THasElems>
303class DispatchMsgWeakCountFinder
305 template <
typename TAllMessages, std::
size_t TIdx>
306 using OrigMsgType =
typename std::tuple_element<TIdx, TAllMessages>::type;
308 template <
typename TAllMessages, std::
size_t TIdx, std::
size_t TCount>
310 typename std::tuple_element<
311 std::tuple_size<TAllMessages>::value - TCount,
316 template <
typename TAllMessages, std::
size_t TOrigIdx, std::
size_t TRem>
319 OrigMsgType<TAllMessages, TOrigIdx>::doGetId() == CurrMsgType<TAllMessages, TOrigIdx, TRem>::doGetId()
321 std::integral_constant<
323 1U + DispatchMsgWeakCountFinder<(1U < TRem)>::template Type<TAllMessages, TOrigIdx, TRem - 1>::value
325 std::integral_constant<std::size_t, 0U>
330class DispatchMsgWeakCountFinder<false>
333 template <
typename TAllMessages, std::
size_t TOrigIdx, std::
size_t TRem>
334 using Type = std::integral_constant<std::size_t, 0U>;
338template <DispatchMsgTypeEnum TType>
339class DispatchMsgWeakStaticBinSearchHelper
349 template <std::
size_t TFrom, std::
size_t TCount>
351 std::integral_constant<std::size_t, (TFrom + (TCount / 2))>;
353 template <
typename TAllMessages, std::
size_t TFrom, std::
size_t TCount>
355 typename std::tuple_element<
356 MidIdx<TFrom, TCount>::value,
365 template <
typename TAllMessages, std::
size_t TFrom, std::
size_t TCount>
366 using MidRangeStartIdxTmp =
367 typename DispatchMsgWeakStartIdxFinder<
368 MidIdx<TFrom, TCount>::value == 0U
371 MidIdx<TFrom, TCount>::value
375 template <
typename TAllMessages, std::
size_t TFrom, std::
size_t TCount>
376 using MidRangeStartIdx =
377 typename comms::util::IntMaxBinaryOp<>::template Type<
378 MidRangeStartIdxTmp<TAllMessages, TFrom, TCount>,
379 std::integral_constant<std::size_t, TFrom>
382 template <
typename TAllMessages, std::
size_t TFrom, std::
size_t TCount>
384 std::integral_constant<
386 std::tuple_size<TAllMessages>::value - MidRangeStartIdx<TAllMessages, TFrom, TCount>::value
389 template <
typename TAllMessages, std::
size_t TFrom, std::
size_t TCount>
390 using MidRangeCountTmp =
391 typename DispatchMsgWeakCountFinder<
392 (0U < RemCount<TAllMessages, TFrom, TCount>::value)
395 MidRangeStartIdx<TAllMessages, TFrom, TCount>::value,
396 RemCount<TAllMessages, TFrom, TCount>::value
399 template <
typename TAllMessages, std::
size_t TFrom, std::
size_t TCount>
400 using MidRangeCount =
401 typename comms::util::IntMinBinaryOp<>::template Type<
402 std::integral_constant<std::size_t, TCount - MidRangeStartIdx<TAllMessages, TFrom, TCount>::value>,
403 MidRangeCountTmp<TAllMessages, TFrom, TCount>
414 typename TAllMessages,
419 static auto dispatch(
typename TMsg::MsgIdParamType
id, std::size_t offset, TMsg& msg, THandler& handler) ->
420 MessageInterfaceDispatchRetType<
421 typename std::decay<
decltype(handler)>::type>
424 MessageInterfaceDispatchRetType<
425 typename std::decay<
decltype(handler)>::type>;
427 using MidElemType = MidElem<TAllMessages, TFrom, TCount>;
429 typename TMsg::MsgIdParamType midId = MidElemType::doGetId();
430 static constexpr std::size_t StartIdx =
431 MidRangeStartIdx<TAllMessages, TFrom, TCount>::value;
436 static constexpr std::size_t NextCount = StartIdx - TFrom;
437 static constexpr auto HelperType = DispatchMsgHelperIntType<NextCount>::value;
439 DispatchMsgWeakStaticBinSearchHelper<HelperType>::template
440 dispatch<TAllMessages, TFrom, NextCount>(
id, offset, msg, handler);
443 static constexpr std::size_t MidCount = MidRangeCount<TAllMessages, TFrom, TCount>::value;
446 static constexpr std::size_t NewStart = StartIdx + MidCount;
447 static constexpr std::size_t NextCount = TCount - (NewStart - TFrom);
448 static constexpr auto HelperType = DispatchMsgHelperIntType<NextCount>::value;
451 DispatchMsgWeakStaticBinSearchHelper<HelperType>::template
452 dispatch<TAllMessages, NewStart, NextCount>(
id, offset, msg, handler);
455 if (MidCount <= offset) {
456 return static_cast<RetType
>(handler.handle(msg));
459 static constexpr auto HelperType = DispatchMsgHelperIntType<MidCount>::value;
461 DispatchMsgWeakStaticBinSearchHelper<HelperType>::template
462 dispatchOffset<TAllMessages, StartIdx, MidCount>(offset, msg, handler);
466 typename TAllMessages,
471 static auto dispatchOffset(std::size_t offset, TMsg& msg, THandler& handler) ->
472 MessageInterfaceDispatchRetType<
473 typename std::decay<
decltype(handler)>::type>
476 MessageInterfaceDispatchRetType<
477 typename std::decay<
decltype(handler)>::type>;
479 static constexpr std::size_t MidOffset = TCount / 2;
481 if (offset < MidOffset) {
482 static constexpr auto HelperType = DispatchMsgHelperIntType<MidOffset>::value;
484 DispatchMsgWeakStaticBinSearchHelper<HelperType>::template
485 dispatchOffset<TAllMessages, TFrom, MidOffset>(offset, msg, handler);
488 if (MidOffset < offset) {
489 static constexpr std::size_t NextCount = TCount - (MidOffset - TFrom);
490 static constexpr auto HelperType = DispatchMsgHelperIntType<NextCount>::value;
492 DispatchMsgWeakStaticBinSearchHelper<HelperType>::template
493 dispatchOffset<TAllMessages, MidOffset, NextCount>(offset - MidOffset, msg, handler);
496 using MidElemType = MidElem<TAllMessages, TFrom, TCount>;
497 auto& castedMsg =
static_cast<MidElemType&
>(msg);
498 return static_cast<RetType
>(handler.handle(castedMsg));
502 typename TAllMessages,
507 static bool dispatchType(TId&&
id, std::size_t offset, THandler& handler)
509 using MidElemType = MidElem<TAllMessages, TFrom, TCount>;
510 static constexpr std::size_t StartIdx =
511 MidRangeStartIdx<TAllMessages, TFrom, TCount>::value;
513 static_assert(StartIdx <= MidIdx<TFrom, TCount>::value,
"Invalid calculation");
515 typename MidElemType::MsgIdParamType midId = MidElemType::doGetId();
517 static constexpr std::size_t NextCount = StartIdx - TFrom;
518 static constexpr auto HelperType = DispatchMsgHelperIntType<NextCount>::value;
520 DispatchMsgWeakStaticBinSearchHelper<HelperType>::template
521 dispatchType<TAllMessages, TFrom, NextCount>(
id, offset, handler);
524 static constexpr std::size_t MidCount = MidRangeCount<TAllMessages, TFrom, TCount>::value;
527 static constexpr std::size_t NewStart = StartIdx + MidCount;
528 static constexpr std::size_t NextCount = TCount - (NewStart - TFrom);
529 static constexpr auto HelperType = DispatchMsgHelperIntType<NextCount>::value;
531 DispatchMsgWeakStaticBinSearchHelper<HelperType>::template
532 dispatchType<TAllMessages, NewStart, NextCount>(
id, offset, handler);
535 if (MidCount <= offset) {
539 static constexpr auto HelperType = DispatchMsgHelperIntType<MidCount>::value;
541 DispatchMsgWeakStaticBinSearchHelper<HelperType>::template
542 dispatchTypeOffset<TAllMessages, StartIdx, MidCount>(offset, handler);
546 typename TAllMessages,
550 static bool dispatchTypeOffset(std::size_t offset, THandler& handler)
552 static constexpr std::size_t MidOffset = TCount / 2;
554 if (offset < MidOffset) {
555 static constexpr auto HelperType = DispatchMsgHelperIntType<MidOffset>::value;
557 DispatchMsgWeakStaticBinSearchHelper<HelperType>::template
558 dispatchTypeOffset<TAllMessages, TFrom, MidOffset>(offset, handler);
561 if (MidOffset < offset) {
562 static constexpr std::size_t NextCount = TCount - (MidOffset - TFrom);
563 static constexpr auto HelperType = DispatchMsgHelperIntType<NextCount>::value;
565 DispatchMsgWeakStaticBinSearchHelper<HelperType>::template
566 dispatchTypeOffset<TAllMessages, MidOffset, NextCount>(offset - MidOffset, handler);
569 using MidElemType = MidElem<TAllMessages, TFrom, TCount>;
570 handler.template handle<MidElemType>();
575 typename TAllMessages,
579 static std::size_t dispatchTypeCount(TId&&
id)
581 static constexpr std::size_t StartIdx = MidRangeStartIdx<TAllMessages, TFrom, TCount>::value;
582 static_assert(StartIdx <= MidIdx<TFrom, TCount>::value,
"Invalid calculation");
584 using MidElemType = MidElem<TAllMessages, TFrom, TCount>;
585 typename MidElemType::MsgIdParamType midId = MidElemType::doGetId();
587 static constexpr std::size_t NextCount = StartIdx - TFrom;
588 static constexpr auto HelperType = DispatchMsgHelperIntType<NextCount>::value;
590 DispatchMsgWeakStaticBinSearchHelper<HelperType>::template
591 dispatchTypeCount<TAllMessages, TFrom, NextCount>(
id);
594 static constexpr std::size_t MidCount = MidRangeCount<TAllMessages, TFrom, TCount>::value;
597 static constexpr std::size_t NewStart = StartIdx + MidCount;
598 static constexpr std::size_t NextCount = TCount - (NewStart - TFrom);
599 static constexpr auto HelperType = DispatchMsgHelperIntType<NextCount>::value;
601 DispatchMsgWeakStaticBinSearchHelper<HelperType>::template
602 dispatchTypeCount<TAllMessages, NewStart, NextCount>(
id);
610class DispatchMsgWeakStaticBinSearchHelper<DispatchMsgTypeEnum::Single>
618 template <
typename TAllMessages, std::
size_t TFrom>
619 using Elem =
typename std::tuple_element<TFrom, TAllMessages>::type;
623 typename TAllMessages,
628 static auto dispatch(
typename TMsg::MsgIdParamType
id, std::size_t offset, TMsg& msg, THandler& handler) ->
629 MessageInterfaceDispatchRetType<
630 typename std::decay<
decltype(handler)>::type>
633 MessageInterfaceDispatchRetType<
634 typename std::decay<
decltype(handler)>::type>;
637 return static_cast<RetType
>(handler.handle(msg));
640 using ElemType = Elem<TAllMessages, TFrom>;
641 typename TMsg::MsgIdParamType elemId = ElemType::doGetId();
643 return static_cast<RetType
>(handler.handle(msg));
646 auto& castedMsg =
static_cast<ElemType&
>(msg);
647 return static_cast<RetType
>(handler.handle(castedMsg));
651 typename TAllMessages,
656 static auto dispatchOffset(std::size_t offset, TMsg& msg, THandler& handler) ->
657 MessageInterfaceDispatchRetType<
658 typename std::decay<
decltype(handler)>::type>
661 MessageInterfaceDispatchRetType<
662 typename std::decay<
decltype(handler)>::type>;
665 return static_cast<RetType
>(handler.handle(msg));
668 using ElemType = Elem<TAllMessages, TFrom>;
669 auto& castedMsg =
static_cast<ElemType&
>(msg);
670 return static_cast<RetType
>(handler.handle(castedMsg));
674 typename TAllMessages,
679 static bool dispatchType(TId&&
id, std::size_t offset, THandler& handler)
685 using ElemType = Elem<TAllMessages, TFrom>;
686 typename ElemType::MsgIdParamType elemId = ElemType::doGetId();
691 handler.template handle<ElemType>();
696 typename TAllMessages,
700 static bool dispatchTypeOffset(std::size_t offset, THandler& handler)
706 using ElemType = Elem<TAllMessages, TFrom>;
707 handler.template handle<ElemType>();
712 typename TAllMessages,
716 static std::size_t dispatchTypeCount(TId&&
id)
718 using ElemType = Elem<TAllMessages, TFrom>;
719 typename ElemType::MsgIdParamType elemId = ElemType::doGetId();
729class DispatchMsgWeakStaticBinSearchHelper<DispatchMsgTypeEnum::None>
733 typename TAllMessages,
738 static auto dispatch(
typename TMsg::MsgIdParamType
id, std::size_t offset, TMsg& msg, THandler& handler) ->
739 MessageInterfaceDispatchRetType<
740 typename std::decay<
decltype(handler)>::type>
742 static_cast<void>(id);
743 static_cast<void>(offset);
746 MessageInterfaceDispatchRetType<
747 typename std::decay<
decltype(handler)>::type>;
748 return static_cast<RetType
>(handler.handle(msg));
752 typename TAllMessages,
757 static auto dispatchOffset(std::size_t offset, TMsg& msg, THandler& handler) ->
758 MessageInterfaceDispatchRetType<
759 typename std::decay<
decltype(handler)>::type>
761 static_cast<void>(offset);
764 MessageInterfaceDispatchRetType<
765 typename std::decay<
decltype(handler)>::type>;
766 return static_cast<RetType
>(handler.handle(msg));
770 typename TAllMessages,
775 static bool dispatchType(TId&&
id, std::size_t offset, THandler& handler)
777 static_cast<void>(id);
778 static_cast<void>(offset);
779 static_cast<void>(handler);
784 typename TAllMessages,
788 static bool dispatchTypeOffset(std::size_t offset, THandler& handler)
790 static_cast<void>(offset);
791 static_cast<void>(handler);
796 typename TAllMessages,
800 static std::size_t dispatchTypeCount(TId&&
id)
802 static_cast<void>(id);
808template <
typename...>
809class DispatchMsgStaticBinSearchHelper
811 template <
typename... TParams>
812 using EmptyTag = comms::details::tag::Tag1<>;
814 template <
typename... TParams>
815 using StrongTag = comms::details::tag::Tag2<>;
817 template <
typename... TParams>
818 using WeakTag = comms::details::tag::Tag3<>;
820 template<
typename TAllMessages,
typename...>
821 using StrongWeakTag =
822 typename comms::util::LazyShallowConditional<
823 allMessagesAreStrongSorted<TAllMessages>()
830 template <
typename TAllMessages,
typename...>
832 typename comms::util::LazyShallowConditional<
833 std::tuple_size<TAllMessages>::value == 0U
840 template <
typename TAllMessages,
typename TMsg>
842 typename comms::util::LazyShallowConditional<
843 comms::isMessageBase<TMsg>()
851 template <
typename TAllMessages,
typename TMsg,
typename THandler>
852 static auto dispatch(TMsg& msg, THandler& handler) ->
853 MessageInterfaceDispatchRetType<
854 typename std::decay<
decltype(handler)>::type>
856 using MsgType =
typename std::decay<
decltype(msg)>::type;
857 static_assert(MsgType::hasGetId(),
858 "The used message object must provide polymorphic ID retrieval function");
859 static_assert(MsgType::hasMsgIdType(),
860 "Message interface class must define its id type");
861 return dispatchInternal<TAllMessages>(msg.getId(), msg, handler, AdjustedTag<TAllMessages, MsgType>());
865 typename TAllMessages,
869 static auto dispatch(TId&&
id, TMsg& msg, THandler& handler) ->
870 MessageInterfaceDispatchRetType<
871 typename std::decay<
decltype(handler)>::type>
873 using MsgType =
typename std::decay<
decltype(msg)>::type;
874 static_assert(MsgType::hasMsgIdType(),
875 "Message interface class must define its id type");
877 using MsgIdParamType =
typename MsgType::MsgIdParamType;
878 return dispatchInternal<TAllMessages>(
static_cast<MsgIdParamType
>(
id), msg, handler, AdjustedTag<TAllMessages, MsgType>());
882 typename TAllMessages,
886 static auto dispatch(TId&&
id, std::size_t offset, TMsg& msg, THandler& handler) ->
887 MessageInterfaceDispatchRetType<
888 typename std::decay<
decltype(handler)>::type>
890 using MsgType =
typename std::decay<
decltype(msg)>::type;
891 static_assert(MsgType::hasMsgIdType(),
892 "Message interface class must define its id type");
894 using MsgIdParamType =
typename MsgType::MsgIdParamType;
895 return dispatchInternal<TAllMessages>(
static_cast<MsgIdParamType
>(
id), offset, msg, handler, AdjustedTag<TAllMessages, MsgType>());
898 template <
typename TAllMessages,
typename TId,
typename THandler>
899 static bool dispatchType(TId&&
id, THandler& handler)
901 return dispatchTypeInternal<TAllMessages>(std::forward<TId>(
id), handler, BinSearchTag<TAllMessages>());
904 template <
typename TAllMessages,
typename TId,
typename THandler>
905 static bool dispatchType(TId&&
id, std::size_t offset, THandler& handler)
907 return dispatchTypeInternal<TAllMessages>(std::forward<TId>(
id), offset, handler, BinSearchTag<TAllMessages>());
910 template <
typename TAllMessages,
typename TId>
911 static std::size_t dispatchTypeCount(TId&&
id)
913 return dispatchTypeCountInternal<TAllMessages>(std::forward<TId>(
id), BinSearchTag<TAllMessages>());
917 template <
typename TAllMessages,
typename TMsg,
typename THandler,
typename... TParams>
918 static auto dispatchInternal(
typename TMsg::MsgIdParamType
id, TMsg& msg, THandler& handler, EmptyTag<TParams...>) ->
919 MessageInterfaceDispatchRetType<
920 typename std::decay<
decltype(handler)>::type>
922 return dispatchInternal<TAllMessages>(
id, 0U, msg, handler, EmptyTag<>());
925 template <
typename TAllMessages,
typename TMsg,
typename THandler,
typename... TParams>
926 static auto dispatchInternal(
typename TMsg::MsgIdParamType
id, std::size_t offset, TMsg& msg, THandler& handler, EmptyTag<TParams...>) ->
927 MessageInterfaceDispatchRetType<
928 typename std::decay<
decltype(handler)>::type>
930 static_cast<void>(id);
931 static_cast<void>(offset);
933 MessageInterfaceDispatchRetType<
934 typename std::decay<
decltype(handler)>::type>;
935 return static_cast<RetType
>(handler.handle(msg));
938 template <
typename TAllMessages,
typename TMsg,
typename THandler,
typename... TParams>
939 static auto dispatchInternal(
typename TMsg::MsgIdParamType
id, TMsg& msg, THandler& handler, StrongTag<TParams...>) ->
940 MessageInterfaceDispatchRetType<
941 typename std::decay<
decltype(handler)>::type>
943 static constexpr std::size_t Count = std::tuple_size<TAllMessages>::value;
944 static constexpr auto HelperType = DispatchMsgHelperIntType<Count>::value;
946 DispatchMsgStrongStaticBinSearchHelper<HelperType>::template
947 dispatch<TAllMessages, 0, Count>(
id, msg, handler);
950 template <
typename TAllMessages,
typename TMsg,
typename THandler,
typename... TParams>
951 static auto dispatchInternal(
typename TMsg::MsgIdParamType
id, std::size_t offset, TMsg& msg, THandler& handler, StrongTag<TParams...>) ->
952 MessageInterfaceDispatchRetType<
953 typename std::decay<
decltype(handler)>::type>
957 MessageInterfaceDispatchRetType<
958 typename std::decay<
decltype(handler)>::type>;
959 return static_cast<RetType
>(handler.handle(msg));
963 static constexpr std::size_t Count = std::tuple_size<TAllMessages>::value;
964 static constexpr auto HelperType = DispatchMsgHelperIntType<Count>::value;
966 DispatchMsgStrongStaticBinSearchHelper<HelperType>::template
967 dispatch<TAllMessages, 0, Count>(
id, msg, handler);
971 template <
typename TAllMessages,
typename TMsg,
typename THandler,
typename... TParams>
972 static auto dispatchInternal(
typename TMsg::MsgIdParamType
id, TMsg& msg, THandler& handler, WeakTag<TParams...>) ->
973 MessageInterfaceDispatchRetType<
974 typename std::decay<
decltype(handler)>::type>
976 return dispatchInternal<TAllMessages>(
id, 0U, msg, handler, WeakTag<>());
979 template <
typename TAllMessages,
typename TMsg,
typename THandler,
typename... TParams>
980 static auto dispatchInternal(
typename TMsg::MsgIdParamType
id, std::size_t offset, TMsg& msg, THandler& handler, WeakTag<TParams...>) ->
981 MessageInterfaceDispatchRetType<
982 typename std::decay<
decltype(handler)>::type>
984 static_assert(allMessagesAreWeakSorted<TAllMessages>(),
985 "The message types in the provided tuple must be sorted by their IDs");
987 static constexpr std::size_t Count = std::tuple_size<TAllMessages>::value;
988 static constexpr auto HelperType = DispatchMsgHelperIntType<Count>::value;
990 DispatchMsgWeakStaticBinSearchHelper<HelperType>::template
991 dispatch<TAllMessages, 0, Count>(
id, offset, msg, handler);
995 template <
typename TAllMessages,
typename TId,
typename THandler,
typename... TParams>
996 static bool dispatchTypeInternal(TId&&
id, THandler& handler, EmptyTag<TParams...>)
998 return dispatchTypeInternal<TAllMessages>(
id, 0U, handler, EmptyTag<>());
1001 template <
typename TAllMessages,
typename TId,
typename THandler,
typename... TParams>
1002 static bool dispatchTypeInternal(TId&&
id, std::size_t offset, THandler& handler, EmptyTag<TParams...>)
1004 static_cast<void>(id);
1005 static_cast<void>(offset);
1006 static_cast<void>(handler);
1010 template <
typename TAllMessages,
typename TId,
typename THandler,
typename... TParams>
1011 static bool dispatchTypeInternal(TId&&
id, THandler& handler, StrongTag<TParams...>)
1013 using FirstMsgType =
typename std::tuple_element<0, TAllMessages>::type;
1014 static_assert(comms::isMessageBase<FirstMsgType>(),
1015 "The type in the tuple are expected to be proper messages");
1016 static_assert(FirstMsgType::hasMsgIdType(),
"The messages must define their ID type");
1017 using MsgIdParamType =
typename FirstMsgType::MsgIdParamType;
1019 static constexpr std::size_t Count = std::tuple_size<TAllMessages>::value;
1020 static constexpr auto HelperType = DispatchMsgHelperIntType<Count>::value;
1022 DispatchMsgStrongStaticBinSearchHelper<HelperType>::template
1023 dispatchType<TAllMessages, 0, Count>(
static_cast<MsgIdParamType
>(
id), handler);
1026 template <
typename TAllMessages,
typename TId,
typename THandler,
typename... TParams>
1027 static bool dispatchTypeInternal(TId&&
id, std::size_t offset, THandler& handler, StrongTag<TParams...>)
1033 return dispatchTypeInternal<TAllMessages>(std::forward<TId>(
id), handler, StrongTag<>());
1036 template <
typename TAllMessages,
typename TId,
typename THandler,
typename... TParams>
1037 static bool dispatchTypeInternal(TId&&
id, THandler& handler, WeakTag<TParams...>)
1039 return dispatchTypeInternal<TAllMessages>(std::forward<TId>(
id), 0U, handler, WeakTag<>());
1042 template <
typename TAllMessages,
typename TId,
typename THandler,
typename... TParams>
1043 static bool dispatchTypeInternal(TId&&
id, std::size_t offset, THandler& handler, WeakTag<TParams...>)
1045 static_assert(allMessagesAreWeakSorted<TAllMessages>(),
1046 "The message types in the provided tuple must be sorted by their IDs");
1048 using FirstMsgType =
typename std::tuple_element<0, TAllMessages>::type;
1049 static_assert(comms::isMessageBase<FirstMsgType>(),
1050 "The type in the tuple are expected to be proper messages");
1051 static_assert(FirstMsgType::hasMsgIdType(),
"The messages must define their ID type");
1052 using MsgIdParamType =
typename FirstMsgType::MsgIdParamType;
1053 static constexpr std::size_t Count = std::tuple_size<TAllMessages>::value;
1054 static constexpr auto HelperType = DispatchMsgHelperIntType<Count>::value;
1056 DispatchMsgWeakStaticBinSearchHelper<HelperType>::template
1057 dispatchType<TAllMessages, 0, Count>(
static_cast<MsgIdParamType
>(
id), offset, handler);
1061 template <
typename TAllMessages,
typename TId,
typename... TParams>
1062 static std::size_t dispatchTypeCountInternal(TId&&
id, EmptyTag<TParams...>)
1064 static_cast<void>(id);
1068 template <
typename TAllMessages,
typename TId,
typename... TParams>
1069 static std::size_t dispatchTypeCountInternal(TId&&
id, StrongTag<TParams...>)
1071 using FirstMsgType =
typename std::tuple_element<0, TAllMessages>::type;
1072 static_assert(comms::isMessageBase<FirstMsgType>(),
1073 "The type in the tuple are expected to be proper messages");
1074 static_assert(FirstMsgType::hasMsgIdType(),
"The messages must define their ID type");
1075 using MsgIdParamType =
typename FirstMsgType::MsgIdParamType;
1077 static constexpr std::size_t Count = std::tuple_size<TAllMessages>::value;
1078 static constexpr auto HelperType = DispatchMsgHelperIntType<Count>::value;
1080 DispatchMsgStrongStaticBinSearchHelper<HelperType>::template
1081 dispatchTypeCount<TAllMessages, 0, Count>(
static_cast<MsgIdParamType
>(
id));
1084 template <
typename TAllMessages,
typename TId,
typename... TParams>
1085 static std::size_t dispatchTypeCountInternal(TId&&
id, WeakTag<TParams...>)
1087 static_assert(allMessagesAreWeakSorted<TAllMessages>(),
1088 "The message types in the provided tuple must be sorted by their IDs");
1090 using FirstMsgType =
typename std::tuple_element<0, TAllMessages>::type;
1091 static_assert(comms::isMessageBase<FirstMsgType>(),
1092 "The type in the tuple are expected to be proper messages");
1093 static_assert(FirstMsgType::hasMsgIdType(),
"The messages must define their ID type");
1094 using MsgIdParamType =
typename FirstMsgType::MsgIdParamType;
1095 static constexpr std::size_t Count = std::tuple_size<TAllMessages>::value;
1096 static constexpr auto HelperType = DispatchMsgHelperIntType<Count>::value;
1098 DispatchMsgWeakStaticBinSearchHelper<HelperType>::template
1099 dispatchTypeCount<TAllMessages, 0, Count>(
static_cast<MsgIdParamType
>(
id));
Provides common base class for the custom messages with default implementation.
Contains definition of Message object interface and various base classes for custom messages.
comms::option::def::MsgType< TMsg > MsgType
Same as comms::option::def::MsgType.
Definition options.h:1500
Main namespace for all classes / functions of COMMS library.
Replacement to std::conditional.
Definition type_traits.h:32
Replacement to some types from standard type_traits.