COMMS
Template library intended to help with implementation of communication protocols.
Loading...
Searching...
No Matches
AdaptBasicField.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 "adapters.h"
11#include "OptionsParser.h"
12
13namespace comms
14{
15
16namespace field
17{
18
19namespace details
20{
21
22template<
23 bool T1 = false,
24 bool T2 = false,
25 bool T3 = false,
26 bool T4 = false,
27 bool T5 = false,
28 bool T6 = false>
29struct FieldsOptionsCompatibilityCalc
30{
31 static const std::size_t Value =
32 static_cast<std::size_t>(T1) +\
33 static_cast<std::size_t>(T2) +
34 static_cast<std::size_t>(T3) +
35 static_cast<std::size_t>(T4) +
36 static_cast<std::size_t>(T5) +
37 static_cast<std::size_t>(T6);
38};
39
40//--
41
42template <typename TBasic, typename... TOptions>
43class AdaptBasicField
44{
45 using ParsedOptions = OptionsParser<TOptions...>;
46
47 static const bool CustomReaderIncompatible =
48 ParsedOptions::HasSerOffset ||
49 ParsedOptions::HasFixedLengthLimit ||
50 ParsedOptions::HasFixedBitLengthLimit ||
51 ParsedOptions::HasVarLengthLimits ||
52 ParsedOptions::HasAvailableLengthLimit ||
53 ParsedOptions::HasSequenceElemLengthForcing ||
54 ParsedOptions::HasSequenceSizeForcing ||
55 ParsedOptions::HasSequenceLengthForcing ||
56 ParsedOptions::HasSequenceFixedSize ||
57 ParsedOptions::HasSequenceSizeFieldPrefix ||
58 ParsedOptions::HasSequenceSerLengthFieldPrefix ||
59 ParsedOptions::HasSequenceElemSerLengthFieldPrefix ||
60 ParsedOptions::HasSequenceElemFixedSerLengthFieldPrefix ||
61 ParsedOptions::HasSequenceTrailingFieldSuffix ||
62 ParsedOptions::HasSequenceTerminationFieldSuffix ||
63 ParsedOptions::HasEmptySerialization ||
64 ParsedOptions::HasMissingOnReadFail;
65
66
67 static const bool VarLengthIncompatible =
68 ParsedOptions::HasFixedLengthLimit ||
69 ParsedOptions::HasFixedBitLengthLimit ||
70 ParsedOptions::HasAvailableLengthLimit;
71
72 static_assert(
73 (!ParsedOptions::HasVarLengthLimits) || (!VarLengthIncompatible),
74 "VarLength option is incompatible with FixedLength, FixedBitLength "
75 "and AvailableLengthLimit");
76
77 static_assert(
78 1U >= FieldsOptionsCompatibilityCalc<
79 ParsedOptions::HasSequenceSizeFieldPrefix,
80 ParsedOptions::HasSequenceSerLengthFieldPrefix,
81 ParsedOptions::HasSequenceFixedSize,
82 ParsedOptions::HasSequenceSizeForcing,
83 ParsedOptions::HasSequenceLengthForcing,
84 ParsedOptions::HasSequenceTerminationFieldSuffix>::Value,
85 "The following options are incompatible, cannot be used together: "
86 "SequenceSizeFieldPrefix, SequenceSerLengthFieldPrefix, "
87 "SequenceFixedSize, SequenceSizeForcingEnabled, SequenceLengthForcingEnabled, "
88 "SequenceTerminationFieldSuffix");
89
90 static_assert(
91 1U >= FieldsOptionsCompatibilityCalc<
92 ParsedOptions::HasSequenceElemSerLengthFieldPrefix,
93 ParsedOptions::HasSequenceElemFixedSerLengthFieldPrefix,
94 ParsedOptions::HasSequenceTerminationFieldSuffix>::Value,
95 "The following options are incompatible, cannot be used together: "
96 "SequenceElemSerLengthFieldPrefix, SequenceElemFixedSerLengthFieldPrefix "
97 "SequenceTerminationFieldSuffix");
98
99 static_assert(
100 (!ParsedOptions::HasSequenceTrailingFieldSuffix) ||
101 (!ParsedOptions::HasSequenceTerminationFieldSuffix),
102 "The following options are incompatible, cannot be used together: "
103 "SequenceTrailingFieldSuffix, SequenceTerminationFieldSuffix");
104
105 static_assert(
106 (!ParsedOptions::HasFailOnInvalid) ||
107 (!ParsedOptions::HasIgnoreInvalid),
108 "The following options are incompatible, cannot be used together: "
109 "FailOnInvalid, IgnoreInvalid");
110
111 static_assert(
112 1U >= FieldsOptionsCompatibilityCalc<
113 ParsedOptions::HasCustomStorageType,
114 ParsedOptions::HasFixedSizeStorage,
115 ParsedOptions::HasOrigDataView>::Value,
116 "The following options are incompatible, cannot be used together: "
117 "CustomStorageType, FixedSizeStorage, OrigDataView");
118
119 static_assert(
120 (!ParsedOptions::HasSequenceFixedSizeUseFixedSizeStorage) ||
121 (ParsedOptions::HasSequenceFixedSize),
122 "The option SequenceFixedSizeUseFixedSizeStorage cannot be used without SequenceFixedSize.");
123
124 static_assert(
125 (!ParsedOptions::HasSequenceFixedSizeUseFixedSizeStorage) ||
126 (!ParsedOptions::HasFixedSizeStorage),
127 "The following options are incompatible, cannot be used together: "
128 "SequenceFixedSizeUseFixedSizeStorage, FixedSizeStorage");
129
130 using FieldTypeAdapted =
131 typename ParsedOptions::template AdaptFieldType<TBasic>;
132
133 using InvalidByDefaultAdapted =
134 typename ParsedOptions::template AdaptInvalidByDefault<FieldTypeAdapted>;
135
136 using VersionStorageAdapted =
137 typename ParsedOptions::template AdaptVersionStorage<InvalidByDefaultAdapted>;
138
139 using SerOffsetAdapted =
140 typename ParsedOptions::template AdaptSerOffset<VersionStorageAdapted>;
141
142 using VersionsRangeAdapted =
143 typename ParsedOptions::template AdaptVersionsRange<SerOffsetAdapted>;
144
145 using FixedLengthLimitAdapted =
146 typename ParsedOptions::template AdaptFixedLengthLimit<VersionsRangeAdapted>;
147
148 using FixedBitLengthLimitAdapted =
149 typename ParsedOptions::template AdaptFixedBitLengthLimit<FixedLengthLimitAdapted>;
150
151 using VarLengthLimitsAdapted =
152 typename ParsedOptions::template AdaptVarLengthLimits<FixedBitLengthLimitAdapted>;
153
154 using AvailableLengthLimitAdapted =
155 typename ParsedOptions::template AdaptAvailableLengthLimit<VarLengthLimitsAdapted>;
156
157 using SequenceElemLengthForcingAdapted =
158 typename ParsedOptions::template AdaptSequenceElemLengthForcing<AvailableLengthLimitAdapted>;
159
160 using SequenceElemSerLengthFieldPrefixAdapted =
161 typename ParsedOptions::template AdaptSequenceElemSerLengthFieldPrefix<SequenceElemLengthForcingAdapted>;
162
163 using SequenceElemFixedSerLengthFieldPrefixAdapted =
164 typename ParsedOptions::template AdaptSequenceElemFixedSerLengthFieldPrefix<SequenceElemSerLengthFieldPrefixAdapted>;
165
166 using SequenceSizeForcingAdapted =
167 typename ParsedOptions::template AdaptSequenceSizeForcing<SequenceElemFixedSerLengthFieldPrefixAdapted>;
168
169 using SequenceLengthForcingAdapted =
170 typename ParsedOptions::template AdaptSequenceLengthForcing<SequenceSizeForcingAdapted>;
171
172 using SequenceFixedSizeAdapted =
173 typename ParsedOptions::template AdaptSequenceFixedSize<SequenceLengthForcingAdapted>;
174
175 using SequenceSizeFieldPrefixAdapted =
176 typename ParsedOptions::template AdaptSequenceSizeFieldPrefix<SequenceFixedSizeAdapted>;
177
178 using SequenceSerLengthFieldPrefixAdapted =
179 typename ParsedOptions::template AdaptSequenceSerLengthFieldPrefix<SequenceSizeFieldPrefixAdapted>;
180
181 using SequenceTrailingFieldSuffixAdapted =
182 typename ParsedOptions::template AdaptSequenceTrailingFieldSuffix<SequenceSerLengthFieldPrefixAdapted>;
183
184 using SequenceTerminationFieldSuffixAdapted =
185 typename ParsedOptions::template AdaptSequenceTerminationFieldSuffix<SequenceTrailingFieldSuffixAdapted>;
186
187 using RemLengthMemberFieldAdapted =
188 typename ParsedOptions::template AdaptRemLengthMemberField<SequenceTerminationFieldSuffixAdapted>;
189
190 using DefaultValueInitialiserAdapted =
191 typename ParsedOptions::template AdaptDefaultValueInitialiser<RemLengthMemberFieldAdapted>;
192
193 using MultiRangeValidationAdapted =
194 typename ParsedOptions::template AdaptMultiRangeValidation<DefaultValueInitialiserAdapted>;
195
196 using CustomValidatorAdapted =
197 typename ParsedOptions::template AdaptCustomValidator<MultiRangeValidationAdapted>;
198
199 using FailOnInvalidAdapted =
200 typename ParsedOptions::template AdaptFailOnInvalid<CustomValidatorAdapted>;
201
202 using IgnoreInvalidAdapted =
203 typename ParsedOptions::template AdaptIgnoreInvalid<FailOnInvalidAdapted>;
204
205 using EmptySerializationAdapted =
206 typename ParsedOptions::template AdaptEmptySerialization<IgnoreInvalidAdapted>;
207
208 using CustomReadWrapAdapted =
209 typename ParsedOptions::template AdaptCustomRead<EmptySerializationAdapted>;
210
211 using CustomRefreshWrapAdapted =
212 typename ParsedOptions::template AdaptCustomRefresh<CustomReadWrapAdapted>;
213
214 using CustomWriteWrapAdapted =
215 typename ParsedOptions::template AdaptCustomWrite<CustomRefreshWrapAdapted>;
216
217 using MissingOnInvalidAdapted =
218 typename ParsedOptions::template AdaptMissingOnInvalid<CustomWriteWrapAdapted>;
219
220 using MissingOnReadFailAdapted =
221 typename ParsedOptions::template AdaptMissingOnReadFail<MissingOnInvalidAdapted>;
222
223 using VariantResetOnDestructAdapted =
224 typename ParsedOptions::template AdaptVariantResetOnDestruct<MissingOnReadFailAdapted>;
225
226public:
227 using Type = VariantResetOnDestructAdapted;
228};
229
230template <typename TBasic, typename... TOptions>
231using AdaptBasicFieldT = typename AdaptBasicField<TBasic, TOptions...>::Type;
232
233} // namespace details
234
235} // namespace field
236
237} // namespace comms
238
239
Main namespace for all classes / functions of COMMS library.