10#include "comms/details/DispatchMsgHelperType.h" 
   12#include "comms/details/tag.h" 
   27template <DispatchMsgTypeEnum TType>
 
   28class DispatchMsgStrongStaticBinSearchHelper 
 
   30    template <std::
size_t TFrom, std::
size_t TCount>
 
   32        std::integral_constant<std::size_t, (TFrom + (TCount / 2))>; 
 
   34    template <
typename TAllMessages, std::
size_t TFrom, std::
size_t TCount>
 
   36        typename std::tuple_element<
 
   37            MidIdx<TFrom, TCount>::value, 
 
   51        typename TAllMessages, 
 
   57    static auto dispatch(TId&& 
id, TMsg& msg, THandler& handler) ->
 
   58        MessageInterfaceDispatchRetType<
 
   59            typename std::decay<
decltype(handler)>::type>
 
   62            MessageInterfaceDispatchRetType<
 
   63                typename std::decay<
decltype(handler)>::type>;
 
   65        static constexpr std::size_t Mid = MidIdx<TFrom, TCount>::value;
 
   66        using MidElemType = MidElem<TAllMessages, TFrom, TCount>;
 
   68        typename TMsg::MsgIdParamType midId = MidElemType::doGetId();
 
   70            static constexpr auto NextCount = Mid - TFrom;
 
   71            static constexpr auto HelperType = DispatchMsgHelperIntType<NextCount>::value;
 
   73                DispatchMsgStrongStaticBinSearchHelper<HelperType>::template 
 
   74                    dispatch<TAllMessages, TFrom, NextCount>(
 
   79            static constexpr auto NextCount = TCount - (Mid - TFrom);
 
   80            static constexpr auto HelperType = DispatchMsgHelperIntType<NextCount>::value;
 
   82                DispatchMsgStrongStaticBinSearchHelper<HelperType>::template 
 
   83                    dispatch<TAllMessages, Mid, NextCount>(
 
   87        auto& castedMsg = 
static_cast<MidElemType&
>(msg);
 
   88        return static_cast<RetType
>(handler.handle(castedMsg));
 
   92        typename TAllMessages, 
 
   97    static bool dispatchType(TId&& 
id, THandler& handler)
 
   99        static constexpr std::size_t Mid = MidIdx<TFrom, TCount>::value;
 
  100        using MidElemType = MidElem<TAllMessages, TFrom, TCount>;
 
  101        typename MidElemType::MsgIdParamType midId = MidElemType::doGetId();
 
  103            static constexpr auto NextCount = Mid - TFrom;
 
  104            static constexpr auto HelperType = DispatchMsgHelperIntType<NextCount>::value;
 
  106                DispatchMsgStrongStaticBinSearchHelper<HelperType>::template
 
  107                    dispatchType<TAllMessages, TFrom, NextCount>(
id, handler);
 
  111            static constexpr auto NextCount = TCount - (Mid - TFrom);
 
  112            static constexpr auto HelperType = DispatchMsgHelperIntType<NextCount>::value;
 
  114                DispatchMsgStrongStaticBinSearchHelper<HelperType>::template
 
  115                    dispatchType<TAllMessages, Mid, NextCount>(
id, handler);
 
  118        handler.template handle<MidElemType>();
 
  123        typename TAllMessages, 
 
  127    static std::size_t dispatchTypeCount(TId&& 
id)
 
  129        static constexpr std::size_t Mid = MidIdx<TFrom, TCount>::value;
 
  130        using MidElemType = MidElem<TAllMessages, TFrom, TCount>;
 
  131        typename MidElemType::MsgIdParamType midId = MidElemType::doGetId();
 
  133            static constexpr auto NextCount = Mid - TFrom;
 
  134            static constexpr auto HelperType = DispatchMsgHelperIntType<NextCount>::value;
 
  136                DispatchMsgStrongStaticBinSearchHelper<HelperType>::template
 
  137                    dispatchTypeCount<TAllMessages, TFrom, NextCount>(
id);
 
  141            static constexpr auto NextCount = TCount - (Mid - TFrom);
 
  142            static constexpr auto HelperType = DispatchMsgHelperIntType<NextCount>::value;
 
  144                DispatchMsgStrongStaticBinSearchHelper<HelperType>::template
 
  145                    dispatchTypeCount<TAllMessages, Mid, NextCount>(
id);
 
  153class DispatchMsgStrongStaticBinSearchHelper<DispatchMsgTypeEnum::Single>
 
  158    template <
typename TAllMessages, std::
size_t TFrom>
 
  159    using Elem = 
typename std::tuple_element<TFrom, TAllMessages>::type;
 
  164        typename TAllMessages, 
 
  170    static auto dispatch(TId&& 
id, TMsg& msg, THandler& handler) ->
 
  171        MessageInterfaceDispatchRetType<
 
  172            typename std::decay<
decltype(handler)>::type>
 
  175            MessageInterfaceDispatchRetType<
 
  176                typename std::decay<
decltype(handler)>::type>;
 
  178        using ElemType = Elem<TAllMessages, TFrom>;
 
  180        typename TMsg::MsgIdParamType elemId = ElemType::doGetId();
 
  182            return static_cast<RetType
>(handler.handle(msg));
 
  185        auto& castedMsg = 
static_cast<ElemType&
>(msg);
 
  186        return static_cast<RetType
>(handler.handle(castedMsg));
 
  190        typename TAllMessages, 
 
  195    static bool dispatchType(TId&& 
id, THandler& handler)
 
  197        using ElemType = Elem<TAllMessages, TFrom>;
 
  198        typename ElemType::MsgIdParamType elemId = ElemType::doGetId();
 
  203        handler.template handle<ElemType>();
 
  208        typename TAllMessages, 
 
  212    static std::size_t dispatchTypeCount(TId&& 
id)
 
  214        using ElemType = Elem<TAllMessages, TFrom>;
 
  215        typename ElemType::MsgIdParamType elemId = ElemType::doGetId();
 
  225class DispatchMsgStrongStaticBinSearchHelper<DispatchMsgTypeEnum::None>
 
  229        typename TAllMessages, 
 
  235    static auto dispatch(TId&& 
id, TMsg& msg, THandler& handler) ->
 
  236        MessageInterfaceDispatchRetType<
 
  237            typename std::decay<
decltype(handler)>::type>
 
  239        static_cast<void>(id);
 
  242            MessageInterfaceDispatchRetType<
 
  243                typename std::decay<
decltype(handler)>::type>;
 
  244        return static_cast<RetType
>(handler.handle(msg));
 
  248        typename TAllMessages, 
 
  253    static bool dispatchType(TId&& 
id, THandler& handler)
 
  255        static_cast<void>(id);
 
  256        static_cast<void>(handler);
 
  261        typename TAllMessages, 
 
  265    static std::size_t dispatchTypeCount(TId&& 
id)
 
  267        static_cast<void>(id);
 
  272template <
bool TFirst>
 
  273class DispatchMsgWeakStartIdxFinder 
 
  275    template <
typename TAllMessages, std::
size_t TIdx>
 
  276    using CurrMsgType = 
typename std::tuple_element<TIdx, TAllMessages>::type;
 
  278    template <
typename TAllMessages, std::
size_t TIdx>
 
  279    using PrevMsgType = 
typename std::tuple_element<TIdx - 1, TAllMessages>::type;
 
  282    template <
typename TAllMessages, std::
size_t TIdx>
 
  285            CurrMsgType<TAllMessages, TIdx>::doGetId() == PrevMsgType<TAllMessages, TIdx>::doGetId()
 
  287            typename DispatchMsgWeakStartIdxFinder<(TIdx <= 1)>::template Type<TAllMessages, TIdx - 1U>,
 
  288            std::integral_constant<std::size_t, TIdx>
 
  293class DispatchMsgWeakStartIdxFinder<true>
 
  296    template <
typename TAllMessages, std::
size_t TIdx>
 
  297    using Type = std::integral_constant<std::size_t, TIdx>;
 
  300template <
bool THasElems>
 
  301class DispatchMsgWeakCountFinder 
 
  303    template <
typename TAllMessages, std::
size_t TIdx>
 
  304    using OrigMsgType = 
typename std::tuple_element<TIdx, TAllMessages>::type;
 
  306    template <
typename TAllMessages, std::
size_t TIdx, std::
size_t TCount>
 
  308        typename std::tuple_element<
 
  309            std::tuple_size<TAllMessages>::value - TCount, 
 
  314    template <
typename TAllMessages, std::
size_t TOrigIdx, std::
size_t TRem>
 
  317            OrigMsgType<TAllMessages, TOrigIdx>::doGetId() == CurrMsgType<TAllMessages, TOrigIdx, TRem>::doGetId()
 
  319            std::integral_constant<
 
  321                1U + DispatchMsgWeakCountFinder<(1U < TRem)>::template Type<TAllMessages, TOrigIdx, TRem - 1>::value
 
  323            std::integral_constant<std::size_t, 0U>
 
  328class DispatchMsgWeakCountFinder<false>
 
  331    template <
typename TAllMessages, std::
size_t TOrigIdx, std::
size_t TRem>
 
  332    using Type = std::integral_constant<std::size_t, 0U>;
 
  336template <DispatchMsgTypeEnum TType>
 
  337class DispatchMsgWeakStaticBinSearchHelper 
 
  347    template <std::
size_t TFrom, std::
size_t TCount>
 
  349        std::integral_constant<std::size_t, (TFrom + (TCount / 2))>; 
 
  351    template <
typename TAllMessages, std::
size_t TFrom, std::
size_t TCount>
 
  353        typename std::tuple_element<
 
  354            MidIdx<TFrom, TCount>::value, 
 
  363    template <
typename TAllMessages, std::
size_t TFrom, std::
size_t TCount>
 
  364    using MidRangeStartIdxTmp = 
 
  365        typename DispatchMsgWeakStartIdxFinder<
 
  366            MidIdx<TFrom, TCount>::value == 0U
 
  369            MidIdx<TFrom, TCount>::value
 
  373    template <
typename TAllMessages, std::
size_t TFrom, std::
size_t TCount>
 
  374    using MidRangeStartIdx = 
 
  375        typename comms::util::IntMaxBinaryOp<>::template Type<
 
  376            MidRangeStartIdxTmp<TAllMessages, TFrom, TCount>,
 
  377            std::integral_constant<std::size_t, TFrom>
 
  380    template <
typename TAllMessages, std::
size_t TFrom, std::
size_t TCount>
 
  382        std::integral_constant<
 
  384            std::tuple_size<TAllMessages>::value - MidRangeStartIdx<TAllMessages, TFrom, TCount>::value
 
  387    template <
typename TAllMessages, std::
size_t TFrom, std::
size_t TCount>
 
  388    using MidRangeCountTmp = 
 
  389        typename DispatchMsgWeakCountFinder<
 
  390            (0U < RemCount<TAllMessages, TFrom, TCount>::value)
 
  393            MidRangeStartIdx<TAllMessages, TFrom, TCount>::value, 
 
  394            RemCount<TAllMessages, TFrom, TCount>::value
 
  397    template <
typename TAllMessages, std::
size_t TFrom, std::
size_t TCount>
 
  398    using MidRangeCount = 
 
  399        typename comms::util::IntMinBinaryOp<>::template Type<
 
  400            std::integral_constant<std::size_t, TCount - MidRangeStartIdx<TAllMessages, TFrom, TCount>::value>,
 
  401            MidRangeCountTmp<TAllMessages, TFrom, TCount>
 
  412        typename TAllMessages, 
 
  417    static auto dispatch(
typename TMsg::MsgIdParamType 
id, std::size_t offset, TMsg& msg, THandler& handler) ->
 
  418        MessageInterfaceDispatchRetType<
 
  419            typename std::decay<
decltype(handler)>::type>
 
  422            MessageInterfaceDispatchRetType<
 
  423                typename std::decay<
decltype(handler)>::type>;
 
  425        using MidElemType = MidElem<TAllMessages, TFrom, TCount>;
 
  427        typename TMsg::MsgIdParamType midId = MidElemType::doGetId();
 
  428        static constexpr std::size_t StartIdx = 
 
  429            MidRangeStartIdx<TAllMessages, TFrom, TCount>::value;
 
  434            static constexpr std::size_t NextCount = StartIdx - TFrom;
 
  435            static constexpr auto HelperType = DispatchMsgHelperIntType<NextCount>::value;
 
  437                DispatchMsgWeakStaticBinSearchHelper<HelperType>::template 
 
  438                    dispatch<TAllMessages, TFrom, NextCount>(
id, offset, msg, handler);
 
  441        static constexpr std::size_t MidCount = MidRangeCount<TAllMessages, TFrom, TCount>::value;
 
  444            static constexpr std::size_t NewStart = StartIdx + MidCount;
 
  445            static constexpr std::size_t NextCount = TCount - (NewStart - TFrom);
 
  446            static constexpr auto HelperType = DispatchMsgHelperIntType<NextCount>::value;
 
  449                DispatchMsgWeakStaticBinSearchHelper<HelperType>::template 
 
  450                    dispatch<TAllMessages, NewStart, NextCount>(
id, offset, msg, handler);
 
  453        if (MidCount <= offset) {
 
  454            return static_cast<RetType
>(handler.handle(msg));
 
  457        static constexpr auto HelperType = DispatchMsgHelperIntType<MidCount>::value;
 
  459            DispatchMsgWeakStaticBinSearchHelper<HelperType>::template 
 
  460                dispatchOffset<TAllMessages, StartIdx, MidCount>(offset, msg, handler);
 
  464        typename TAllMessages, 
 
  469    static auto dispatchOffset(std::size_t offset, TMsg& msg, THandler& handler) ->
 
  470        MessageInterfaceDispatchRetType<
 
  471            typename std::decay<
decltype(handler)>::type>
 
  474            MessageInterfaceDispatchRetType<
 
  475                typename std::decay<
decltype(handler)>::type>;
 
  477        static constexpr std::size_t MidOffset = TCount / 2;
 
  479        if (offset < MidOffset) {
 
  480            static constexpr auto HelperType = DispatchMsgHelperIntType<MidOffset>::value;
 
  482                DispatchMsgWeakStaticBinSearchHelper<HelperType>::template 
 
  483                    dispatchOffset<TAllMessages, TFrom, MidOffset>(offset, msg, handler);
 
  486        if (MidOffset < offset) {
 
  487            static constexpr std::size_t NextCount = TCount - (MidOffset - TFrom);
 
  488            static constexpr auto HelperType = DispatchMsgHelperIntType<NextCount>::value;
 
  490                DispatchMsgWeakStaticBinSearchHelper<HelperType>::template 
 
  491                    dispatchOffset<TAllMessages, MidOffset, NextCount>(offset - MidOffset, msg, handler);
 
  494        using MidElemType = MidElem<TAllMessages, TFrom, TCount>;
 
  495        auto& castedMsg = 
static_cast<MidElemType&
>(msg);
 
  496        return static_cast<RetType
>(handler.handle(castedMsg));
 
  500        typename TAllMessages, 
 
  505    static bool dispatchType(TId&& 
id, std::size_t offset, THandler& handler) 
 
  507        using MidElemType = MidElem<TAllMessages, TFrom, TCount>;
 
  508        static constexpr std::size_t StartIdx = 
 
  509            MidRangeStartIdx<TAllMessages, TFrom, TCount>::value;
 
  511        static_assert(StartIdx <= MidIdx<TFrom, TCount>::value, 
"Invalid calculation");
 
  513        typename MidElemType::MsgIdParamType midId = MidElemType::doGetId();
 
  515            static constexpr std::size_t NextCount = StartIdx - TFrom;
 
  516            static constexpr auto HelperType = DispatchMsgHelperIntType<NextCount>::value;
 
  518                DispatchMsgWeakStaticBinSearchHelper<HelperType>::template 
 
  519                    dispatchType<TAllMessages, TFrom, NextCount>(
id, offset, handler);
 
  522        static constexpr std::size_t MidCount = MidRangeCount<TAllMessages, TFrom, TCount>::value;
 
  525            static constexpr std::size_t NewStart = StartIdx + MidCount; 
 
  526            static constexpr std::size_t NextCount = TCount - (NewStart - TFrom);
 
  527            static constexpr auto HelperType = DispatchMsgHelperIntType<NextCount>::value;
 
  529                DispatchMsgWeakStaticBinSearchHelper<HelperType>::template 
 
  530                    dispatchType<TAllMessages, NewStart, NextCount>(
id, offset, handler);
 
  533        if (MidCount <= offset) {
 
  537        static constexpr auto HelperType = DispatchMsgHelperIntType<MidCount>::value;
 
  539            DispatchMsgWeakStaticBinSearchHelper<HelperType>::template 
 
  540                dispatchTypeOffset<TAllMessages, StartIdx, MidCount>(offset, handler);
 
  544        typename TAllMessages, 
 
  548    static bool dispatchTypeOffset(std::size_t offset, THandler& handler)
 
  550        static constexpr std::size_t MidOffset = TCount / 2;
 
  552        if (offset < MidOffset) {
 
  553            static constexpr auto HelperType = DispatchMsgHelperIntType<MidOffset>::value;
 
  555                DispatchMsgWeakStaticBinSearchHelper<HelperType>::template 
 
  556                    dispatchTypeOffset<TAllMessages, TFrom, MidOffset>(offset, handler);
 
  559        if (MidOffset < offset) {
 
  560            static constexpr std::size_t NextCount = TCount - (MidOffset - TFrom);
 
  561            static constexpr auto HelperType = DispatchMsgHelperIntType<NextCount>::value;
 
  563                DispatchMsgWeakStaticBinSearchHelper<HelperType>::template 
 
  564                    dispatchTypeOffset<TAllMessages, MidOffset, NextCount>(offset - MidOffset, handler);
 
  567        using MidElemType = MidElem<TAllMessages, TFrom, TCount>;
 
  568        handler.template handle<MidElemType>();
 
  573        typename TAllMessages, 
 
  577    static std::size_t dispatchTypeCount(TId&& 
id) 
 
  579        static constexpr std::size_t StartIdx = MidRangeStartIdx<TAllMessages, TFrom, TCount>::value;
 
  580        static_assert(StartIdx <= MidIdx<TFrom, TCount>::value, 
"Invalid calculation");
 
  582        using MidElemType = MidElem<TAllMessages, TFrom, TCount>;
 
  583        typename MidElemType::MsgIdParamType midId = MidElemType::doGetId();
 
  585            static constexpr std::size_t NextCount = StartIdx - TFrom;
 
  586            static constexpr auto HelperType = DispatchMsgHelperIntType<NextCount>::value;
 
  588                DispatchMsgWeakStaticBinSearchHelper<HelperType>::template 
 
  589                    dispatchTypeCount<TAllMessages, TFrom, NextCount>(
id);
 
  592        static constexpr std::size_t MidCount = MidRangeCount<TAllMessages, TFrom, TCount>::value;
 
  595            static constexpr std::size_t NewStart = StartIdx + MidCount; 
 
  596            static constexpr std::size_t NextCount = TCount - (NewStart - TFrom);
 
  597            static constexpr auto HelperType = DispatchMsgHelperIntType<NextCount>::value;
 
  599                DispatchMsgWeakStaticBinSearchHelper<HelperType>::template 
 
  600                    dispatchTypeCount<TAllMessages, NewStart, NextCount>(
id);
 
  608class DispatchMsgWeakStaticBinSearchHelper<DispatchMsgTypeEnum::Single>
 
  616    template <
typename TAllMessages, std::
size_t TFrom>
 
  617    using Elem = 
typename std::tuple_element<TFrom, TAllMessages>::type;
 
  621        typename TAllMessages, 
 
  626    static auto dispatch(
typename TMsg::MsgIdParamType 
id, std::size_t offset, TMsg& msg, THandler& handler) ->
 
  627        MessageInterfaceDispatchRetType<
 
  628            typename std::decay<
decltype(handler)>::type>
 
  631            MessageInterfaceDispatchRetType<
 
  632                typename std::decay<
decltype(handler)>::type>;
 
  635            return static_cast<RetType
>(handler.handle(msg));
 
  638        using ElemType = Elem<TAllMessages, TFrom>;
 
  639        typename TMsg::MsgIdParamType elemId = ElemType::doGetId();
 
  641            return static_cast<RetType
>(handler.handle(msg));
 
  644        auto& castedMsg = 
static_cast<ElemType&
>(msg);
 
  645        return static_cast<RetType
>(handler.handle(castedMsg));
 
  649        typename TAllMessages, 
 
  654    static auto dispatchOffset(std::size_t offset, TMsg& msg, THandler& handler) ->
 
  655        MessageInterfaceDispatchRetType<
 
  656            typename std::decay<
decltype(handler)>::type>
 
  659            MessageInterfaceDispatchRetType<
 
  660                typename std::decay<
decltype(handler)>::type>;
 
  663            return static_cast<RetType
>(handler.handle(msg));
 
  666        using ElemType = Elem<TAllMessages, TFrom>;
 
  667        auto& castedMsg = 
static_cast<ElemType&
>(msg);
 
  668        return static_cast<RetType
>(handler.handle(castedMsg));
 
  672        typename TAllMessages, 
 
  677    static bool dispatchType(TId&& 
id, std::size_t offset, THandler& handler) 
 
  683        using ElemType = Elem<TAllMessages, TFrom>;
 
  684        typename ElemType::MsgIdParamType elemId = ElemType::doGetId();
 
  689        handler.template handle<ElemType>();
 
  694        typename TAllMessages, 
 
  698    static bool dispatchTypeOffset(std::size_t offset, THandler& handler) 
 
  704        using ElemType = Elem<TAllMessages, TFrom>;
 
  705        handler.template handle<ElemType>();
 
  710        typename TAllMessages, 
 
  714    static std::size_t dispatchTypeCount(TId&& 
id)
 
  716        using ElemType = Elem<TAllMessages, TFrom>;
 
  717        typename ElemType::MsgIdParamType elemId = ElemType::doGetId();
 
  727class DispatchMsgWeakStaticBinSearchHelper<DispatchMsgTypeEnum::None>
 
  731        typename TAllMessages, 
 
  736    static auto dispatch(
typename TMsg::MsgIdParamType 
id, std::size_t offset, TMsg& msg, THandler& handler) ->
 
  737        MessageInterfaceDispatchRetType<
 
  738            typename std::decay<
decltype(handler)>::type>
 
  740        static_cast<void>(id);
 
  741        static_cast<void>(offset);
 
  744            MessageInterfaceDispatchRetType<
 
  745                typename std::decay<
decltype(handler)>::type>;
 
  746        return static_cast<RetType
>(handler.handle(msg));
 
  750        typename TAllMessages, 
 
  755    static auto dispatchOffset(std::size_t offset, TMsg& msg, THandler& handler) ->
 
  756        MessageInterfaceDispatchRetType<
 
  757            typename std::decay<
decltype(handler)>::type>
 
  759        static_cast<void>(offset);
 
  762            MessageInterfaceDispatchRetType<
 
  763                typename std::decay<
decltype(handler)>::type>;
 
  764        return static_cast<RetType
>(handler.handle(msg));
 
  768        typename TAllMessages, 
 
  773    static bool dispatchType(TId&& 
id, std::size_t offset, THandler& handler)
 
  775        static_cast<void>(id);
 
  776        static_cast<void>(offset);
 
  777        static_cast<void>(handler);
 
  782        typename TAllMessages, 
 
  786    static bool dispatchTypeOffset(std::size_t offset, THandler& handler) 
 
  788        static_cast<void>(offset);
 
  789        static_cast<void>(handler);
 
  794        typename TAllMessages, 
 
  798    static std::size_t dispatchTypeCount(TId&& 
id)
 
  800        static_cast<void>(id);
 
  806template <
typename...>
 
  807class DispatchMsgStaticBinSearchHelper    
 
  809    template <
typename... TParams>    
 
  810    using EmptyTag = comms::details::tag::Tag1<>;
 
  812    template <
typename... TParams>    
 
  813    using StrongTag = comms::details::tag::Tag2<>;
 
  815    template <
typename... TParams>    
 
  816    using WeakTag = comms::details::tag::Tag3<>;
 
  818    template<
typename TAllMessages, 
typename...>
 
  819    using StrongWeakTag = 
 
  820        typename comms::util::LazyShallowConditional<
 
  821            allMessagesAreStrongSorted<TAllMessages>()
 
  828    template <
typename TAllMessages, 
typename...>
 
  830        typename comms::util::LazyShallowConditional<
 
  831            std::tuple_size<TAllMessages>::value == 0U
 
  838    template <
typename TAllMessages, 
typename TMsg>
 
  840        typename comms::util::LazyShallowConditional<
 
  841            comms::isMessageBase<TMsg>()
 
  849    template <
typename TAllMessages, 
typename TMsg, 
typename THandler>
 
  850    static auto dispatch(TMsg& msg, THandler& handler) ->
 
  851        MessageInterfaceDispatchRetType<
 
  852            typename std::decay<
decltype(handler)>::type>
 
  854        using MsgType = 
typename std::decay<
decltype(msg)>::type;
 
  855        static_assert(MsgType::hasGetId(), 
 
  856            "The used message object must provide polymorphic ID retrieval function");
 
  857        static_assert(MsgType::hasMsgIdType(), 
 
  858            "Message interface class must define its id type");            
 
  859        return dispatchInternal<TAllMessages>(msg.getId(), msg, handler, AdjustedTag<TAllMessages, MsgType>());
 
  863        typename TAllMessages,
 
  867    static auto dispatch(TId&& 
id, TMsg& msg, THandler& handler) ->
 
  868        MessageInterfaceDispatchRetType<
 
  869            typename std::decay<
decltype(handler)>::type>
 
  871        using MsgType = 
typename std::decay<
decltype(msg)>::type;
 
  872        static_assert(MsgType::hasMsgIdType(), 
 
  873            "Message interface class must define its id type");            
 
  875        using MsgIdParamType = 
typename MsgType::MsgIdParamType;
 
  876        return dispatchInternal<TAllMessages>(
static_cast<MsgIdParamType
>(
id), msg, handler, AdjustedTag<TAllMessages, MsgType>());
 
  880        typename TAllMessages,
 
  884    static auto dispatch(TId&& 
id, std::size_t offset, TMsg& msg, THandler& handler) ->
 
  885        MessageInterfaceDispatchRetType<
 
  886            typename std::decay<
decltype(handler)>::type>
 
  888        using MsgType = 
typename std::decay<
decltype(msg)>::type;
 
  889        static_assert(MsgType::hasMsgIdType(), 
 
  890            "Message interface class must define its id type");            
 
  892        using MsgIdParamType = 
typename MsgType::MsgIdParamType;
 
  893        return dispatchInternal<TAllMessages>(
static_cast<MsgIdParamType
>(
id), offset, msg, handler, AdjustedTag<TAllMessages, MsgType>());
 
  896    template <
typename TAllMessages, 
typename TId, 
typename THandler>
 
  897    static bool dispatchType(TId&& 
id, THandler& handler)
 
  899        return dispatchTypeInternal<TAllMessages>(std::forward<TId>(
id), handler, BinSearchTag<TAllMessages>());
 
  902    template <
typename TAllMessages, 
typename TId, 
typename THandler>
 
  903    static bool dispatchType(TId&& 
id, std::size_t offset, THandler& handler)
 
  905        return dispatchTypeInternal<TAllMessages>(std::forward<TId>(
id), offset, handler, BinSearchTag<TAllMessages>());
 
  908    template <
typename TAllMessages, 
typename TId>
 
  909    static std::size_t dispatchTypeCount(TId&& 
id)
 
  911        return dispatchTypeCountInternal<TAllMessages>(std::forward<TId>(
id), BinSearchTag<TAllMessages>());
 
  915    template <
typename TAllMessages, 
typename TMsg, 
typename THandler, 
typename... TParams>
 
  916    static auto dispatchInternal(
typename TMsg::MsgIdParamType 
id, TMsg& msg, THandler& handler, EmptyTag<TParams...>) ->
 
  917        MessageInterfaceDispatchRetType<
 
  918            typename std::decay<
decltype(handler)>::type>
 
  920        return dispatchInternal<TAllMessages>(
id, 0U, msg, handler, EmptyTag<>());
 
  923    template <
typename TAllMessages, 
typename TMsg, 
typename THandler, 
typename... TParams>
 
  924    static auto dispatchInternal(
typename TMsg::MsgIdParamType 
id, std::size_t offset, TMsg& msg, THandler& handler, EmptyTag<TParams...>) ->
 
  925        MessageInterfaceDispatchRetType<
 
  926            typename std::decay<
decltype(handler)>::type>
 
  928        static_cast<void>(id);
 
  929        static_cast<void>(offset);
 
  931            MessageInterfaceDispatchRetType<
 
  932                typename std::decay<
decltype(handler)>::type>;
 
  933        return static_cast<RetType
>(handler.handle(msg));
 
  936    template <
typename TAllMessages, 
typename TMsg, 
typename THandler, 
typename... TParams>
 
  937    static auto dispatchInternal(
typename TMsg::MsgIdParamType 
id, TMsg& msg, THandler& handler, StrongTag<TParams...>) ->
 
  938        MessageInterfaceDispatchRetType<
 
  939            typename std::decay<
decltype(handler)>::type>
 
  941        static constexpr std::size_t Count = std::tuple_size<TAllMessages>::value;
 
  942        static constexpr auto HelperType = DispatchMsgHelperIntType<Count>::value;
 
  944            DispatchMsgStrongStaticBinSearchHelper<HelperType>::template
 
  945                dispatch<TAllMessages, 0, Count>(
id, msg, handler);
 
  948    template <
typename TAllMessages, 
typename TMsg, 
typename THandler, 
typename... TParams>
 
  949    static auto dispatchInternal(
typename TMsg::MsgIdParamType 
id, std::size_t offset, TMsg& msg, THandler& handler, StrongTag<TParams...>) ->
 
  950        MessageInterfaceDispatchRetType<
 
  951            typename std::decay<
decltype(handler)>::type>
 
  955                MessageInterfaceDispatchRetType<
 
  956                    typename std::decay<
decltype(handler)>::type>;
 
  957            return static_cast<RetType
>(handler.handle(msg));
 
  961        static constexpr std::size_t Count = std::tuple_size<TAllMessages>::value;
 
  962        static constexpr auto HelperType = DispatchMsgHelperIntType<Count>::value;
 
  964            DispatchMsgStrongStaticBinSearchHelper<HelperType>::template
 
  965                dispatch<TAllMessages, 0, Count>(
id, msg, handler);
 
  969    template <
typename TAllMessages, 
typename TMsg, 
typename THandler, 
typename... TParams>
 
  970    static auto dispatchInternal(
typename TMsg::MsgIdParamType 
id, TMsg& msg, THandler& handler, WeakTag<TParams...>) ->
 
  971        MessageInterfaceDispatchRetType<
 
  972            typename std::decay<
decltype(handler)>::type>
 
  974        return dispatchInternal<TAllMessages>(
id, 0U, msg, handler, WeakTag<>());
 
  977    template <
typename TAllMessages, 
typename TMsg, 
typename THandler, 
typename... TParams>
 
  978    static auto dispatchInternal(
typename TMsg::MsgIdParamType 
id, std::size_t offset, TMsg& msg, THandler& handler, WeakTag<TParams...>) ->
 
  979        MessageInterfaceDispatchRetType<
 
  980            typename std::decay<
decltype(handler)>::type>
 
  982        static_assert(allMessagesAreWeakSorted<TAllMessages>(),
 
  983                "The message types in the provided tuple must be sorted by their IDs");
 
  985        static constexpr std::size_t Count = std::tuple_size<TAllMessages>::value;
 
  986        static constexpr auto HelperType = DispatchMsgHelperIntType<Count>::value;
 
  988            DispatchMsgWeakStaticBinSearchHelper<HelperType>::template
 
  989                dispatch<TAllMessages, 0, Count>(
id, offset, msg, handler);
 
  993    template <
typename TAllMessages, 
typename TId, 
typename THandler, 
typename... TParams>
 
  994    static bool dispatchTypeInternal(TId&& 
id, THandler& handler, EmptyTag<TParams...>) 
 
  996        return dispatchTypeInternal<TAllMessages>(
id, 0U, handler, EmptyTag<>());
 
  999    template <
typename TAllMessages, 
typename TId, 
typename THandler, 
typename... TParams>
 
 1000    static bool dispatchTypeInternal(TId&& 
id, std::size_t offset, THandler& handler, EmptyTag<TParams...>) 
 
 1002        static_cast<void>(id);
 
 1003        static_cast<void>(offset);
 
 1004        static_cast<void>(handler);
 
 1008    template <
typename TAllMessages, 
typename TId, 
typename THandler, 
typename... TParams>
 
 1009    static bool dispatchTypeInternal(TId&& 
id, THandler& handler, StrongTag<TParams...>)
 
 1011        using FirstMsgType = 
typename std::tuple_element<0, TAllMessages>::type;
 
 1012        static_assert(comms::isMessageBase<FirstMsgType>(), 
 
 1013            "The type in the tuple are expected to be proper messages");
 
 1014        static_assert(FirstMsgType::hasMsgIdType(), 
"The messages must define their ID type");
 
 1015        using MsgIdParamType = 
typename FirstMsgType::MsgIdParamType;
 
 1017        static constexpr std::size_t Count = std::tuple_size<TAllMessages>::value;
 
 1018        static constexpr auto HelperType = DispatchMsgHelperIntType<Count>::value;
 
 1020            DispatchMsgStrongStaticBinSearchHelper<HelperType>::template
 
 1021                dispatchType<TAllMessages, 0, Count>(
static_cast<MsgIdParamType
>(
id), handler);
 
 1024    template <
typename TAllMessages, 
typename TId, 
typename THandler, 
typename... TParams>
 
 1025    static bool dispatchTypeInternal(TId&& 
id, std::size_t offset, THandler& handler, StrongTag<TParams...>)
 
 1031        return dispatchTypeInternal<TAllMessages>(std::forward<TId>(
id), handler, StrongTag<>());
 
 1034    template <
typename TAllMessages, 
typename TId, 
typename THandler, 
typename... TParams>
 
 1035    static bool dispatchTypeInternal(TId&& 
id, THandler& handler, WeakTag<TParams...>) 
 
 1037        return dispatchTypeInternal<TAllMessages>(std::forward<TId>(
id), 0U, handler, WeakTag<>());
 
 1040    template <
typename TAllMessages, 
typename TId, 
typename THandler, 
typename... TParams>
 
 1041    static bool dispatchTypeInternal(TId&& 
id, std::size_t offset, THandler& handler, WeakTag<TParams...>) 
 
 1043        static_assert(allMessagesAreWeakSorted<TAllMessages>(),
 
 1044                "The message types in the provided tuple must be sorted by their IDs");
 
 1046        using FirstMsgType = 
typename std::tuple_element<0, TAllMessages>::type;
 
 1047        static_assert(comms::isMessageBase<FirstMsgType>(), 
 
 1048            "The type in the tuple are expected to be proper messages");
 
 1049        static_assert(FirstMsgType::hasMsgIdType(), 
"The messages must define their ID type");
 
 1050        using MsgIdParamType = 
typename FirstMsgType::MsgIdParamType;        
 
 1051        static constexpr std::size_t Count = std::tuple_size<TAllMessages>::value;
 
 1052        static constexpr auto HelperType = DispatchMsgHelperIntType<Count>::value;
 
 1054            DispatchMsgWeakStaticBinSearchHelper<HelperType>::template
 
 1055                dispatchType<TAllMessages, 0, Count>(
static_cast<MsgIdParamType
>(
id), offset, handler);
 
 1059    template <
typename TAllMessages, 
typename TId, 
typename... TParams>
 
 1060    static std::size_t dispatchTypeCountInternal(TId&& 
id, EmptyTag<TParams...>) 
 
 1062        static_cast<void>(id);
 
 1066    template <
typename TAllMessages, 
typename TId, 
typename... TParams>
 
 1067    static std::size_t dispatchTypeCountInternal(TId&& 
id, StrongTag<TParams...>)
 
 1069        using FirstMsgType = 
typename std::tuple_element<0, TAllMessages>::type;
 
 1070        static_assert(comms::isMessageBase<FirstMsgType>(), 
 
 1071            "The type in the tuple are expected to be proper messages");
 
 1072        static_assert(FirstMsgType::hasMsgIdType(), 
"The messages must define their ID type");
 
 1073        using MsgIdParamType = 
typename FirstMsgType::MsgIdParamType;
 
 1075        static constexpr std::size_t Count = std::tuple_size<TAllMessages>::value;
 
 1076        static constexpr auto HelperType = DispatchMsgHelperIntType<Count>::value;
 
 1078            DispatchMsgStrongStaticBinSearchHelper<HelperType>::template
 
 1079                dispatchTypeCount<TAllMessages, 0, Count>(
static_cast<MsgIdParamType
>(
id));
 
 1082    template <
typename TAllMessages, 
typename TId, 
typename... TParams>
 
 1083    static std::size_t dispatchTypeCountInternal(TId&& 
id, WeakTag<TParams...>) 
 
 1085        static_assert(allMessagesAreWeakSorted<TAllMessages>(),
 
 1086                "The message types in the provided tuple must be sorted by their IDs");
 
 1088        using FirstMsgType = 
typename std::tuple_element<0, TAllMessages>::type;
 
 1089        static_assert(comms::isMessageBase<FirstMsgType>(), 
 
 1090            "The type in the tuple are expected to be proper messages");
 
 1091        static_assert(FirstMsgType::hasMsgIdType(), 
"The messages must define their ID type");
 
 1092        using MsgIdParamType = 
typename FirstMsgType::MsgIdParamType; 
 
 1093        static constexpr std::size_t Count = std::tuple_size<TAllMessages>::value;
 
 1094        static constexpr auto HelperType = DispatchMsgHelperIntType<Count>::value;               
 
 1096            DispatchMsgWeakStaticBinSearchHelper<HelperType>::template
 
 1097                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:1487
Main namespace for all classes / functions of COMMS library.
Replacement to std::conditional.
Definition type_traits.h:29
Replacement to some types from standard type_traits.