18#include "comms/details/tag.h"
48template <
typename TDefault,
typename TAll,
typename TRetType =
void>
52 "TAll must be std::tuple");
54#ifdef FOR_DOXYGEN_DOC_ONLY
61 virtual TRetType
handle(TDefault& msg);
89class GenericHandler<TDefault,
std::tuple<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, TRest...>, TRetType>
92 using BaseImpl =
GenericHandler<TDefault, std::tuple<TRest...>, TRetType>;
95 using BaseImpl::handle;
96 virtual TRetType
handle(T1& msg)
98 static_assert(std::is_base_of<TDefault, T1>::value,
99 "TDefault must be base class for every element in TAll");
101 return this->
handle(
static_cast<TDefault&
>(msg));
104 virtual TRetType
handle(T2& msg)
106 static_assert(std::is_base_of<TDefault, T2>::value,
107 "TDefault must be base class for every element in TAll");
109 return this->
handle(
static_cast<TDefault&
>(msg));
112 virtual TRetType
handle(T3& msg)
114 static_assert(std::is_base_of<TDefault, T3>::value,
115 "TDefault must be base class for every element in TAll");
117 return this->
handle(
static_cast<TDefault&
>(msg));
120 virtual TRetType
handle(T4& msg)
122 static_assert(std::is_base_of<TDefault, T4>::value,
123 "TDefault must be base class for every element in TAll");
125 return this->
handle(
static_cast<TDefault&
>(msg));
128 virtual TRetType
handle(T5& msg)
130 static_assert(std::is_base_of<TDefault, T5>::value,
131 "TDefault must be base class for every element in TAll");
133 return this->
handle(
static_cast<TDefault&
>(msg));
136 virtual TRetType
handle(T6& msg)
138 static_assert(std::is_base_of<TDefault, T6>::value,
139 "TDefault must be base class for every element in TAll");
141 return this->
handle(
static_cast<TDefault&
>(msg));
144 virtual TRetType
handle(T7& msg)
146 static_assert(std::is_base_of<TDefault, T7>::value,
147 "TDefault must be base class for every element in TAll");
149 return this->
handle(
static_cast<TDefault&
>(msg));
152 virtual TRetType
handle(T8& msg)
154 static_assert(std::is_base_of<TDefault, T8>::value,
155 "TDefault must be base class for every element in TAll");
157 return this->
handle(
static_cast<TDefault&
>(msg));
160 virtual TRetType
handle(T9& msg)
162 static_assert(std::is_base_of<TDefault, T9>::value,
163 "TDefault must be base class for every element in TAll");
165 return this->
handle(
static_cast<TDefault&
>(msg));
168 virtual TRetType
handle(T10& msg)
170 static_assert(std::is_base_of<TDefault, T10>::value,
171 "TDefault must be base class for every element in TAll");
173 return this->
handle(
static_cast<TDefault&
>(msg));
183template <
typename TDefault,
typename TRetType>
184class GenericHandlerBase
187 using RetType = TRetType;
189 virtual TRetType handle(TDefault& msg)
192 static_cast<void>(msg);
195 typename comms::util::LazyShallowConditional<
196 std::is_void<TRetType>::value
199 RetValueShallowCondWrap
202 return defaultHandle(Tag());
206 template <
typename... TParams>
207 using VoidReturnTag = comms::details::tag::Tag1<>;
209 template <
typename... TParams>
210 using ReferenceReturnTag = comms::details::tag::Tag2<>;
212 template <
typename... TParams>
213 using ValueReturnTag = comms::details::tag::Tag3<>;
215 template <
typename... TParams>
216 using RetValueShallowCondWrap =
217 typename comms::util::LazyShallowConditional<
218 std::is_lvalue_reference<TRetType>::value
225 template <
typename... TParams>
226 void defaultHandle(VoidReturnTag<TParams...>)
230 template <
typename... TParams>
231 TRetType defaultHandle(ReferenceReturnTag<TParams...>)
233 static typename std::decay<TRetType>::type Value;
237 template <
typename... TParams>
238 TRetType defaultHandle(ValueReturnTag<TParams...>)
240 return typename std::decay<TRetType>::type();
259class GenericHandler<TDefault,
std::tuple<T1, T2, T3, T4, T5, T6, T7, T8, T9>, TRetType> :
public
260 details::GenericHandlerBase<TDefault, TRetType>
262 using BaseImpl = details::GenericHandlerBase<TDefault, TRetType>;
265 using BaseImpl::handle;
266 virtual TRetType handle(T1& msg)
268 static_assert(std::is_base_of<TDefault, T1>::value,
269 "TDefault must be base class for every element in TAll");
271 return this->handle(
static_cast<TDefault&
>(msg));
274 virtual TRetType handle(T2& msg)
276 static_assert(std::is_base_of<TDefault, T2>::value,
277 "TDefault must be base class for every element in TAll");
279 return this->handle(
static_cast<TDefault&
>(msg));
282 virtual TRetType handle(T3& msg)
284 static_assert(std::is_base_of<TDefault, T3>::value,
285 "TDefault must be base class for every element in TAll");
287 return this->handle(
static_cast<TDefault&
>(msg));
290 virtual TRetType handle(T4& msg)
292 static_assert(std::is_base_of<TDefault, T4>::value,
293 "TDefault must be base class for every element in TAll");
295 return this->handle(
static_cast<TDefault&
>(msg));
298 virtual TRetType handle(T5& msg)
300 static_assert(std::is_base_of<TDefault, T5>::value,
301 "TDefault must be base class for every element in TAll");
303 return this->handle(
static_cast<TDefault&
>(msg));
306 virtual TRetType handle(T6& msg)
308 static_assert(std::is_base_of<TDefault, T6>::value,
309 "TDefault must be base class for every element in TAll");
311 return this->handle(
static_cast<TDefault&
>(msg));
314 virtual TRetType handle(T7& msg)
316 static_assert(std::is_base_of<TDefault, T7>::value,
317 "TDefault must be base class for every element in TAll");
319 return this->handle(
static_cast<TDefault&
>(msg));
322 virtual TRetType handle(T8& msg)
324 static_assert(std::is_base_of<TDefault, T8>::value,
325 "TDefault must be base class for every element in TAll");
327 return this->handle(
static_cast<TDefault&
>(msg));
330 virtual TRetType handle(T9& msg)
332 static_assert(std::is_base_of<TDefault, T9>::value,
333 "TDefault must be base class for every element in TAll");
335 return this->handle(
static_cast<TDefault&
>(msg));
339 ~GenericHandler() noexcept = default;
353class GenericHandler<TDefault,
std::tuple<T1, T2, T3, T4, T5, T6, T7, T8>, TRetType> : public
354 details::GenericHandlerBase<TDefault, TRetType>
356 using BaseImpl = details::GenericHandlerBase<TDefault, TRetType>;
359 using BaseImpl::handle;
360 virtual TRetType handle(T1& msg)
362 static_assert(std::is_base_of<TDefault, T1>::value,
363 "TDefault must be base class for every element in TAll");
365 return this->handle(
static_cast<TDefault&
>(msg));
368 virtual TRetType handle(T2& msg)
370 static_assert(std::is_base_of<TDefault, T2>::value,
371 "TDefault must be base class for every element in TAll");
373 return this->handle(
static_cast<TDefault&
>(msg));
376 virtual TRetType handle(T3& msg)
378 static_assert(std::is_base_of<TDefault, T3>::value,
379 "TDefault must be base class for every element in TAll");
381 return this->handle(
static_cast<TDefault&
>(msg));
384 virtual TRetType handle(T4& msg)
386 static_assert(std::is_base_of<TDefault, T4>::value,
387 "TDefault must be base class for every element in TAll");
389 return this->handle(
static_cast<TDefault&
>(msg));
392 virtual TRetType handle(T5& msg)
394 static_assert(std::is_base_of<TDefault, T5>::value,
395 "TDefault must be base class for every element in TAll");
397 return this->handle(
static_cast<TDefault&
>(msg));
400 virtual TRetType handle(T6& msg)
402 static_assert(std::is_base_of<TDefault, T6>::value,
403 "TDefault must be base class for every element in TAll");
405 return this->handle(
static_cast<TDefault&
>(msg));
408 virtual TRetType handle(T7& msg)
410 static_assert(std::is_base_of<TDefault, T7>::value,
411 "TDefault must be base class for every element in TAll");
413 return this->handle(
static_cast<TDefault&
>(msg));
416 virtual TRetType handle(T8& msg)
418 static_assert(std::is_base_of<TDefault, T8>::value,
419 "TDefault must be base class for every element in TAll");
421 return this->handle(
static_cast<TDefault&
>(msg));
425 ~GenericHandler() noexcept = default;
438class GenericHandler<TDefault,
std::tuple<T1, T2, T3, T4, T5, T6, T7>, TRetType> : public
439 details::GenericHandlerBase<TDefault, TRetType>
441 using BaseImpl = details::GenericHandlerBase<TDefault, TRetType>;
444 using BaseImpl::handle;
445 virtual TRetType handle(T1& msg)
447 static_assert(std::is_base_of<TDefault, T1>::value,
448 "TDefault must be base class for every element in TAll");
450 return this->handle(
static_cast<TDefault&
>(msg));
453 virtual TRetType handle(T2& msg)
455 static_assert(std::is_base_of<TDefault, T2>::value,
456 "TDefault must be base class for every element in TAll");
458 return this->handle(
static_cast<TDefault&
>(msg));
461 virtual TRetType handle(T3& msg)
463 static_assert(std::is_base_of<TDefault, T3>::value,
464 "TDefault must be base class for every element in TAll");
466 return this->handle(
static_cast<TDefault&
>(msg));
469 virtual TRetType handle(T4& msg)
471 static_assert(std::is_base_of<TDefault, T4>::value,
472 "TDefault must be base class for every element in TAll");
474 return this->handle(
static_cast<TDefault&
>(msg));
477 virtual TRetType handle(T5& msg)
479 static_assert(std::is_base_of<TDefault, T5>::value,
480 "TDefault must be base class for every element in TAll");
482 return this->handle(
static_cast<TDefault&
>(msg));
485 virtual TRetType handle(T6& msg)
487 static_assert(std::is_base_of<TDefault, T6>::value,
488 "TDefault must be base class for every element in TAll");
490 return this->handle(
static_cast<TDefault&
>(msg));
493 virtual TRetType handle(T7& msg)
495 static_assert(std::is_base_of<TDefault, T7>::value,
496 "TDefault must be base class for every element in TAll");
498 return this->handle(
static_cast<TDefault&
>(msg));
503 ~GenericHandler() noexcept = default;
515class GenericHandler<TDefault,
std::tuple<T1, T2, T3, T4, T5, T6>, TRetType> : public
516 details::GenericHandlerBase<TDefault, TRetType>
518 using BaseImpl = details::GenericHandlerBase<TDefault, TRetType>;
521 using BaseImpl::handle;
522 virtual TRetType handle(T1& msg)
524 static_assert(std::is_base_of<TDefault, T1>::value,
525 "TDefault must be base class for every element in TAll");
527 return this->handle(
static_cast<TDefault&
>(msg));
530 virtual TRetType handle(T2& msg)
532 static_assert(std::is_base_of<TDefault, T2>::value,
533 "TDefault must be base class for every element in TAll");
535 return this->handle(
static_cast<TDefault&
>(msg));
538 virtual TRetType handle(T3& msg)
540 static_assert(std::is_base_of<TDefault, T3>::value,
541 "TDefault must be base class for every element in TAll");
543 return this->handle(
static_cast<TDefault&
>(msg));
546 virtual TRetType handle(T4& msg)
548 static_assert(std::is_base_of<TDefault, T4>::value,
549 "TDefault must be base class for every element in TAll");
551 return this->handle(
static_cast<TDefault&
>(msg));
554 virtual TRetType handle(T5& msg)
556 static_assert(std::is_base_of<TDefault, T5>::value,
557 "TDefault must be base class for every element in TAll");
559 return this->handle(
static_cast<TDefault&
>(msg));
562 virtual TRetType handle(T6& msg)
564 static_assert(std::is_base_of<TDefault, T6>::value,
565 "TDefault must be base class for every element in TAll");
567 return this->handle(
static_cast<TDefault&
>(msg));
572 ~GenericHandler() noexcept = default;
583class GenericHandler<TDefault,
std::tuple<T1, T2, T3, T4, T5>, TRetType> : public
584 details::GenericHandlerBase<TDefault, TRetType>
586 using BaseImpl = details::GenericHandlerBase<TDefault, TRetType>;
589 using BaseImpl::handle;
590 virtual TRetType handle(T1& msg)
592 static_assert(std::is_base_of<TDefault, T1>::value,
593 "TDefault must be base class for every element in TAll");
595 return this->handle(
static_cast<TDefault&
>(msg));
598 virtual TRetType handle(T2& msg)
600 static_assert(std::is_base_of<TDefault, T2>::value,
601 "TDefault must be base class for every element in TAll");
603 return this->handle(
static_cast<TDefault&
>(msg));
606 virtual TRetType handle(T3& msg)
608 static_assert(std::is_base_of<TDefault, T3>::value,
609 "TDefault must be base class for every element in TAll");
611 return this->handle(
static_cast<TDefault&
>(msg));
614 virtual TRetType handle(T4& msg)
616 static_assert(std::is_base_of<TDefault, T4>::value,
617 "TDefault must be base class for every element in TAll");
619 return this->handle(
static_cast<TDefault&
>(msg));
622 virtual TRetType handle(T5& msg)
624 static_assert(std::is_base_of<TDefault, T5>::value,
625 "TDefault must be base class for every element in TAll");
627 return this->handle(
static_cast<TDefault&
>(msg));
632 ~GenericHandler() noexcept = default;
642class GenericHandler<TDefault,
std::tuple<T1, T2, T3, T4>, TRetType> : public
643 details::GenericHandlerBase<TDefault, TRetType>
645 using BaseImpl = details::GenericHandlerBase<TDefault, TRetType>;
648 using BaseImpl::handle;
649 virtual TRetType handle(T1& msg)
651 static_assert(std::is_base_of<TDefault, T1>::value,
652 "TDefault must be base class for every element in TAll");
654 return this->handle(
static_cast<TDefault&
>(msg));
657 virtual TRetType handle(T2& msg)
659 static_assert(std::is_base_of<TDefault, T2>::value,
660 "TDefault must be base class for every element in TAll");
662 return this->handle(
static_cast<TDefault&
>(msg));
665 virtual TRetType handle(T3& msg)
667 static_assert(std::is_base_of<TDefault, T3>::value,
668 "TDefault must be base class for every element in TAll");
670 return this->handle(
static_cast<TDefault&
>(msg));
673 virtual TRetType handle(T4& msg)
675 static_assert(std::is_base_of<TDefault, T4>::value,
676 "TDefault must be base class for every element in TAll");
678 return this->handle(
static_cast<TDefault&
>(msg));
682 ~GenericHandler() noexcept = default;
685template <typename TDefault, typename T1, typename T2, typename T3, typename TRetType>
686class GenericHandler<TDefault,
std::tuple<T1, T2, T3>, TRetType> : public
687 details::GenericHandlerBase<TDefault, TRetType>
689 using BaseImpl = details::GenericHandlerBase<TDefault, TRetType>;
692 using BaseImpl::handle;
693 virtual TRetType handle(T1& msg)
695 static_assert(std::is_base_of<TDefault, T1>::value,
696 "TDefault must be base class for every element in TAll");
698 return this->handle(
static_cast<TDefault&
>(msg));
701 virtual TRetType handle(T2& msg)
703 static_assert(std::is_base_of<TDefault, T2>::value,
704 "TDefault must be base class for every element in TAll");
706 return this->handle(
static_cast<TDefault&
>(msg));
709 virtual TRetType handle(T3& msg)
711 static_assert(std::is_base_of<TDefault, T3>::value,
712 "TDefault must be base class for every element in TAll");
714 return this->handle(
static_cast<TDefault&
>(msg));
718 ~GenericHandler() noexcept = default;
721template <typename TDefault, typename T1, typename T2, typename TRetType>
722class GenericHandler<TDefault,
std::tuple<T1, T2>, TRetType> : public
723 details::GenericHandlerBase<TDefault, TRetType>
725 using BaseImpl = details::GenericHandlerBase<TDefault, TRetType>;
728 using BaseImpl::handle;
729 virtual TRetType handle(T1& msg)
731 static_assert(std::is_base_of<TDefault, T1>::value,
732 "TDefault must be base class for every element in TAll");
734 return this->handle(
static_cast<TDefault&
>(msg));
737 virtual TRetType handle(T2& msg)
739 static_assert(std::is_base_of<TDefault, T2>::value,
740 "TDefault must be base class for every element in TAll");
742 return this->handle(
static_cast<TDefault&
>(msg));
746 ~GenericHandler() noexcept = default;
749template <typename TDefault, typename T1, typename TRetType>
750class GenericHandler<TDefault,
std::tuple<T1>, TRetType> : public
751 details::GenericHandlerBase<TDefault, TRetType>
753 using BaseImpl = details::GenericHandlerBase<TDefault, TRetType>;
756 using BaseImpl::handle;
757 virtual TRetType handle(T1& msg)
759 static_assert(std::is_base_of<TDefault, T1>::value,
760 "TDefault must be base class for every element in TAll");
762 return this->handle(
static_cast<TDefault&
>(msg));
766 ~GenericHandler() noexcept = default;
769template <typename TDefault, typename TRetType>
770class GenericHandler<TDefault,
std::tuple<>, TRetType> : public
771 details::GenericHandlerBase<TDefault, TRetType>
773 using BaseImpl = details::GenericHandlerBase<TDefault, TRetType>;
775 using BaseImpl::handle;
777 ~GenericHandler() noexcept = default;
Contains various tuple type manipulation classes and functions.
Generic common message handler.
Definition GenericHandler.h:50
~GenericHandler() noexcept=default
Destructor.
virtual TRetType handle(TDefault &msg)
Handle message object.
TRetType RetType
Return type of every handle() member function.
Definition GenericHandler.h:57
Main namespace for all classes / functions of COMMS library.
Check whether provided type is a variant of std::tuple.
Definition Tuple.h:36
Replacement to some types from standard type_traits.