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