COMMS
Template library intended to help with implementation of communication protocols.
Loading...
Searching...
No Matches
MessageInterfaceOptionsParser.h
1//
2// Copyright 2015 - 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/details/MessageInterfaceBases.h"
13#include "comms/options.h"
14#include "comms/util/Tuple.h"
15
16#include <cstdint>
17#include <limits>
18#include <tuple>
19
20namespace comms
21{
22
23namespace details
24{
25
26template <typename... TOptions>
27class MessageInterfaceOptionsParser;
28
29template <>
30class MessageInterfaceOptionsParser<>
31{
32public:
33 static constexpr bool HasEndian = false;
34 static constexpr bool HasMsgIdType = false;
35 static constexpr bool HasExtraTransportFields = false;
36 static constexpr bool HasVersionInExtraTransportFields = false;
37 static constexpr bool HasMsgIdInfo = false;
38 static constexpr bool HasReadIterator = false;
39 static constexpr bool HasWriteIterator = false;
40 static constexpr bool HasValid = false;
41 static constexpr bool HasLength = false;
42 static constexpr bool HasHandler = false;
43 static constexpr bool HasRefresh = false;
44 static constexpr bool HasName = false;
45 static constexpr bool HasNoVirtualDestructor = false;
46
47 static constexpr std::size_t VersionInExtraTransportFields = std::numeric_limits<std::size_t>::max();
48
49 template <typename TBase = MessageInterfaceEmptyBase>
50 using BuildEndian = TBase;
51
52 template <typename TBase>
53 using BuildMsgIdType = TBase;
54
55 template <typename TBase>
56 using BuildExtraTransportFields = TBase;
57
58 template <typename TBase>
59 using BuildVersionInExtraTransportFields = TBase;
60
61 template <typename TBase>
62 using BuildMsgIdInfo = TBase;
63
64 template <typename TBase>
65 using BuildReadBase = TBase;
66
67 template <typename TBase>
68 using BuildWriteBase = TBase;
69
70 template <typename TBase>
71 using BuildValid = TBase;
72
73 template <typename TBase>
74 using BuildLength = TBase;
75
76 template <typename TBase>
77 using BuildHandler = TBase;
78
79 template <typename TBase>
80 using BuildRefresh = TBase;
81
82 template <typename TBase>
83 using BuildName = TBase;
84};
85
86template <typename T, typename... TOptions>
87class MessageInterfaceOptionsParser<
88 comms::option::def::MsgIdType<T>,
89 TOptions...> : public MessageInterfaceOptionsParser<TOptions...>
90{
91public:
92 using MsgIdType = T;
93 static constexpr bool HasMsgIdType = true;
94
95 template <typename TBase>
96 using BuildMsgIdType = MessageInterfaceIdTypeBase<TBase, MsgIdType>;
97};
98
99template <typename... TOptions>
100class MessageInterfaceOptionsParser<
101 comms::option::app::IdInfoInterface,
102 TOptions...> : public MessageInterfaceOptionsParser<TOptions...>
103{
104public:
105 static constexpr bool HasMsgIdInfo = true;
106
107 template <typename TBase>
108 using BuildMsgIdInfo = MessageInterfaceIdInfoBase<TBase>;
109};
110
111template <typename TEndian, typename... TOptions>
112class MessageInterfaceOptionsParser<
113 comms::option::def::Endian<TEndian>,
114 TOptions...> : public MessageInterfaceOptionsParser<TOptions...>
115{
116public:
117 static constexpr bool HasEndian = true;
118 using Endian = TEndian;
119
120 template <typename TBase = MessageInterfaceEmptyBase>
121 using BuildEndian = MessageInterfaceEndianBase<Endian>;
122};
123
124template <typename TIter, typename... TOptions>
125class MessageInterfaceOptionsParser<
126 comms::option::app::ReadIterator<TIter>,
127 TOptions...> : public MessageInterfaceOptionsParser<TOptions...>
128{
129public:
130 static constexpr bool HasReadIterator = true;
131 using ReadIterator = TIter;
132
133 template <typename TBase>
134 using BuildReadBase = MessageInterfaceReadBase<TBase, ReadIterator>;
135};
136
137template <typename TIter, typename... TOptions>
138class MessageInterfaceOptionsParser<
139 comms::option::app::WriteIterator<TIter>,
140 TOptions...> : public MessageInterfaceOptionsParser<TOptions...>
141{
142public:
143 static constexpr bool HasWriteIterator = true;
144 using WriteIterator = TIter;
145
146 template <typename TBase>
147 using BuildWriteBase = MessageInterfaceWriteBase<TBase, WriteIterator>;
148};
149
150template <typename T, typename... TOptions>
151class MessageInterfaceOptionsParser<
152 comms::option::app::Handler<T>,
153 TOptions...> : public MessageInterfaceOptionsParser<TOptions...>
154{
155public:
156 static constexpr bool HasHandler = true;
157 using Handler = T;
158
159 template <typename TBase>
160 using BuildHandler = MessageInterfaceHandlerBase<TBase, Handler>;
161};
162
163template <typename... TOptions>
164class MessageInterfaceOptionsParser<
165 comms::option::app::ValidCheckInterface,
166 TOptions...> : public MessageInterfaceOptionsParser<TOptions...>
167{
168public:
169 static constexpr bool HasValid = true;
170
171 template <typename TBase>
172 using BuildValid = MessageInterfaceValidBase<TBase>;
173};
174
175template <typename... TOptions>
176class MessageInterfaceOptionsParser<
177 comms::option::app::LengthInfoInterface,
178 TOptions...> : public MessageInterfaceOptionsParser<TOptions...>
179{
180public:
181 static constexpr bool HasLength = true;
182
183 template <typename TBase>
184 using BuildLength = MessageInterfaceLengthBase<TBase>;
185};
186
187template <typename... TOptions>
188class MessageInterfaceOptionsParser<
189 comms::option::app::RefreshInterface,
190 TOptions...> : public MessageInterfaceOptionsParser<TOptions...>
191{
192public:
193 static constexpr bool HasRefresh = true;
194
195 template <typename TBase>
196 using BuildRefresh = MessageInterfaceRefreshBase<TBase>;
197};
198
199template <typename... TOptions>
200class MessageInterfaceOptionsParser<
201 comms::option::app::NameInterface,
202 TOptions...> : public MessageInterfaceOptionsParser<TOptions...>
203{
204public:
205 static constexpr bool HasName = true;
206
207 template <typename TBase>
208 using BuildName = MessageInterfaceNameBase<TBase>;
209};
210
211template <typename... TOptions>
212class MessageInterfaceOptionsParser<
213 comms::option::app::NoVirtualDestructor,
214 TOptions...> : public MessageInterfaceOptionsParser<TOptions...>
215{
216public:
217 static constexpr bool HasNoVirtualDestructor = true;
218};
219
220template <typename TFields, typename... TOptions>
221class MessageInterfaceOptionsParser<
222 comms::option::def::ExtraTransportFields<TFields>,
223 TOptions...> : public MessageInterfaceOptionsParser<TOptions...>
224{
225 static_assert(comms::util::isTuple<TFields>(),
226 "Template parameter to comms::option::def::ExtraTransportFields is expected to "
227 "be std::tuple.");
228public:
229 static constexpr bool HasExtraTransportFields = true;
230 using ExtraTransportFields = TFields;
231
232 template <typename TBase>
233 using BuildExtraTransportFields = MessageInterfaceExtraTransportFieldsBase<TBase, ExtraTransportFields>;
234};
235
236template <std::size_t TIdx, typename... TOptions>
237class MessageInterfaceOptionsParser<
238 comms::option::def::VersionInExtraTransportFields<TIdx>,
239 TOptions...> : public MessageInterfaceOptionsParser<TOptions...>
240{
241public:
242 static constexpr bool HasVersionInExtraTransportFields = true;
243 static constexpr std::size_t VersionInExtraTransportFields = TIdx;
244
245 template <typename TBase>
246 using BuildVersionInExtraTransportFields =
247 MessageInterfaceVersionInExtraTransportFieldsBase<TBase, VersionInExtraTransportFields>;
248};
249
250template <typename... TOptions>
251class MessageInterfaceOptionsParser<
252 comms::option::app::EmptyOption,
253 TOptions...> : public MessageInterfaceOptionsParser<TOptions...>
254{
255};
256
257template <typename... TBundledOptions, typename... TOptions>
258class MessageInterfaceOptionsParser<
259 std::tuple<TBundledOptions...>,
260 TOptions...> : public MessageInterfaceOptionsParser<TBundledOptions..., TOptions...>
261{
262};
263
264} // namespace details
265
266} // namespace comms
267
Contains various tuple type manipulation classes and functions.
comms::option::def::HasName HasName
Same as comms::option::def::HasName.
Definition options.h:1917
comms::option::app::WriteIterator< TIter > WriteIterator
Same as comms::option::app::WriteIterator.
Definition options.h:1983
comms::option::app::Handler< T > Handler
Same as comms::option::app::Handler.
Definition options.h:2008
comms::option::app::ReadIterator< TIter > ReadIterator
Same as comms::option::app::ReadIterator.
Definition options.h:1978
comms::option::def::ExtraTransportFields< TFields > ExtraTransportFields
Same as comms::option::def::ExtraTransportFields.
Definition options.h:1510
comms::option::def::VersionInExtraTransportFields< TIdx > VersionInExtraTransportFields
Same as comms::option::def::VersionInExtraTransportFields.
Definition options.h:1515
comms::option::def::Endian< TEndian > Endian
Same as comms::option::def::Endian.
Definition options.h:1473
comms::option::def::MsgIdType< T > MsgIdType
Same as comms::option::def::MsgIdType.
Definition options.h:1486
Main namespace for all classes / functions of COMMS library.
STL namespace.
Contains definition of all the options used by the COMMS library.