16#include "comms/field/details/FieldOpHelpers.h"
17#include "comms/field/details/MembersVersionDependency.h"
19#include "CommonFuncs.h"
33template <comms::field::details::MembersVersionDependency TVersionDependency,
typename... TMembers>
34struct BundleVersionDependencyDetectHelper;
36template <
typename... TMembers>
37struct BundleVersionDependencyDetectHelper<
comms::field::details::MembersVersionDependency_NotSpecified, TMembers...>
39 static constexpr bool Value = CommonFuncs::IsAnyFieldVersionDependentBoolType<TMembers...>::value;
42template <
typename... TMembers>
43struct BundleVersionDependencyDetectHelper<
comms::field::details::MembersVersionDependency_Independent, TMembers...>
45 static constexpr bool Value =
false;
48template <
typename... TMembers>
49struct BundleVersionDependencyDetectHelper<
comms::field::details::MembersVersionDependency_Dependent, TMembers...>
51 static constexpr bool Value =
true;
57template <
typename TFieldBase, comms::field::details::MembersVersionDependency TVersionDependency,
typename TMembers>
60template <
typename TFieldBase, comms::field::details::MembersVersionDependency TVersionDependency,
typename... TMembers>
61class Bundle<TFieldBase, TVersionDependency,
std::tuple<TMembers...> > :
public TFieldBase
64 using ValueType = std::tuple<TMembers...>;
65 using Members = ValueType;
66 using VersionType =
typename TFieldBase::VersionType;
67 using CommsTag = comms::field::tag::Bundle;
70 explicit Bundle(
const ValueType& val)
75 explicit Bundle(ValueType&& val)
76 : members_(
std::move(val))
80 Bundle(
const Bundle&) =
default;
81 Bundle(Bundle&&) =
default;
82 ~Bundle() noexcept = default;
84 Bundle& operator=(const Bundle&) = default;
85 Bundle& operator=(Bundle&&) = default;
87 const ValueType& value()
const
97 const ValueType& getValue()
const
102 template <
typename T>
103 void setValue(T&& val)
105 value() = std::forward<T>(val);
108 constexpr std::size_t length()
const
111 value(), std::size_t(0), comms::field::details::FieldLengthSumCalcHelper<>());
114 template <std::
size_t TFromIdx>
115 constexpr std::size_t lengthFrom()
const
118 comms::util::tupleAccumulateFromUntil<TFromIdx, std::tuple_size<ValueType>::value>(
121 comms::field::details::FieldLengthSumCalcHelper<>());
124 template <std::
size_t TUntilIdx>
125 constexpr std::size_t lengthUntil()
const
128 comms::util::tupleAccumulateFromUntil<0, TUntilIdx>(
131 comms::field::details::FieldLengthSumCalcHelper<>());
134 template <std::
size_t TFromIdx, std::
size_t TUntilIdx>
135 constexpr std::size_t lengthFromUntil()
const
138 comms::util::tupleAccumulateFromUntil<TFromIdx, TUntilIdx>(
141 comms::field::details::FieldLengthSumCalcHelper<>());
144 static constexpr std::size_t minLength()
147 comms::util::tupleTypeAccumulate<Members>(
148 std::size_t(0), comms::field::details::FieldMinLengthSumCalcHelper<>());
151 template <std::
size_t TFromIdx>
152 static constexpr std::size_t minLengthFrom()
155 comms::util::tupleTypeAccumulateFromUntil<TFromIdx, std::tuple_size<ValueType>::value, Members>(
156 std::size_t(0), comms::field::details::FieldMinLengthSumCalcHelper<>());
159 template <std::
size_t TUntilIdx>
160 static constexpr std::size_t minLengthUntil()
163 comms::util::tupleTypeAccumulateFromUntil<0, TUntilIdx, Members>(
164 std::size_t(0), comms::field::details::FieldMinLengthSumCalcHelper<>());
167 template <std::
size_t TFromIdx, std::
size_t TUntilIdx>
168 static constexpr std::size_t minLengthFromUntil()
171 comms::util::tupleTypeAccumulateFromUntil<TFromIdx, TUntilIdx, Members>(
172 std::size_t(0), comms::field::details::FieldMinLengthSumCalcHelper<>());
175 static constexpr std::size_t maxLength()
178 comms::util::tupleTypeAccumulate<Members>(
179 std::size_t(0), comms::field::details::FieldMaxLengthSumCalcHelper<>());
182 template <std::
size_t TFromIdx>
183 static constexpr std::size_t maxLengthFrom()
186 comms::util::tupleTypeAccumulateFromUntil<TFromIdx, std::tuple_size<ValueType>::value, Members>(
187 std::size_t(0), comms::field::details::FieldMaxLengthSumCalcHelper<>());
190 template <std::
size_t TUntilIdx>
191 static constexpr std::size_t maxLengthUntil()
194 comms::util::tupleTypeAccumulateFromUntil<0, TUntilIdx, Members>(
195 std::size_t(0), comms::field::details::FieldMaxLengthSumCalcHelper<>());
198 template <std::
size_t TFromIdx, std::
size_t TUntilIdx>
199 static constexpr std::size_t maxLengthFromUntil()
202 comms::util::tupleTypeAccumulateFromUntil<TFromIdx, TUntilIdx, Members>(
203 std::size_t(0), comms::field::details::FieldMaxLengthSumCalcHelper<>());
206 constexpr bool valid()
const
216 template <
typename TIter>
224 template <std::
size_t TFromIdx,
typename TIter>
227 return readFromAndUpdateLen<TFromIdx>(iter, len);
230 template <std::
size_t TFromIdx,
typename TIter>
231 ErrorStatus readFromAndUpdateLen(TIter& iter, std::size_t& len)
234 comms::util::template tupleForEachFrom<TFromIdx>(value(), makeReadHelper(es, iter, len));
238 template <std::
size_t TUntilIdx,
typename TIter>
239 ErrorStatus readUntil(TIter& iter, std::size_t len)
241 return readUntilAndUpdateLen<TUntilIdx>(iter, len);
244 template <std::
size_t TUntilIdx,
typename TIter>
245 ErrorStatus readUntilAndUpdateLen(TIter& iter, std::size_t& len)
248 comms::util::template tupleForEachUntil<TUntilIdx>(value(), makeReadHelper(es, iter, len));
252 template <std::
size_t TFromIdx, std::
size_t TUntilIdx,
typename TIter>
253 ErrorStatus readFromUntil(TIter& iter, std::size_t len)
255 return readFromUntilAndUpdateLen<TFromIdx, TUntilIdx>(iter, len);
258 template <std::
size_t TFromIdx, std::
size_t TUntilIdx,
typename TIter>
259 ErrorStatus readFromUntilAndUpdateLen(TIter& iter, std::size_t& len)
262 comms::util::template tupleForEachFromUntil<TFromIdx, TUntilIdx>(value(), makeReadHelper(es, iter, len));
266 static constexpr bool hasReadNoStatus()
268 return CommonFuncs::AllFieldsHaveReadNoStatusBoolType<TMembers...>::value;
271 template <
typename TIter>
272 void readNoStatus(TIter& iter)
277 template <std::
size_t TFromIdx,
typename TIter>
278 void readFromNoStatus(TIter& iter)
280 comms::util::template tupleForEachFrom<TFromIdx>(value(), makeReadNoStatusHelper(iter));
283 template <std::
size_t TUntilIdx,
typename TIter>
284 void readUntilNoStatus(TIter& iter)
286 comms::util::template tupleForEachUntil<TUntilIdx>(value(), makeReadNoStatusHelper(iter));
289 template <std::
size_t TFromIdx, std::
size_t TUntilIdx,
typename TIter>
290 void readFromUntilNoStatus(TIter& iter)
292 comms::util::template tupleForEachFromUntil<TFromIdx, TUntilIdx>(value(), makeReadNoStatusHelper(iter));
295 bool canWrite()
const
299 value(),
true, comms::field::details::FieldCanWriteCheckHelper<>());
302 template <
typename TIter>
303 ErrorStatus write(TIter& iter, std::size_t len)
const
310 template <std::
size_t TFromIdx,
typename TIter>
311 ErrorStatus writeFrom(TIter& iter, std::size_t len)
const
314 comms::util::template tupleForEachFrom<TFromIdx>(value(), makeWriteHelper(es, iter, len));
318 template <std::
size_t TUntilIdx,
typename TIter>
319 ErrorStatus writeUntil(TIter& iter, std::size_t len)
const
322 comms::util::template tupleForEachUntil<TUntilIdx>(value(), makeWriteHelper(es, iter, len));
326 template <std::
size_t TFromIdx, std::
size_t TUntilIdx,
typename TIter>
327 ErrorStatus writeFromUntil(TIter& iter, std::size_t len)
const
330 comms::util::template tupleForEachFromUntil<TFromIdx, TUntilIdx>(value(), makeWriteHelper(es, iter, len));
334 static constexpr bool hasWriteNoStatus()
336 return CommonFuncs::AllFieldsHaveWriteNoStatusBoolType<TMembers...>::value;
339 template <
typename TIter>
340 void writeNoStatus(TIter& iter)
const
345 template <std::
size_t TFromIdx,
typename TIter>
346 void writeFromNoStatus(TIter& iter)
const
348 comms::util::template tupleForEachFrom<TFromIdx>(value(), makeWriteNoStatusHelper(iter));
351 template <std::
size_t TUntilIdx,
typename TIter>
352 void writeUntilNoStatus(TIter& iter)
const
354 comms::util::template tupleForEachUntil<TUntilIdx>(value(), makeWriteNoStatusHelper(iter));
357 template <std::
size_t TFromIdx, std::
size_t TUntilIdx,
typename TIter>
358 void writeFromUntilNoStatus(TIter& iter)
const
360 comms::util::template tupleForEachFromUntil<TFromIdx, TUntilIdx>(value(), makeWriteNoStatusHelper(iter));
363 static constexpr bool isVersionDependent()
365 return details::BundleVersionDependencyDetectHelper<TVersionDependency, TMembers...>::Value;
368 static constexpr bool hasNonDefaultRefresh()
370 return CommonFuncs::AnyFieldHasNonDefaultRefreshBoolType<TMembers...>::value;
373 bool setVersion(VersionType
version)
375 return CommonFuncs::setVersionForMembers(value(),
version);
379 template <
typename TIter>
380 static comms::field::details::FieldReadHelper<TIter> makeReadHelper(
comms::ErrorStatus& es, TIter& iter, std::size_t& len)
382 return comms::field::details::FieldReadHelper<TIter>(es, iter, len);
385 template <
typename TIter>
386 static comms::field::details::FieldReadNoStatusHelper<TIter> makeReadNoStatusHelper(TIter& iter)
388 return comms::field::details::FieldReadNoStatusHelper<TIter>(iter);
391 template <
typename TIter>
392 static comms::field::details::FieldWriteHelper<TIter> makeWriteHelper(
ErrorStatus& es, TIter& iter, std::size_t len)
394 return comms::field::details::FieldWriteHelper<TIter>(es, iter, len);
397 template <
typename TIter>
398 static comms::field::details::FieldWriteNoStatusHelper<TIter> makeWriteNoStatusHelper(TIter& iter)
400 return comms::field::details::FieldWriteNoStatusHelper<TIter>(iter);
This file contains classes required for generic custom assertion functionality.
This file contain definition of error statuses used by comms module.
Contains various tuple type manipulation classes and functions.
Contains definition of various tag classes.
comms::option::def::VersionType< T > VersionType
Same as comms::option::def::VersionType.
Definition options.h:1797
void tupleForEach(TTuple &&tuple, TFunc &&func)
Invoke provided functor for every element in the tuple.
Definition Tuple.h:239
constexpr TValue tupleAccumulate(TTuple &&tuple, const TValue &value, TFunc &&func)
Performs "accumulate" algorithm on every element of the tuple.
Definition Tuple.h:586
Main namespace for all classes / functions of COMMS library.
ErrorStatus
Error statuses reported by the Communication module.
Definition ErrorStatus.h:17
@ Success
Used to indicate successful outcome of the operation.
constexpr unsigned version()
Version of the COMMS library as single numeric value.
Definition version.h:64
Check whether provided type is a variant of std::tuple.
Definition Tuple.h:36