COMMS
Template library intended to help with implementation of communication protocols.
Loading...
Searching...
No Matches
FrameLayerDetails.h
1//
2// Copyright 2014 - 2025 (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 "comms/details/detect.h"
11
12namespace comms
13{
14
15namespace frame
16{
17
18namespace details
19{
20
21template <typename T, bool THasImpl>
22struct FrameLayerHasFieldsImplHelper;
23
24template <typename T>
25struct FrameLayerHasFieldsImplHelper<T, true>
26{
27 static const bool Value = T::hasFields();
28};
29
30template <typename T>
31struct FrameLayerHasFieldsImplHelper<T, false>
32{
33 static const bool Value = false;
34};
35
36template <typename T>
37struct FrameLayerHasFieldsImpl
38{
39 static const bool Value =
40 FrameLayerHasFieldsImplHelper<T, comms::details::hasImplOptions<T>()>::Value;
41};
42
43template <class T>
44constexpr bool frameLayerHasFieldsImpl()
45{
46 return FrameLayerHasFieldsImpl<T>::Value;
47}
48
49template <typename T, bool THasImpl>
50struct FrameLayerHasDoGetIdHelper;
51
52template <typename T>
53struct FrameLayerHasDoGetIdHelper<T, true>
54{
55 static const bool Value = T::hasStaticMsgId();
56};
57
58template <typename T>
59struct FrameLayerHasDoGetIdHelper<T, false>
60{
61 static const bool Value = false;
62};
63
64template <typename T>
65struct FrameLayerHasDoGetId
66{
67 static const bool Value =
68 FrameLayerHasDoGetIdHelper<T, comms::details::hasImplOptions<T>()>::Value;
69};
70
71template <typename T>
72constexpr bool frameLayerHasDoGetId()
73{
74 return FrameLayerHasDoGetId<T>::Value;
75}
76
77template <class T, class R = void>
78struct FrameLayerEnableIfHasMsgPtr { using Type = R; };
79
80template <class T, class Enable = void>
81struct FrameLayerMsgPtr
82{
83 using Type = void;
84};
85
86template <class T>
87struct FrameLayerMsgPtr<T, typename FrameLayerEnableIfHasMsgPtr<typename T::MsgPtr>::Type>
88{
89 using Type = typename T::MsgPtr;
90};
91
92template<typename...>
93class MissingSizeRetriever
94{
95public:
96 MissingSizeRetriever(std::size_t& val) : m_value(val) {}
97
98 void setValue(std::size_t val)
99 {
100 m_value = val;
101 }
102
103private:
104 std::size_t& m_value;
105};
106
107template <typename T>
108struct IsMissingSizeRetrieverHelper
109{
110 static const bool Value = false;
111};
112
113template <typename... TParams>
114struct IsMissingSizeRetrieverHelper<MissingSizeRetriever<TParams...> >
115{
116 static const bool Value = true;
117};
118
119template <typename T>
120constexpr bool isMissingSizeRetriever()
121{
122 return IsMissingSizeRetrieverHelper<T>::Value;
123}
124
125template <typename TId>
126class MsgIdRetriever
127{
128public:
129 MsgIdRetriever(TId& val) : m_value(val) {}
130
131 template <typename U>
132 void setValue(U&& val)
133 {
134 m_value = static_cast<TId>(val);
135 }
136
137private:
138 TId& m_value;
139};
140
141template <typename T>
142struct IsMsgIdRetrieverHelper
143{
144 static const bool Value = false;
145};
146
147template <typename TId>
148struct IsMsgIdRetrieverHelper<MsgIdRetriever<TId> >
149{
150 static const bool Value = true;
151};
152
153template <typename T>
154constexpr bool isMsgIdRetriever()
155{
156 return IsMsgIdRetrieverHelper<T>::Value;
157}
158
159class MsgIndexRetriever
160{
161public:
162 MsgIndexRetriever(std::size_t& val) : m_value(val) {}
163
164 void setValue(std::size_t val)
165 {
166 m_value = val;
167 }
168
169private:
170 std::size_t& m_value;
171};
172
173template <typename T>
174struct IsMsgIndexRetrieverHelper
175{
176 static const bool Value = false;
177};
178
179template <>
180struct IsMsgIndexRetrieverHelper<MsgIndexRetriever>
181{
182 static const bool Value = true;
183};
184
185template <typename T>
186constexpr bool isMsgIndexRetriever()
187{
188 return IsMsgIndexRetrieverHelper<T>::Value;
189}
190
191template <typename... TRetrievers>
192struct MsgIndexRetrieverDetector;
193
194template <typename T, typename... TRetrievers>
195struct MsgIndexRetrieverDetector<T, TRetrievers...>
196{
197 static const bool Detected = isMsgIndexRetriever<typename std::decay<T>::type>() || MsgIndexRetrieverDetector<TRetrievers...>::Detected;
198};
199
200template <typename... TRetrievers>
201constexpr bool hasMsgIndexRetriever()
202{
203 return MsgIndexRetrieverDetector<TRetrievers...>::Detected;
204}
205
206template <>
207struct MsgIndexRetrieverDetector<>
208{
209 static const bool Detected = false;
210};
211
212template <typename TIter>
213class MsgPayloadRetriever
214{
215public:
216 MsgPayloadRetriever(TIter& iter, std::size_t& len) : m_iter(iter), m_len(len) {}
217
218 template <typename TOtherIter>
219 void setValue(TOtherIter iter, std::size_t len)
220 {
221 m_iter = static_cast<TIter>(iter);
222 m_len = len;
223 }
224
225private:
226 TIter& m_iter;
227 std::size_t& m_len;
228};
229
230template <typename TITer>
231struct IsMsgPayloadRetrieverHelper
232{
233 static const bool Value = false;
234};
235
236template <typename TIter>
237struct IsMsgPayloadRetrieverHelper<MsgPayloadRetriever<TIter> >
238{
239 static const bool Value = true;
240};
241
242template <typename T>
243constexpr bool isMsgPayloadRetriever()
244{
245 return IsMsgPayloadRetrieverHelper<T>::Value;
246}
247
248} // namespace details
249
250} // namespace frame
251
252} // namespace comms
Main namespace for all classes / functions of COMMS library.