14#include "comms/details/tag.h"
17#include "DispatchMsgHelperType.h"
26template <DispatchMsgTypeEnum TType>
27class DispatchMsgStrongStaticBinSearchHelper
29 template <std::
size_t TFrom, std::
size_t TCount>
31 std::integral_constant<std::size_t, (TFrom + (TCount / 2))>;
33 template <
typename TAllMessages, std::
size_t TFrom, std::
size_t TCount>
35 typename std::tuple_element<
36 MidIdx<TFrom, TCount>::value,
50 typename TAllMessages,
56 static auto dispatch(TId&&
id, TMsg& msg, THandler& handler) ->
57 MessageInterfaceDispatchRetType<
58 typename std::decay<
decltype(handler)>::type>
61 MessageInterfaceDispatchRetType<
62 typename std::decay<
decltype(handler)>::type>;
64 static constexpr std::size_t Mid = MidIdx<TFrom, TCount>::value;
65 using MidElemType = MidElem<TAllMessages, TFrom, TCount>;
67 typename TMsg::MsgIdParamType midId = MidElemType::doGetId();
69 static constexpr auto NextCount = Mid - TFrom;
70 static constexpr auto HelperType = DispatchMsgHelperIntType<NextCount>::value;
72 DispatchMsgStrongStaticBinSearchHelper<HelperType>::template
73 dispatch<TAllMessages, TFrom, NextCount>(
78 static constexpr auto NextCount = TCount - (Mid - TFrom);
79 static constexpr auto HelperType = DispatchMsgHelperIntType<NextCount>::value;
81 DispatchMsgStrongStaticBinSearchHelper<HelperType>::template
82 dispatch<TAllMessages, Mid, NextCount>(
86 auto& castedMsg =
static_cast<MidElemType&
>(msg);
87 return static_cast<RetType
>(handler.handle(castedMsg));
91 typename TAllMessages,
96 static bool dispatchType(TId&&
id, THandler& handler)
98 static constexpr std::size_t Mid = MidIdx<TFrom, TCount>::value;
99 using MidElemType = MidElem<TAllMessages, TFrom, TCount>;
100 typename MidElemType::MsgIdParamType midId = MidElemType::doGetId();
102 static constexpr auto NextCount = Mid - TFrom;
103 static constexpr auto HelperType = DispatchMsgHelperIntType<NextCount>::value;
105 DispatchMsgStrongStaticBinSearchHelper<HelperType>::template
106 dispatchType<TAllMessages, TFrom, NextCount>(
id, handler);
110 static constexpr auto NextCount = TCount - (Mid - TFrom);
111 static constexpr auto HelperType = DispatchMsgHelperIntType<NextCount>::value;
113 DispatchMsgStrongStaticBinSearchHelper<HelperType>::template
114 dispatchType<TAllMessages, Mid, NextCount>(
id, handler);
117 handler.template handle<MidElemType>();
122 typename TAllMessages,
126 static std::size_t dispatchTypeCount(TId&&
id)
128 static constexpr std::size_t Mid = MidIdx<TFrom, TCount>::value;
129 using MidElemType = MidElem<TAllMessages, TFrom, TCount>;
130 typename MidElemType::MsgIdParamType midId = MidElemType::doGetId();
132 static constexpr auto NextCount = Mid - TFrom;
133 static constexpr auto HelperType = DispatchMsgHelperIntType<NextCount>::value;
135 DispatchMsgStrongStaticBinSearchHelper<HelperType>::template
136 dispatchTypeCount<TAllMessages, TFrom, NextCount>(
id);
140 static constexpr auto NextCount = TCount - (Mid - TFrom);
141 static constexpr auto HelperType = DispatchMsgHelperIntType<NextCount>::value;
143 DispatchMsgStrongStaticBinSearchHelper<HelperType>::template
144 dispatchTypeCount<TAllMessages, Mid, NextCount>(
id);
152class DispatchMsgStrongStaticBinSearchHelper<DispatchMsgTypeEnum::Single>
157 template <
typename TAllMessages, std::
size_t TFrom>
158 using Elem =
typename std::tuple_element<TFrom, TAllMessages>::type;
163 typename TAllMessages,
169 static auto dispatch(TId&&
id, TMsg& msg, THandler& handler) ->
170 MessageInterfaceDispatchRetType<
171 typename std::decay<
decltype(handler)>::type>
174 MessageInterfaceDispatchRetType<
175 typename std::decay<
decltype(handler)>::type>;
177 using ElemType = Elem<TAllMessages, TFrom>;
179 typename TMsg::MsgIdParamType elemId = ElemType::doGetId();
181 return static_cast<RetType
>(handler.handle(msg));
184 auto& castedMsg =
static_cast<ElemType&
>(msg);
185 return static_cast<RetType
>(handler.handle(castedMsg));
189 typename TAllMessages,
194 static bool dispatchType(TId&&
id, THandler& handler)
196 using ElemType = Elem<TAllMessages, TFrom>;
197 typename ElemType::MsgIdParamType elemId = ElemType::doGetId();
202 handler.template handle<ElemType>();
207 typename TAllMessages,
211 static std::size_t dispatchTypeCount(TId&&
id)
213 using ElemType = Elem<TAllMessages, TFrom>;
214 typename ElemType::MsgIdParamType elemId = ElemType::doGetId();
224class DispatchMsgStrongStaticBinSearchHelper<DispatchMsgTypeEnum::None>
228 typename TAllMessages,
234 static auto dispatch(TId&&
id, TMsg& msg, THandler& handler) ->
235 MessageInterfaceDispatchRetType<
236 typename std::decay<
decltype(handler)>::type>
238 static_cast<void>(id);
241 MessageInterfaceDispatchRetType<
242 typename std::decay<
decltype(handler)>::type>;
243 return static_cast<RetType
>(handler.handle(msg));
247 typename TAllMessages,
252 static bool dispatchType(TId&&
id, THandler& handler)
254 static_cast<void>(id);
255 static_cast<void>(handler);
260 typename TAllMessages,
264 static std::size_t dispatchTypeCount(TId&&
id)
266 static_cast<void>(id);
271template <
bool TFirst>
272class DispatchMsgWeakStartIdxFinder
274 template <
typename TAllMessages, std::
size_t TIdx>
275 using CurrMsgType =
typename std::tuple_element<TIdx, TAllMessages>::type;
277 template <
typename TAllMessages, std::
size_t TIdx>
278 using PrevMsgType =
typename std::tuple_element<TIdx - 1, TAllMessages>::type;
281 template <
typename TAllMessages, std::
size_t TIdx>
284 CurrMsgType<TAllMessages, TIdx>::doGetId() == PrevMsgType<TAllMessages, TIdx>::doGetId()
286 typename DispatchMsgWeakStartIdxFinder<(TIdx <= 1)>::template Type<TAllMessages, TIdx - 1U>,
287 std::integral_constant<std::size_t, TIdx>
292class DispatchMsgWeakStartIdxFinder<true>
295 template <
typename TAllMessages, std::
size_t TIdx>
296 using Type = std::integral_constant<std::size_t, TIdx>;
299template <
bool THasElems>
300class DispatchMsgWeakCountFinder
302 template <
typename TAllMessages, std::
size_t TIdx>
303 using OrigMsgType =
typename std::tuple_element<TIdx, TAllMessages>::type;
305 template <
typename TAllMessages, std::
size_t TIdx, std::
size_t TCount>
307 typename std::tuple_element<
308 std::tuple_size<TAllMessages>::value - TCount,
313 template <
typename TAllMessages, std::
size_t TOrigIdx, std::
size_t TRem>
316 OrigMsgType<TAllMessages, TOrigIdx>::doGetId() == CurrMsgType<TAllMessages, TOrigIdx, TRem>::doGetId()
318 std::integral_constant<
320 1U + DispatchMsgWeakCountFinder<(1U < TRem)>::template Type<TAllMessages, TOrigIdx, TRem - 1>::value
322 std::integral_constant<std::size_t, 0U>
327class DispatchMsgWeakCountFinder<false>
330 template <
typename TAllMessages, std::
size_t TOrigIdx, std::
size_t TRem>
331 using Type = std::integral_constant<std::size_t, 0U>;
335template <DispatchMsgTypeEnum TType>
336class DispatchMsgWeakStaticBinSearchHelper
346 template <std::
size_t TFrom, std::
size_t TCount>
348 std::integral_constant<std::size_t, (TFrom + (TCount / 2))>;
350 template <
typename TAllMessages, std::
size_t TFrom, std::
size_t TCount>
352 typename std::tuple_element<
353 MidIdx<TFrom, TCount>::value,
362 template <
typename TAllMessages, std::
size_t TFrom, std::
size_t TCount>
363 using MidRangeStartIdxTmp =
364 typename DispatchMsgWeakStartIdxFinder<
365 MidIdx<TFrom, TCount>::value == 0U
368 MidIdx<TFrom, TCount>::value
372 template <
typename TAllMessages, std::
size_t TFrom, std::
size_t TCount>
373 using MidRangeStartIdx =
374 typename comms::util::IntMaxBinaryOp<>::template Type<
375 MidRangeStartIdxTmp<TAllMessages, TFrom, TCount>,
376 std::integral_constant<std::size_t, TFrom>
379 template <
typename TAllMessages, std::
size_t TFrom, std::
size_t TCount>
381 std::integral_constant<
383 std::tuple_size<TAllMessages>::value - MidRangeStartIdx<TAllMessages, TFrom, TCount>::value
386 template <
typename TAllMessages, std::
size_t TFrom, std::
size_t TCount>
387 using MidRangeCountTmp =
388 typename DispatchMsgWeakCountFinder<
389 (0U < RemCount<TAllMessages, TFrom, TCount>::value)
392 MidRangeStartIdx<TAllMessages, TFrom, TCount>::value,
393 RemCount<TAllMessages, TFrom, TCount>::value
396 template <
typename TAllMessages, std::
size_t TFrom, std::
size_t TCount>
397 using MidRangeCount =
398 typename comms::util::IntMinBinaryOp<>::template Type<
399 std::integral_constant<std::size_t, TCount - MidRangeStartIdx<TAllMessages, TFrom, TCount>::value>,
400 MidRangeCountTmp<TAllMessages, TFrom, TCount>
411 typename TAllMessages,
416 static auto dispatch(
typename TMsg::MsgIdParamType
id, std::size_t offset, TMsg& msg, THandler& handler) ->
417 MessageInterfaceDispatchRetType<
418 typename std::decay<
decltype(handler)>::type>
421 MessageInterfaceDispatchRetType<
422 typename std::decay<
decltype(handler)>::type>;
424 using MidElemType = MidElem<TAllMessages, TFrom, TCount>;
426 typename TMsg::MsgIdParamType midId = MidElemType::doGetId();
427 static constexpr std::size_t StartIdx =
428 MidRangeStartIdx<TAllMessages, TFrom, TCount>::value;
433 static constexpr std::size_t NextCount = StartIdx - TFrom;
434 static constexpr auto HelperType = DispatchMsgHelperIntType<NextCount>::value;
436 DispatchMsgWeakStaticBinSearchHelper<HelperType>::template
437 dispatch<TAllMessages, TFrom, NextCount>(
id, offset, msg, handler);
440 static constexpr std::size_t MidCount = MidRangeCount<TAllMessages, TFrom, TCount>::value;
443 static constexpr std::size_t NewStart = StartIdx + MidCount;
444 static constexpr std::size_t NextCount = TCount - (NewStart - TFrom);
445 static constexpr auto HelperType = DispatchMsgHelperIntType<NextCount>::value;
448 DispatchMsgWeakStaticBinSearchHelper<HelperType>::template
449 dispatch<TAllMessages, NewStart, NextCount>(
id, offset, msg, handler);
452 if (MidCount <= offset) {
453 return static_cast<RetType
>(handler.handle(msg));
456 static constexpr auto HelperType = DispatchMsgHelperIntType<MidCount>::value;
458 DispatchMsgWeakStaticBinSearchHelper<HelperType>::template
459 dispatchOffset<TAllMessages, StartIdx, MidCount>(offset, msg, handler);
463 typename TAllMessages,
468 static auto dispatchOffset(std::size_t offset, TMsg& msg, THandler& handler) ->
469 MessageInterfaceDispatchRetType<
470 typename std::decay<
decltype(handler)>::type>
473 MessageInterfaceDispatchRetType<
474 typename std::decay<
decltype(handler)>::type>;
476 static constexpr std::size_t MidOffset = TCount / 2;
478 if (offset < MidOffset) {
479 static constexpr auto HelperType = DispatchMsgHelperIntType<MidOffset>::value;
481 DispatchMsgWeakStaticBinSearchHelper<HelperType>::template
482 dispatchOffset<TAllMessages, TFrom, MidOffset>(offset, msg, handler);
485 if (MidOffset < offset) {
486 static constexpr std::size_t NextCount = TCount - (MidOffset - TFrom);
487 static constexpr auto HelperType = DispatchMsgHelperIntType<NextCount>::value;
489 DispatchMsgWeakStaticBinSearchHelper<HelperType>::template
490 dispatchOffset<TAllMessages, MidOffset, NextCount>(offset - MidOffset, msg, handler);
493 using MidElemType = MidElem<TAllMessages, TFrom, TCount>;
494 auto& castedMsg =
static_cast<MidElemType&
>(msg);
495 return static_cast<RetType
>(handler.handle(castedMsg));
499 typename TAllMessages,
504 static bool dispatchType(TId&&
id, std::size_t offset, THandler& handler)
506 using MidElemType = MidElem<TAllMessages, TFrom, TCount>;
507 static constexpr std::size_t StartIdx =
508 MidRangeStartIdx<TAllMessages, TFrom, TCount>::value;
510 static_assert(StartIdx <= MidIdx<TFrom, TCount>::value,
"Invalid calculation");
512 typename MidElemType::MsgIdParamType midId = MidElemType::doGetId();
514 static constexpr std::size_t NextCount = StartIdx - TFrom;
515 static constexpr auto HelperType = DispatchMsgHelperIntType<NextCount>::value;
517 DispatchMsgWeakStaticBinSearchHelper<HelperType>::template
518 dispatchType<TAllMessages, TFrom, NextCount>(
id, offset, handler);
521 static constexpr std::size_t MidCount = MidRangeCount<TAllMessages, TFrom, TCount>::value;
524 static constexpr std::size_t NewStart = StartIdx + MidCount;
525 static constexpr std::size_t NextCount = TCount - (NewStart - TFrom);
526 static constexpr auto HelperType = DispatchMsgHelperIntType<NextCount>::value;
528 DispatchMsgWeakStaticBinSearchHelper<HelperType>::template
529 dispatchType<TAllMessages, NewStart, NextCount>(
id, offset, handler);
532 if (MidCount <= offset) {
536 static constexpr auto HelperType = DispatchMsgHelperIntType<MidCount>::value;
538 DispatchMsgWeakStaticBinSearchHelper<HelperType>::template
539 dispatchTypeOffset<TAllMessages, StartIdx, MidCount>(offset, handler);
543 typename TAllMessages,
547 static bool dispatchTypeOffset(std::size_t offset, THandler& handler)
549 static constexpr std::size_t MidOffset = TCount / 2;
551 if (offset < MidOffset) {
552 static constexpr auto HelperType = DispatchMsgHelperIntType<MidOffset>::value;
554 DispatchMsgWeakStaticBinSearchHelper<HelperType>::template
555 dispatchTypeOffset<TAllMessages, TFrom, MidOffset>(offset, handler);
558 if (MidOffset < offset) {
559 static constexpr std::size_t NextCount = TCount - (MidOffset - TFrom);
560 static constexpr auto HelperType = DispatchMsgHelperIntType<NextCount>::value;
562 DispatchMsgWeakStaticBinSearchHelper<HelperType>::template
563 dispatchTypeOffset<TAllMessages, MidOffset, NextCount>(offset - MidOffset, handler);
566 using MidElemType = MidElem<TAllMessages, TFrom, TCount>;
567 handler.template handle<MidElemType>();
572 typename TAllMessages,
576 static std::size_t dispatchTypeCount(TId&&
id)
578 static constexpr std::size_t StartIdx = MidRangeStartIdx<TAllMessages, TFrom, TCount>::value;
579 static_assert(StartIdx <= MidIdx<TFrom, TCount>::value,
"Invalid calculation");
581 using MidElemType = MidElem<TAllMessages, TFrom, TCount>;
582 typename MidElemType::MsgIdParamType midId = MidElemType::doGetId();
584 static constexpr std::size_t NextCount = StartIdx - TFrom;
585 static constexpr auto HelperType = DispatchMsgHelperIntType<NextCount>::value;
587 DispatchMsgWeakStaticBinSearchHelper<HelperType>::template
588 dispatchTypeCount<TAllMessages, TFrom, NextCount>(
id);
591 static constexpr std::size_t MidCount = MidRangeCount<TAllMessages, TFrom, TCount>::value;
594 static constexpr std::size_t NewStart = StartIdx + MidCount;
595 static constexpr std::size_t NextCount = TCount - (NewStart - TFrom);
596 static constexpr auto HelperType = DispatchMsgHelperIntType<NextCount>::value;
598 DispatchMsgWeakStaticBinSearchHelper<HelperType>::template
599 dispatchTypeCount<TAllMessages, NewStart, NextCount>(
id);
607class DispatchMsgWeakStaticBinSearchHelper<DispatchMsgTypeEnum::Single>
615 template <
typename TAllMessages, std::
size_t TFrom>
616 using Elem =
typename std::tuple_element<TFrom, TAllMessages>::type;
620 typename TAllMessages,
625 static auto dispatch(
typename TMsg::MsgIdParamType
id, std::size_t offset, TMsg& msg, THandler& handler) ->
626 MessageInterfaceDispatchRetType<
627 typename std::decay<
decltype(handler)>::type>
630 MessageInterfaceDispatchRetType<
631 typename std::decay<
decltype(handler)>::type>;
634 return static_cast<RetType
>(handler.handle(msg));
637 using ElemType = Elem<TAllMessages, TFrom>;
638 typename TMsg::MsgIdParamType elemId = ElemType::doGetId();
640 return static_cast<RetType
>(handler.handle(msg));
643 auto& castedMsg =
static_cast<ElemType&
>(msg);
644 return static_cast<RetType
>(handler.handle(castedMsg));
648 typename TAllMessages,
653 static auto dispatchOffset(std::size_t offset, TMsg& msg, THandler& handler) ->
654 MessageInterfaceDispatchRetType<
655 typename std::decay<
decltype(handler)>::type>
658 MessageInterfaceDispatchRetType<
659 typename std::decay<
decltype(handler)>::type>;
662 return static_cast<RetType
>(handler.handle(msg));
665 using ElemType = Elem<TAllMessages, TFrom>;
666 auto& castedMsg =
static_cast<ElemType&
>(msg);
667 return static_cast<RetType
>(handler.handle(castedMsg));
671 typename TAllMessages,
676 static bool dispatchType(TId&&
id, std::size_t offset, THandler& handler)
682 using ElemType = Elem<TAllMessages, TFrom>;
683 typename ElemType::MsgIdParamType elemId = ElemType::doGetId();
688 handler.template handle<ElemType>();
693 typename TAllMessages,
697 static bool dispatchTypeOffset(std::size_t offset, THandler& handler)
703 using ElemType = Elem<TAllMessages, TFrom>;
704 handler.template handle<ElemType>();
709 typename TAllMessages,
713 static std::size_t dispatchTypeCount(TId&&
id)
715 using ElemType = Elem<TAllMessages, TFrom>;
716 typename ElemType::MsgIdParamType elemId = ElemType::doGetId();
726class DispatchMsgWeakStaticBinSearchHelper<DispatchMsgTypeEnum::None>
730 typename TAllMessages,
735 static auto dispatch(
typename TMsg::MsgIdParamType
id, std::size_t offset, TMsg& msg, THandler& handler) ->
736 MessageInterfaceDispatchRetType<
737 typename std::decay<
decltype(handler)>::type>
739 static_cast<void>(id);
740 static_cast<void>(offset);
743 MessageInterfaceDispatchRetType<
744 typename std::decay<
decltype(handler)>::type>;
745 return static_cast<RetType
>(handler.handle(msg));
749 typename TAllMessages,
754 static auto dispatchOffset(std::size_t offset, TMsg& msg, THandler& handler) ->
755 MessageInterfaceDispatchRetType<
756 typename std::decay<
decltype(handler)>::type>
758 static_cast<void>(offset);
761 MessageInterfaceDispatchRetType<
762 typename std::decay<
decltype(handler)>::type>;
763 return static_cast<RetType
>(handler.handle(msg));
767 typename TAllMessages,
772 static bool dispatchType(TId&&
id, std::size_t offset, THandler& handler)
774 static_cast<void>(id);
775 static_cast<void>(offset);
776 static_cast<void>(handler);
781 typename TAllMessages,
785 static bool dispatchTypeOffset(std::size_t offset, THandler& handler)
787 static_cast<void>(offset);
788 static_cast<void>(handler);
793 typename TAllMessages,
797 static std::size_t dispatchTypeCount(TId&&
id)
799 static_cast<void>(id);
805template <
typename...>
806class DispatchMsgStaticBinSearchHelper
808 template <
typename... TParams>
809 using EmptyTag = comms::details::tag::Tag1<>;
811 template <
typename... TParams>
812 using StrongTag = comms::details::tag::Tag2<>;
814 template <
typename... TParams>
815 using WeakTag = comms::details::tag::Tag3<>;
817 template<
typename TAllMessages,
typename...>
818 using StrongWeakTag =
819 typename comms::util::LazyShallowConditional<
820 allMessagesAreStrongSorted<TAllMessages>()
827 template <
typename TAllMessages,
typename...>
829 typename comms::util::LazyShallowConditional<
830 std::tuple_size<TAllMessages>::value == 0U
837 template <
typename TAllMessages,
typename TMsg>
839 typename comms::util::LazyShallowConditional<
840 comms::isMessageBase<TMsg>()
848 template <
typename TAllMessages,
typename TMsg,
typename THandler>
849 static auto dispatch(TMsg& msg, THandler& handler) ->
850 MessageInterfaceDispatchRetType<
851 typename std::decay<
decltype(handler)>::type>
853 using MsgType =
typename std::decay<
decltype(msg)>::type;
854 static_assert(MsgType::hasGetId(),
855 "The used message object must provide polymorphic ID retrieval function");
856 static_assert(MsgType::hasMsgIdType(),
857 "Message interface class must define its id type");
858 return dispatchInternal<TAllMessages>(msg.getId(), msg, handler, AdjustedTag<TAllMessages, MsgType>());
862 typename TAllMessages,
866 static auto dispatch(TId&&
id, TMsg& msg, THandler& handler) ->
867 MessageInterfaceDispatchRetType<
868 typename std::decay<
decltype(handler)>::type>
870 using MsgType =
typename std::decay<
decltype(msg)>::type;
871 static_assert(MsgType::hasMsgIdType(),
872 "Message interface class must define its id type");
874 using MsgIdParamType =
typename MsgType::MsgIdParamType;
875 return dispatchInternal<TAllMessages>(
static_cast<MsgIdParamType
>(
id), msg, handler, AdjustedTag<TAllMessages, MsgType>());
879 typename TAllMessages,
883 static auto dispatch(TId&&
id, std::size_t offset, TMsg& msg, THandler& handler) ->
884 MessageInterfaceDispatchRetType<
885 typename std::decay<
decltype(handler)>::type>
887 using MsgType =
typename std::decay<
decltype(msg)>::type;
888 static_assert(MsgType::hasMsgIdType(),
889 "Message interface class must define its id type");
891 using MsgIdParamType =
typename MsgType::MsgIdParamType;
892 return dispatchInternal<TAllMessages>(
static_cast<MsgIdParamType
>(
id), offset, msg, handler, AdjustedTag<TAllMessages, MsgType>());
895 template <
typename TAllMessages,
typename TId,
typename THandler>
896 static bool dispatchType(TId&&
id, THandler& handler)
898 return dispatchTypeInternal<TAllMessages>(std::forward<TId>(
id), handler, BinSearchTag<TAllMessages>());
901 template <
typename TAllMessages,
typename TId,
typename THandler>
902 static bool dispatchType(TId&&
id, std::size_t offset, THandler& handler)
904 return dispatchTypeInternal<TAllMessages>(std::forward<TId>(
id), offset, handler, BinSearchTag<TAllMessages>());
907 template <
typename TAllMessages,
typename TId>
908 static std::size_t dispatchTypeCount(TId&&
id)
910 return dispatchTypeCountInternal<TAllMessages>(std::forward<TId>(
id), BinSearchTag<TAllMessages>());
914 template <
typename TAllMessages,
typename TMsg,
typename THandler,
typename... TParams>
915 static auto dispatchInternal(
typename TMsg::MsgIdParamType
id, TMsg& msg, THandler& handler, EmptyTag<TParams...>) ->
916 MessageInterfaceDispatchRetType<
917 typename std::decay<
decltype(handler)>::type>
919 return dispatchInternal<TAllMessages>(
id, 0U, msg, handler, EmptyTag<>());
922 template <
typename TAllMessages,
typename TMsg,
typename THandler,
typename... TParams>
923 static auto dispatchInternal(
typename TMsg::MsgIdParamType
id, std::size_t offset, TMsg& msg, THandler& handler, EmptyTag<TParams...>) ->
924 MessageInterfaceDispatchRetType<
925 typename std::decay<
decltype(handler)>::type>
927 static_cast<void>(id);
928 static_cast<void>(offset);
930 MessageInterfaceDispatchRetType<
931 typename std::decay<
decltype(handler)>::type>;
932 return static_cast<RetType
>(handler.handle(msg));
935 template <
typename TAllMessages,
typename TMsg,
typename THandler,
typename... TParams>
936 static auto dispatchInternal(
typename TMsg::MsgIdParamType
id, TMsg& msg, THandler& handler, StrongTag<TParams...>) ->
937 MessageInterfaceDispatchRetType<
938 typename std::decay<
decltype(handler)>::type>
940 static constexpr std::size_t Count = std::tuple_size<TAllMessages>::value;
941 static constexpr auto HelperType = DispatchMsgHelperIntType<Count>::value;
943 DispatchMsgStrongStaticBinSearchHelper<HelperType>::template
944 dispatch<TAllMessages, 0, Count>(
id, msg, handler);
947 template <
typename TAllMessages,
typename TMsg,
typename THandler,
typename... TParams>
948 static auto dispatchInternal(
typename TMsg::MsgIdParamType
id, std::size_t offset, TMsg& msg, THandler& handler, StrongTag<TParams...>) ->
949 MessageInterfaceDispatchRetType<
950 typename std::decay<
decltype(handler)>::type>
954 MessageInterfaceDispatchRetType<
955 typename std::decay<
decltype(handler)>::type>;
956 return static_cast<RetType
>(handler.handle(msg));
960 static constexpr std::size_t Count = std::tuple_size<TAllMessages>::value;
961 static constexpr auto HelperType = DispatchMsgHelperIntType<Count>::value;
963 DispatchMsgStrongStaticBinSearchHelper<HelperType>::template
964 dispatch<TAllMessages, 0, Count>(
id, msg, handler);
968 template <
typename TAllMessages,
typename TMsg,
typename THandler,
typename... TParams>
969 static auto dispatchInternal(
typename TMsg::MsgIdParamType
id, TMsg& msg, THandler& handler, WeakTag<TParams...>) ->
970 MessageInterfaceDispatchRetType<
971 typename std::decay<
decltype(handler)>::type>
973 return dispatchInternal<TAllMessages>(
id, 0U, msg, handler, WeakTag<>());
976 template <
typename TAllMessages,
typename TMsg,
typename THandler,
typename... TParams>
977 static auto dispatchInternal(
typename TMsg::MsgIdParamType
id, std::size_t offset, TMsg& msg, THandler& handler, WeakTag<TParams...>) ->
978 MessageInterfaceDispatchRetType<
979 typename std::decay<
decltype(handler)>::type>
981 static_assert(allMessagesAreWeakSorted<TAllMessages>(),
982 "The message types in the provided tuple must be sorted by their IDs");
984 static constexpr std::size_t Count = std::tuple_size<TAllMessages>::value;
985 static constexpr auto HelperType = DispatchMsgHelperIntType<Count>::value;
987 DispatchMsgWeakStaticBinSearchHelper<HelperType>::template
988 dispatch<TAllMessages, 0, Count>(
id, offset, msg, handler);
992 template <
typename TAllMessages,
typename TId,
typename THandler,
typename... TParams>
993 static bool dispatchTypeInternal(TId&&
id, THandler& handler, EmptyTag<TParams...>)
995 return dispatchTypeInternal<TAllMessages>(
id, 0U, handler, EmptyTag<>());
998 template <
typename TAllMessages,
typename TId,
typename THandler,
typename... TParams>
999 static bool dispatchTypeInternal(TId&&
id, std::size_t offset, THandler& handler, EmptyTag<TParams...>)
1001 static_cast<void>(id);
1002 static_cast<void>(offset);
1003 static_cast<void>(handler);
1007 template <
typename TAllMessages,
typename TId,
typename THandler,
typename... TParams>
1008 static bool dispatchTypeInternal(TId&&
id, THandler& handler, StrongTag<TParams...>)
1010 using FirstMsgType =
typename std::tuple_element<0, TAllMessages>::type;
1011 static_assert(comms::isMessageBase<FirstMsgType>(),
1012 "The type in the tuple are expected to be proper messages");
1013 static_assert(FirstMsgType::hasMsgIdType(),
"The messages must define their ID type");
1014 using MsgIdParamType =
typename FirstMsgType::MsgIdParamType;
1016 static constexpr std::size_t Count = std::tuple_size<TAllMessages>::value;
1017 static constexpr auto HelperType = DispatchMsgHelperIntType<Count>::value;
1019 DispatchMsgStrongStaticBinSearchHelper<HelperType>::template
1020 dispatchType<TAllMessages, 0, Count>(
static_cast<MsgIdParamType
>(
id), handler);
1023 template <
typename TAllMessages,
typename TId,
typename THandler,
typename... TParams>
1024 static bool dispatchTypeInternal(TId&&
id, std::size_t offset, THandler& handler, StrongTag<TParams...>)
1030 return dispatchTypeInternal<TAllMessages>(std::forward<TId>(
id), handler, StrongTag<>());
1033 template <
typename TAllMessages,
typename TId,
typename THandler,
typename... TParams>
1034 static bool dispatchTypeInternal(TId&&
id, THandler& handler, WeakTag<TParams...>)
1036 return dispatchTypeInternal<TAllMessages>(std::forward<TId>(
id), 0U, handler, WeakTag<>());
1039 template <
typename TAllMessages,
typename TId,
typename THandler,
typename... TParams>
1040 static bool dispatchTypeInternal(TId&&
id, std::size_t offset, THandler& handler, WeakTag<TParams...>)
1042 static_assert(allMessagesAreWeakSorted<TAllMessages>(),
1043 "The message types in the provided tuple must be sorted by their IDs");
1045 using FirstMsgType =
typename std::tuple_element<0, TAllMessages>::type;
1046 static_assert(comms::isMessageBase<FirstMsgType>(),
1047 "The type in the tuple are expected to be proper messages");
1048 static_assert(FirstMsgType::hasMsgIdType(),
"The messages must define their ID type");
1049 using MsgIdParamType =
typename FirstMsgType::MsgIdParamType;
1050 static constexpr std::size_t Count = std::tuple_size<TAllMessages>::value;
1051 static constexpr auto HelperType = DispatchMsgHelperIntType<Count>::value;
1053 DispatchMsgWeakStaticBinSearchHelper<HelperType>::template
1054 dispatchType<TAllMessages, 0, Count>(
static_cast<MsgIdParamType
>(
id), offset, handler);
1058 template <
typename TAllMessages,
typename TId,
typename... TParams>
1059 static std::size_t dispatchTypeCountInternal(TId&&
id, EmptyTag<TParams...>)
1061 static_cast<void>(id);
1065 template <
typename TAllMessages,
typename TId,
typename... TParams>
1066 static std::size_t dispatchTypeCountInternal(TId&&
id, StrongTag<TParams...>)
1068 using FirstMsgType =
typename std::tuple_element<0, TAllMessages>::type;
1069 static_assert(comms::isMessageBase<FirstMsgType>(),
1070 "The type in the tuple are expected to be proper messages");
1071 static_assert(FirstMsgType::hasMsgIdType(),
"The messages must define their ID type");
1072 using MsgIdParamType =
typename FirstMsgType::MsgIdParamType;
1074 static constexpr std::size_t Count = std::tuple_size<TAllMessages>::value;
1075 static constexpr auto HelperType = DispatchMsgHelperIntType<Count>::value;
1077 DispatchMsgStrongStaticBinSearchHelper<HelperType>::template
1078 dispatchTypeCount<TAllMessages, 0, Count>(
static_cast<MsgIdParamType
>(
id));
1081 template <
typename TAllMessages,
typename TId,
typename... TParams>
1082 static std::size_t dispatchTypeCountInternal(TId&&
id, WeakTag<TParams...>)
1084 static_assert(allMessagesAreWeakSorted<TAllMessages>(),
1085 "The message types in the provided tuple must be sorted by their IDs");
1087 using FirstMsgType =
typename std::tuple_element<0, TAllMessages>::type;
1088 static_assert(comms::isMessageBase<FirstMsgType>(),
1089 "The type in the tuple are expected to be proper messages");
1090 static_assert(FirstMsgType::hasMsgIdType(),
"The messages must define their ID type");
1091 using MsgIdParamType =
typename FirstMsgType::MsgIdParamType;
1092 static constexpr std::size_t Count = std::tuple_size<TAllMessages>::value;
1093 static constexpr auto HelperType = DispatchMsgHelperIntType<Count>::value;
1095 DispatchMsgWeakStaticBinSearchHelper<HelperType>::template
1096 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:1459
Main namespace for all classes / functions of COMMS library.
Replacement to std::conditional.
Definition type_traits.h:28
Replacement to some types from standard type_traits.