COMMS
Template library intended to help with implementation of communication protocols.
Loading...
Searching...
No Matches
process.h
1//
2// Copyright 2019 - 2024 (C). Alex Robenko. All rights reserved.
3//
4// This Source Code Form is subject to the terms of the Mozilla Public
5// License, v. 2.0. If a copy of the MPL was not distributed with this
6// file, You can obtain one at http://mozilla.org/MPL/2.0/.
7
8#pragma once
9
10#include <type_traits>
11
12#include "comms/Message.h"
13#include "comms/details/detect.h"
14
15namespace comms
16{
17
18namespace details
19{
20
21template <typename T>
22using ProcessMsgDecayType = typename std::decay<T>::type;
23
24template <bool TIsMessage, bool TIsMsgPtr>
25struct ProcessMsgIdRetrieveHelper
26{
27 template <typename T>
28 using Type = void;
29};
30
31template <>
32struct ProcessMsgIdRetrieveHelper<true, false>
33{
34 template <typename T>
35 using Type = comms::MessageIdType<T>;
36};
37
38template <>
39struct ProcessMsgIdRetrieveHelper<false, true>
40{
41private:
42 template <typename T>
43 using ElementType = typename T::element_type;
44public:
45 template <typename T>
46 using Type =
47 typename ProcessMsgIdRetrieveHelper<comms::isMessage<ElementType<T> >(), hasElementType<ElementType<T> >()>::
48 template Type<ElementType<T> >;
49};
50
51template <typename T>
52using ProcessMsgIdType =
53 typename ProcessMsgIdRetrieveHelper<comms::isMessage<ProcessMsgDecayType<T> >(), hasElementType<ProcessMsgDecayType<T> >()>::
54 template Type<ProcessMsgDecayType<T> >;
55
56
57template <bool TIsMessage, bool TIsMsgPtr>
58struct ProcessMsgCastToMsgObjHelper;
59
60template <>
61struct ProcessMsgCastToMsgObjHelper<true, false>
62{
63 template <typename T>
64 static auto cast(T& msg) -> decltype(msg)
65 {
66 return msg;
67 }
68};
69
70template <>
71struct ProcessMsgCastToMsgObjHelper<false, true>
72{
73 template <typename T>
74 static auto cast(T& msg) -> decltype(*msg)
75 {
76 return *msg;
77 }
78};
79
80template <typename T>
81using ProcessMsgCastParamIsMessage =
82 std::integral_constant<
83 bool,
84 isMessage<ProcessMsgDecayType<T> >()
85 >;
86
87template <typename T>
88using ProcessMsgCastParamIsMsgPtr =
89 std::integral_constant<
90 bool,
91 hasElementType<ProcessMsgDecayType<T> >()
92 >;
93
94template <typename T>
95auto processMsgCastToMsgObj(T& msg) ->
96 decltype(ProcessMsgCastToMsgObjHelper<ProcessMsgCastParamIsMessage<T>::value, ProcessMsgCastParamIsMsgPtr<T>::value>::cast(msg))
97{
98 return ProcessMsgCastToMsgObjHelper<ProcessMsgCastParamIsMessage<T>::value, ProcessMsgCastParamIsMsgPtr<T>::value>::cast(msg);
99}
100
101} // namespace details
102
103} // namespace comms
Contains definition of Message object interface and various base classes for custom messages.
Main namespace for all classes / functions of COMMS library.
typename comms::util::LazyDeepConditional< TMsg::InterfaceOptions::HasMsgIdType >::template Type< comms::details::MessageIdTypeRetriever, comms::util::AliasType, TDefaultType, TMsg > MessageIdType
Get type of message ID used by interface class.
Definition Message.h:564