14 #include <type_traits>
18 #include "comms/details/MsgDispatcherOptionsParser.h"
28 template <
class T,
class R =
void>
29 struct EnableIfHasMsgDispatcherTag {
using Type = R; };
31 template <
class T,
class Enable =
void>
32 struct HasMsgDispatcherTag
34 static const bool Value =
false;
38 struct HasMsgDispatcherTag<T, typename EnableIfHasMsgDispatcherTag<typename T::MsgDispatcherTag>::Type>
40 static const bool Value =
true;
44 constexpr
bool hasMsgDispatcherTag()
46 return HasMsgDispatcherTag<T>::Value;
61 template <
typename... TOptions>
64 using NoForcingTag = comms::details::tag::Tag1<>;
66 using ParsedOptionsInternal = details::MsgDispatcherOptionsParser<TOptions...>;
70 ParsedOptionsInternal::HasForcedDispatch
72 typename ParsedOptionsInternal::ForcedDispatch,
76 template <
typename TAllMessages,
typename TMsgId,
typename TMsg,
typename THandler>
77 static auto dispatchInternal(TMsgId&&
id, std::size_t idx, TMsg& msg, THandler& handler, NoForcingTag) ->
78 decltype(comms::dispatchMsg<TAllMessages>(std::forward<TMsgId>(
id), idx, msg, handler))
80 return comms::dispatchMsg<TAllMessages>(std::forward<TMsgId>(
id), idx, msg, handler);
83 template <
typename TAllMessages,
typename TMsgId,
typename TMsg,
typename THandler>
84 static auto dispatchInternal(TMsgId&&
id, TMsg& msg, THandler& handler, NoForcingTag) ->
85 decltype(comms::dispatchMsg<TAllMessages>(std::forward<TMsgId>(
id), msg, handler))
87 return comms::dispatchMsg<TAllMessages>(std::forward<TMsgId>(
id), msg, handler);
90 template <
typename TAllMessages,
typename TMsg,
typename THandler>
91 static auto dispatchInternal(TMsg& msg, THandler& handler, NoForcingTag) ->
92 decltype(comms::dispatchMsg<TAllMessages>(msg, handler))
94 return comms::dispatchMsg<TAllMessages>(msg, handler);
97 template <
typename TAllMessages,
typename TMsgId,
typename TMsg,
typename THandler>
99 decltype(comms::dispatchMsgPolymorphic<TAllMessages>(std::forward<TMsgId>(
id), idx, msg, handler))
101 return comms::dispatchMsgPolymorphic<TAllMessages>(std::forward<TMsgId>(
id), idx, msg, handler);
104 template <
typename TAllMessages,
typename TMsgId,
typename TMsg,
typename THandler>
106 decltype(comms::dispatchMsgPolymorphic<TAllMessages>(std::forward<TMsgId>(
id), msg, handler))
108 return comms::dispatchMsgPolymorphic<TAllMessages>(std::forward<TMsgId>(
id), msg, handler);
111 template <
typename TAllMessages,
typename TMsg,
typename THandler>
113 decltype(comms::dispatchMsgPolymorphic<TAllMessages>(msg, handler))
115 return comms::dispatchMsgPolymorphic<TAllMessages>(msg, handler);
118 template <
typename TAllMessages,
typename TMsgId,
typename TMsg,
typename THandler>
120 decltype(comms::dispatchMsgStaticBinSearch<TAllMessages>(std::forward<TMsgId>(
id), idx, msg, handler))
122 return comms::dispatchMsgStaticBinSearch<TAllMessages>(std::forward<TMsgId>(
id), idx, msg, handler);
125 template <
typename TAllMessages,
typename TMsgId,
typename TMsg,
typename THandler>
127 decltype(comms::dispatchMsgStaticBinSearch<TAllMessages>(std::forward<TMsgId>(
id), msg, handler))
129 return comms::dispatchMsgStaticBinSearch<TAllMessages>(std::forward<TMsgId>(
id), msg, handler);
132 template <
typename TAllMessages,
typename TMsg,
typename THandler>
134 decltype(comms::dispatchMsgStaticBinSearch<TAllMessages>(msg, handler))
136 return comms::dispatchMsgStaticBinSearch<TAllMessages>(msg, handler);
139 template <
typename TAllMessages,
typename TMsgId,
typename TMsg,
typename THandler>
141 decltype(comms::dispatchMsgLinearSwitch<TAllMessages>(std::forward<TMsgId>(
id), idx, msg, handler))
143 return comms::dispatchMsgLinearSwitch<TAllMessages>(std::forward<TMsgId>(
id), idx, msg, handler);
146 template <
typename TAllMessages,
typename TMsgId,
typename TMsg,
typename THandler>
148 decltype(comms::dispatchMsgLinearSwitch<TAllMessages>(std::forward<TMsgId>(
id), msg, handler))
150 return comms::dispatchMsgLinearSwitch<TAllMessages>(std::forward<TMsgId>(
id), msg, handler);
153 template <
typename TAllMessages,
typename TMsg,
typename THandler>
155 decltype(comms::dispatchMsgLinearSwitch<TAllMessages>(msg, handler))
157 return comms::dispatchMsgLinearSwitch<TAllMessages>(msg, handler);
160 template <
typename TAllMessages>
161 static constexpr
bool isDispatchPolymorphicInternal(NoForcingTag)
163 return comms::dispatchMsgTypeIsPolymorphic<TAllMessages>();
166 template <
typename TAllMessages,
typename TTag>
167 static constexpr
bool isDispatchPolymorphicInternal(TTag)
169 static_assert(!std::is_same<TTag, NoForcingTag>::value,
"Invalid tag dispatch");
170 return std::is_same<TTag, comms::traits::dispatch::Polymorphic>::value;
173 template <
typename TAllMessages>
174 static constexpr
bool isDispatchStaticBinSearchInternal(NoForcingTag)
176 return comms::dispatchMsgTypeIsStaticBinSearch<TAllMessages>();
179 template <
typename TAllMessages,
typename TTag>
180 static constexpr
bool isDispatchStaticBinSearchInternal(TTag)
182 static_assert(!std::is_same<TTag, NoForcingTag>::value,
"Invalid tag dispatch");
183 return std::is_same<TTag, comms::traits::dispatch::StaticBinSearch>::value;
186 template <
typename TAllMessages>
187 static constexpr
bool isDispatchLinearSwitchInternal(NoForcingTag)
192 template <
typename TAllMessages,
typename TTag>
193 static constexpr
bool isDispatchLinearSwitchInternal(TTag)
195 static_assert(!std::is_same<TTag, NoForcingTag>::value,
"Invalid tag dispatch");
196 return std::is_same<TTag, comms::traits::dispatch::LinearSwitch>::value;
216 template <
typename TAllMessages,
typename TMsgId,
typename TMsg,
typename THandler>
217 static auto dispatch(TMsgId&&
id, std::size_t idx, TMsg& msg, THandler& handler) ->
218 decltype(dispatchInternal<TAllMessages>(std::forward<TMsgId>(
id), idx, msg, handler, Tag()))
220 return dispatchInternal<TAllMessages>(std::forward<TMsgId>(
id), idx, msg, handler, Tag());
231 template <
typename TAllMessages,
typename TMsgId,
typename TMsg,
typename THandler>
232 static auto dispatch(TMsgId&&
id, TMsg&& msg, THandler&& handler) ->
233 decltype(dispatchInternal<TAllMessages>(std::forward<TMsgId>(
id), msg, handler, Tag()))
235 return dispatchInternal<TAllMessages>(std::forward<TMsgId>(
id), msg, handler, Tag());
249 template <
typename TAllMessages,
typename TMsg,
typename THandler>
250 static auto dispatch(TMsg&& msg, THandler&& handler) ->
251 decltype(dispatchInternal<TAllMessages>(msg, handler, Tag()))
253 return dispatchInternal<TAllMessages>(msg, handler, Tag());
261 template <
typename TAllMessages>
264 return isDispatchPolymorphicInternal<TAllMessages>(Tag());
272 template <
typename TAllMessages>
275 return isDispatchStaticBinSearchInternal<TAllMessages>(Tag());
283 template <
typename TAllMessages>
286 return isDispatchLinearSwitchInternal<TAllMessages>(Tag());
293 template <
typename T>
294 struct IsMsgDispatcher
296 static constexpr
bool Value =
false;
299 template <
typename... TOptions>
300 struct IsMsgDispatcher<MsgDispatcher<TOptions...> >
302 static constexpr
bool Value =
true;
310 template <
typename T>
314 details::IsMsgDispatcher<T>::Value ||
315 details::hasMsgDispatcherTag<T>();
Contains definition of Message object interface and various base classes for custom messages.
An auxiliary class to force a particular way of dispatching message to its handler.
Definition: MsgDispatcher.h:63
static constexpr bool isDispatchPolymorphic()
Compile time inquiry whether polymorphic dispatch tables are generated internally to map message ID t...
Definition: MsgDispatcher.h:262
static constexpr bool isDispatchLinearSwitch()
Compile time inquiry whether linear switch dispatch is generated internally to map message ID to actu...
Definition: MsgDispatcher.h:284
ParsedOptionsInternal ParsedOptions
Parsed Options.
Definition: MsgDispatcher.h:201
constexpr bool isMsgDispatcher()
Compile time check whether the provided class is a variant of comms::MsgDispatcher.
Definition: MsgDispatcher.h:311
static auto dispatch(TMsgId &&id, std::size_t idx, TMsg &msg, THandler &handler) -> decltype(dispatchInternal< TAllMessages >(std::forward< TMsgId >(id), idx, msg, handler, Tag()))
Dispatch message to its handler.
Definition: MsgDispatcher.h:217
typename ParsedOptions::ForcedDispatch MsgDispatcherTag
Class detection tag.
Definition: MsgDispatcher.h:204
static auto dispatch(TMsgId &&id, TMsg &&msg, THandler &&handler) -> decltype(dispatchInternal< TAllMessages >(std::forward< TMsgId >(id), msg, handler, Tag()))
Dispatch message to its handler.
Definition: MsgDispatcher.h:232
static constexpr bool isDispatchStaticBinSearch()
Compile time inquiry whether static binary search dispatch is generated internally to map message ID ...
Definition: MsgDispatcher.h:273
static auto dispatch(TMsg &&msg, THandler &&handler) -> decltype(dispatchInternal< TAllMessages >(msg, handler, Tag()))
Dispatch message to its handler.
Definition: MsgDispatcher.h:250
Contains extra logic to help with dispatching message types and objects.
Main namespace for all classes / functions of COMMS library.
Tag class used to indicate linear switch dispatch.
Definition: traits.h:207
Tag class used to indicate polymorphic dispatch.
Definition: traits.h:201
Tag class used to indicate static binary search dispatch.
Definition: traits.h:204
Replacement to std::conditional.
Definition: type_traits.h:28
This file contains all the classes necessary to properly define message traits.
Replacement to some types from standard type_traits.