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