COMMS
Template library intended to help with implementation of communication protocols.
Loading...
Searching...
No Matches
transport_fields_access.h
1//
2// Copyright 2016 - 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 <tuple>
11#include <type_traits>
12
13#include "macro_common.h"
14#include "gen_enum.h"
15#include "base_detection.h"
16
17#ifdef COMMS_MUST_DEFINE_BASE
18#define COMMS_ACCESS_TRANSPORT_FIELD_FUNC(T_, t_, n_) \
19 typename std::tuple_element<COMMS_CONCATENATE(TransportFieldIdx_, n_), typename Base::T_>::type& COMMS_CONCATENATE(transportField_, n_)()
20#define COMMS_ACCESS_TRANSPORT_FIELD_CONST_FUNC(T_, t_, n_) \
21 const typename std::tuple_element<COMMS_CONCATENATE(TransportFieldIdx_, n_), typename Base::T_>::type& COMMS_CONCATENATE(transportField_, n_)() const
22#define COMMS_MSG_TRANSPORT_FIELDS_ACCESS_FUNC \
23 typename Base::TransportFields& transportFields()
24#define COMMS_MSG_TRANSPORT_FIELDS_ACCESS_CONST_FUNC \
25 const typename Base::TransportFields& transportFields() const
26
27#else // #ifdef COMMS_MUST_DEFINE_BASE
28#define COMMS_ACCESS_TRANSPORT_FIELD_FUNC(T_, t_, n_) FUNC_AUTO_REF_RETURN(COMMS_CONCATENATE(transportField_, n_), decltype(std::get<COMMS_CONCATENATE(TransportFieldIdx_, n_)>(t_)))
29#define COMMS_ACCESS_TRANSPORT_FIELD_CONST_FUNC(T_, t_, n_) FUNC_AUTO_REF_RETURN_CONST(COMMS_CONCATENATE(transportField_, n_), decltype(std::get<COMMS_CONCATENATE(TransportFieldIdx_, n_)>(t_)))
30#define COMMS_MSG_TRANSPORT_FIELDS_ACCESS_FUNC FUNC_AUTO_REF_RETURN(transportFields, decltype(comms::toMessage(*this).transportFields()))
31#define COMMS_MSG_TRANSPORT_FIELDS_ACCESS_CONST_FUNC FUNC_AUTO_REF_RETURN_CONST(transportFields, decltype(comms::toMessage(*this).transportFields()))
32#endif // #ifdef COMMS_MUST_DEFINE_BASE
33
34#define COMMS_TRANSPORT_FIELD_ACC_FUNC(T_, t_, n_) \
35 COMMS_ACCESS_TRANSPORT_FIELD_FUNC(T_, t_, n_) {\
36 return std::get<COMMS_CONCATENATE(TransportFieldIdx_, n_)>(t_); \
37 } \
38 COMMS_ACCESS_TRANSPORT_FIELD_CONST_FUNC(T_, t_, n_) {\
39 return std::get<COMMS_CONCATENATE(TransportFieldIdx_, n_)>(t_); \
40 }
41
42#define COMMS_TRANSPORT_FIELD_ACC_FUNC_1(T_, t_, n_) COMMS_TRANSPORT_FIELD_ACC_FUNC(T_, t_, n_)
43#define COMMS_TRANSPORT_FIELD_ACC_FUNC_2(T_, t_, n_, ...) \
44 COMMS_TRANSPORT_FIELD_ACC_FUNC(T_, t_, n_) \
45 COMMS_EXPAND(COMMS_TRANSPORT_FIELD_ACC_FUNC_1(T_, t_, __VA_ARGS__))
46#define COMMS_TRANSPORT_FIELD_ACC_FUNC_3(T_, t_, n_, ...) \
47 COMMS_TRANSPORT_FIELD_ACC_FUNC(T_, t_, n_) \
48 COMMS_EXPAND(COMMS_TRANSPORT_FIELD_ACC_FUNC_2(T_, t_, __VA_ARGS__))
49#define COMMS_TRANSPORT_FIELD_ACC_FUNC_4(T_, t_, n_, ...) \
50 COMMS_TRANSPORT_FIELD_ACC_FUNC(T_, t_, n_) \
51 COMMS_EXPAND(COMMS_TRANSPORT_FIELD_ACC_FUNC_3(T_, t_, __VA_ARGS__))
52#define COMMS_TRANSPORT_FIELD_ACC_FUNC_5(T_, t_, n_, ...) \
53 COMMS_TRANSPORT_FIELD_ACC_FUNC(T_, t_, n_) \
54 COMMS_EXPAND(COMMS_TRANSPORT_FIELD_ACC_FUNC_4(T_, t_, __VA_ARGS__))
55#define COMMS_TRANSPORT_FIELD_ACC_FUNC_6(T_, t_, n_, ...) \
56 COMMS_TRANSPORT_FIELD_ACC_FUNC(T_, t_, n_) \
57 COMMS_EXPAND(COMMS_TRANSPORT_FIELD_ACC_FUNC_5(T_, t_, __VA_ARGS__))
58#define COMMS_TRANSPORT_FIELD_ACC_FUNC_7(T_, t_, n_, ...) \
59 COMMS_TRANSPORT_FIELD_ACC_FUNC(T_, t_, n_) \
60 COMMS_EXPAND(COMMS_TRANSPORT_FIELD_ACC_FUNC_6(T_, t_, __VA_ARGS__))
61#define COMMS_TRANSPORT_FIELD_ACC_FUNC_8(T_, t_, n_, ...) \
62 COMMS_TRANSPORT_FIELD_ACC_FUNC(T_, t_, n_) \
63 COMMS_EXPAND(COMMS_TRANSPORT_FIELD_ACC_FUNC_7(T_, t_, __VA_ARGS__))
64#define COMMS_TRANSPORT_FIELD_ACC_FUNC_9(T_, t_, n_, ...) \
65 COMMS_TRANSPORT_FIELD_ACC_FUNC(T_, t_, n_) \
66 COMMS_EXPAND(COMMS_TRANSPORT_FIELD_ACC_FUNC_8(T_, t_, __VA_ARGS__))
67#define COMMS_TRANSPORT_FIELD_ACC_FUNC_10(T_, t_, n_, ...) \
68 COMMS_TRANSPORT_FIELD_ACC_FUNC(T_, t_, n_) \
69 COMMS_EXPAND(COMMS_TRANSPORT_FIELD_ACC_FUNC_9(T_, t_, __VA_ARGS__))
70#define COMMS_TRANSPORT_FIELD_ACC_FUNC_11(T_, t_, n_, ...) \
71 COMMS_TRANSPORT_FIELD_ACC_FUNC(T_, t_, n_) \
72 COMMS_EXPAND(COMMS_TRANSPORT_FIELD_ACC_FUNC_10(T_, t_, __VA_ARGS__))
73#define COMMS_TRANSPORT_FIELD_ACC_FUNC_12(T_, t_, n_, ...) \
74 COMMS_TRANSPORT_FIELD_ACC_FUNC(T_, t_, n_) \
75 COMMS_EXPAND(COMMS_TRANSPORT_FIELD_ACC_FUNC_11(T_, t_, __VA_ARGS__))
76#define COMMS_TRANSPORT_FIELD_ACC_FUNC_13(T_, t_, n_, ...) \
77 COMMS_TRANSPORT_FIELD_ACC_FUNC(T_, t_, n_) \
78 COMMS_EXPAND(COMMS_TRANSPORT_FIELD_ACC_FUNC_12(T_, t_, __VA_ARGS__))
79#define COMMS_TRANSPORT_FIELD_ACC_FUNC_14(T_, t_, n_, ...) \
80 COMMS_TRANSPORT_FIELD_ACC_FUNC(T_, t_, n_) \
81 COMMS_EXPAND(COMMS_TRANSPORT_FIELD_ACC_FUNC_13(T_, t_, __VA_ARGS__))
82#define COMMS_TRANSPORT_FIELD_ACC_FUNC_15(T_, t_, n_, ...) \
83 COMMS_TRANSPORT_FIELD_ACC_FUNC(T_, t_, n_) \
84 COMMS_EXPAND(COMMS_TRANSPORT_FIELD_ACC_FUNC_14(T_, t_, __VA_ARGS__))
85#define COMMS_TRANSPORT_FIELD_ACC_FUNC_16(T_, t_, n_, ...) \
86 COMMS_TRANSPORT_FIELD_ACC_FUNC(T_, t_, n_) \
87 COMMS_EXPAND(COMMS_TRANSPORT_FIELD_ACC_FUNC_15(T_, t_, __VA_ARGS__))
88#define COMMS_TRANSPORT_FIELD_ACC_FUNC_17(T_, t_, n_, ...) \
89 COMMS_TRANSPORT_FIELD_ACC_FUNC(T_, t_, n_) \
90 COMMS_EXPAND(COMMS_TRANSPORT_FIELD_ACC_FUNC_16(T_, t_, __VA_ARGS__))
91#define COMMS_TRANSPORT_FIELD_ACC_FUNC_18(T_, t_, n_, ...) \
92 COMMS_TRANSPORT_FIELD_ACC_FUNC(T_, t_, n_) \
93 COMMS_EXPAND(COMMS_TRANSPORT_FIELD_ACC_FUNC_17(T_, t_, __VA_ARGS__))
94#define COMMS_TRANSPORT_FIELD_ACC_FUNC_19(T_, t_, n_, ...) \
95 COMMS_TRANSPORT_FIELD_ACC_FUNC(T_, t_, n_) \
96 COMMS_EXPAND(COMMS_TRANSPORT_FIELD_ACC_FUNC_18(T_, t_, __VA_ARGS__))
97#define COMMS_TRANSPORT_FIELD_ACC_FUNC_20(T_, t_, n_, ...) \
98 COMMS_TRANSPORT_FIELD_ACC_FUNC(T_, t_, n_) \
99 COMMS_EXPAND(COMMS_TRANSPORT_FIELD_ACC_FUNC_19(T_, t_, __VA_ARGS__))
100#define COMMS_TRANSPORT_FIELD_ACC_FUNC_21(T_, t_, n_, ...) \
101 COMMS_TRANSPORT_FIELD_ACC_FUNC(T_, t_, n_) \
102 COMMS_EXPAND(COMMS_TRANSPORT_FIELD_ACC_FUNC_20(T_, t_, __VA_ARGS__))
103#define COMMS_TRANSPORT_FIELD_ACC_FUNC_22(T_, t_, n_, ...) \
104 COMMS_TRANSPORT_FIELD_ACC_FUNC(T_, t_, n_) \
105 COMMS_EXPAND(COMMS_TRANSPORT_FIELD_ACC_FUNC_21(T_, t_, __VA_ARGS__))
106#define COMMS_TRANSPORT_FIELD_ACC_FUNC_23(T_, t_, n_, ...) \
107 COMMS_TRANSPORT_FIELD_ACC_FUNC(T_, t_, n_) \
108 COMMS_EXPAND(COMMS_TRANSPORT_FIELD_ACC_FUNC_22(T_, t_, __VA_ARGS__))
109#define COMMS_TRANSPORT_FIELD_ACC_FUNC_24(T_, t_, n_, ...) \
110 COMMS_TRANSPORT_FIELD_ACC_FUNC(T_, t_, n_) \
111 COMMS_EXPAND(COMMS_TRANSPORT_FIELD_ACC_FUNC_23(T_, t_, __VA_ARGS__))
112#define COMMS_TRANSPORT_FIELD_ACC_FUNC_25(T_, t_, n_, ...) \
113 COMMS_TRANSPORT_FIELD_ACC_FUNC(T_, t_, n_) \
114 COMMS_EXPAND(COMMS_TRANSPORT_FIELD_ACC_FUNC_24(T_, t_, __VA_ARGS__))
115#define COMMS_TRANSPORT_FIELD_ACC_FUNC_26(T_, t_, n_, ...) \
116 COMMS_TRANSPORT_FIELD_ACC_FUNC(T_, t_, n_) \
117 COMMS_EXPAND(COMMS_TRANSPORT_FIELD_ACC_FUNC_25(T_, t_, __VA_ARGS__))
118#define COMMS_TRANSPORT_FIELD_ACC_FUNC_27(T_, t_, n_, ...) \
119 COMMS_TRANSPORT_FIELD_ACC_FUNC(T_, t_, n_) \
120 COMMS_EXPAND(COMMS_TRANSPORT_FIELD_ACC_FUNC_26(T_, t_, __VA_ARGS__))
121#define COMMS_TRANSPORT_FIELD_ACC_FUNC_28(T_, t_, n_, ...) \
122 COMMS_TRANSPORT_FIELD_ACC_FUNC(T_, t_, n_) \
123 COMMS_EXPAND(COMMS_TRANSPORT_FIELD_ACC_FUNC_27(T_, t_, __VA_ARGS__))
124#define COMMS_TRANSPORT_FIELD_ACC_FUNC_29(T_, t_, n_, ...) \
125 COMMS_TRANSPORT_FIELD_ACC_FUNC(T_, t_, n_) \
126 COMMS_EXPAND(COMMS_TRANSPORT_FIELD_ACC_FUNC_28(T_, t_, __VA_ARGS__))
127#define COMMS_TRANSPORT_FIELD_ACC_FUNC_30(T_, t_, n_, ...) \
128 COMMS_TRANSPORT_FIELD_ACC_FUNC(T_, t_, n_) \
129 COMMS_EXPAND(COMMS_TRANSPORT_FIELD_ACC_FUNC_29(T_, t_, __VA_ARGS__))
130#define COMMS_TRANSPORT_FIELD_ACC_FUNC_31(T_, t_, n_, ...) \
131 COMMS_TRANSPORT_FIELD_ACC_FUNC(T_, t_, n_) \
132 COMMS_EXPAND(COMMS_TRANSPORT_FIELD_ACC_FUNC_30(T_, t_, __VA_ARGS__))
133#define COMMS_TRANSPORT_FIELD_ACC_FUNC_32(T_, t_, n_, ...) \
134 COMMS_TRANSPORT_FIELD_ACC_FUNC(T_, t_, n_) \
135 COMMS_EXPAND(COMMS_TRANSPORT_FIELD_ACC_FUNC_31(T_, t_, __VA_ARGS__))
136#define COMMS_TRANSPORT_FIELD_ACC_FUNC_33(T_, t_, n_, ...) \
137 COMMS_TRANSPORT_FIELD_ACC_FUNC(T_, t_, n_) \
138 COMMS_EXPAND(COMMS_TRANSPORT_FIELD_ACC_FUNC_32(T_, t_, __VA_ARGS__))
139#define COMMS_TRANSPORT_FIELD_ACC_FUNC_34(T_, t_, n_, ...) \
140 COMMS_TRANSPORT_FIELD_ACC_FUNC(T_, t_, n_) \
141 COMMS_EXPAND(COMMS_TRANSPORT_FIELD_ACC_FUNC_33(T_, t_, __VA_ARGS__))
142#define COMMS_TRANSPORT_FIELD_ACC_FUNC_35(T_, t_, n_, ...) \
143 COMMS_TRANSPORT_FIELD_ACC_FUNC(T_, t_, n_) \
144 COMMS_EXPAND(COMMS_TRANSPORT_FIELD_ACC_FUNC_34(T_, t_, __VA_ARGS__))
145#define COMMS_TRANSPORT_FIELD_ACC_FUNC_36(T_, t_, n_, ...) \
146 COMMS_TRANSPORT_FIELD_ACC_FUNC(T_, t_, n_) \
147 COMMS_EXPAND(COMMS_TRANSPORT_FIELD_ACC_FUNC_35(T_, t_, __VA_ARGS__))
148#define COMMS_TRANSPORT_FIELD_ACC_FUNC_37(T_, t_, n_, ...) \
149 COMMS_TRANSPORT_FIELD_ACC_FUNC(T_, t_, n_) \
150 COMMS_EXPAND(COMMS_TRANSPORT_FIELD_ACC_FUNC_36(T_, t_, __VA_ARGS__))
151#define COMMS_TRANSPORT_FIELD_ACC_FUNC_38(T_, t_, n_, ...) \
152 COMMS_TRANSPORT_FIELD_ACC_FUNC(T_, t_, n_) \
153 COMMS_EXPAND(COMMS_TRANSPORT_FIELD_ACC_FUNC_37(T_, t_, __VA_ARGS__))
154#define COMMS_TRANSPORT_FIELD_ACC_FUNC_39(T_, t_, n_, ...) \
155 COMMS_TRANSPORT_FIELD_ACC_FUNC(T_, t_, n_) \
156 COMMS_EXPAND(COMMS_TRANSPORT_FIELD_ACC_FUNC_38(T_, t_, __VA_ARGS__))
157#define COMMS_TRANSPORT_FIELD_ACC_FUNC_40(T_, t_, n_, ...) \
158 COMMS_TRANSPORT_FIELD_ACC_FUNC(T_, t_, n_) \
159 COMMS_EXPAND(COMMS_TRANSPORT_FIELD_ACC_FUNC_39(T_, t_, __VA_ARGS__))
160#define COMMS_TRANSPORT_FIELD_ACC_FUNC_41(T_, t_, n_, ...) \
161 COMMS_TRANSPORT_FIELD_ACC_FUNC(T_, t_, n_) \
162 COMMS_EXPAND(COMMS_TRANSPORT_FIELD_ACC_FUNC_40(T_, t_, __VA_ARGS__))
163#define COMMS_TRANSPORT_FIELD_ACC_FUNC_42(T_, t_, n_, ...) \
164 COMMS_TRANSPORT_FIELD_ACC_FUNC(T_, t_, n_) \
165 COMMS_EXPAND(COMMS_TRANSPORT_FIELD_ACC_FUNC_41(T_, t_, __VA_ARGS__))
166#define COMMS_TRANSPORT_FIELD_ACC_FUNC_43(T_, t_, n_, ...) \
167 COMMS_TRANSPORT_FIELD_ACC_FUNC(T_, t_, n_) \
168 COMMS_EXPAND(COMMS_TRANSPORT_FIELD_ACC_FUNC_42(T_, t_, __VA_ARGS__))
169#define COMMS_TRANSPORT_FIELD_ACC_FUNC_44(T_, t_, n_, ...) \
170 COMMS_TRANSPORT_FIELD_ACC_FUNC(T_, t_, n_) \
171 COMMS_EXPAND(COMMS_TRANSPORT_FIELD_ACC_FUNC_43(T_, t_, __VA_ARGS__))
172#define COMMS_TRANSPORT_FIELD_ACC_FUNC_45(T_, t_, n_, ...) \
173 COMMS_TRANSPORT_FIELD_ACC_FUNC(T_, t_, n_) \
174 COMMS_EXPAND(COMMS_TRANSPORT_FIELD_ACC_FUNC_44(T_, t_, __VA_ARGS__))
175#define COMMS_TRANSPORT_FIELD_ACC_FUNC_46(T_, t_, n_, ...) \
176 COMMS_TRANSPORT_FIELD_ACC_FUNC(T_, t_, n_) \
177 COMMS_EXPAND(COMMS_TRANSPORT_FIELD_ACC_FUNC_45(T_, t_, __VA_ARGS__))
178#define COMMS_TRANSPORT_FIELD_ACC_FUNC_47(T_, t_, n_, ...) \
179 COMMS_TRANSPORT_FIELD_ACC_FUNC(T_, t_, n_) \
180 COMMS_EXPAND(COMMS_TRANSPORT_FIELD_ACC_FUNC_46(T_, t_, __VA_ARGS__))
181#define COMMS_TRANSPORT_FIELD_ACC_FUNC_48(T_, t_, n_, ...) \
182 COMMS_TRANSPORT_FIELD_ACC_FUNC(T_, t_, n_) \
183 COMMS_EXPAND(COMMS_TRANSPORT_FIELD_ACC_FUNC_47(T_, t_, __VA_ARGS__))
184
185#define COMMS_CHOOSE_TRANSPORT_FIELD_ACC_FUNC_(N, T_, t_, ...) COMMS_EXPAND(COMMS_TRANSPORT_FIELD_ACC_FUNC_ ## N(T_, t_, __VA_ARGS__))
186#define COMMS_CHOOSE_TRANSPORT_FIELD_ACC_FUNC(N, T_, t_, ...) COMMS_EXPAND(COMMS_CHOOSE_TRANSPORT_FIELD_ACC_FUNC_(N, T_, t_, __VA_ARGS__))
187#define COMMS_DO_TRANSPORT_FIELD_ACC_FUNC(T_, t_, ...) \
188 COMMS_EXPAND(COMMS_CHOOSE_TRANSPORT_FIELD_ACC_FUNC(COMMS_NUM_ARGS(__VA_ARGS__), T_, t_, __VA_ARGS__))
189
190#define COMMS_DEFINE_TRANSPORT_FIELD_ENUM(...) COMMS_EXPAND(COMMS_DEFINE_ENUM(TransportFieldIdx, __VA_ARGS__));
191
192
193
194
195
196
197
198
199
200
201
202