17#if COMMS_HAS_CPP20_SPAN
26#include "basic/ArrayList.h"
27#include "details/AdaptBasicField.h"
28#include "details/OptionsParser.h"
39template <
bool THasOrigDataViewStorage>
40struct ArrayListOrigDataViewStorageType;
43struct ArrayListOrigDataViewStorageType<true>
45#if COMMS_HAS_CPP20_SPAN
46 template <
typename TElement>
47 using Type = std::span<TElement>;
49 template <
typename TElement>
55struct ArrayListOrigDataViewStorageType<false>
57 template <
typename TElement>
58 using Type = std::vector<TElement>;
61template <
bool THasSequenceFixedSizeUseFixedSizeStorage>
62struct ArrayListSequenceFixedSizeUseFixedSizeStorageType;
65struct ArrayListSequenceFixedSizeUseFixedSizeStorageType<true>
67 template <
typename TElement,
typename TOpt>
72struct ArrayListSequenceFixedSizeUseFixedSizeStorageType<false>
74 template <
typename TElement,
typename TOpt>
76 typename ArrayListOrigDataViewStorageType<
77 TOpt::HasOrigDataView && std::is_integral<TElement>::value && (
sizeof(TElement) ==
sizeof(std::uint8_t))
78 >::template Type<TElement>;
81template <
bool THasFixedSizeStorage>
82struct ArrayListFixedSizeStorageType;
85struct ArrayListFixedSizeStorageType<true>
87 template <
typename TElement,
typename TOpt>
92struct ArrayListFixedSizeStorageType<false>
94 template <
typename TElement,
typename TOpt>
96 typename ArrayListSequenceFixedSizeUseFixedSizeStorageType<TOpt::HasSequenceFixedSizeUseFixedSizeStorage>
97 ::template Type<TElement, TOpt>;
100template <
bool THasCustomStorage>
101struct ArrayListCustomArrayListStorageType;
104struct ArrayListCustomArrayListStorageType<true>
106 template <
typename TElement,
typename TOpt>
107 using Type =
typename TOpt::CustomStorageType;
111struct ArrayListCustomArrayListStorageType<false>
113 template <
typename TElement,
typename TOpt>
115 typename ArrayListFixedSizeStorageType<TOpt::HasFixedSizeStorage>::template Type<TElement, TOpt>;
118template <
typename TElement,
typename TOpt>
119using ArrayListStorageTypeT =
120 typename ArrayListCustomArrayListStorageType<TOpt::HasCustomStorageType>::template Type<TElement, TOpt>;
122template <
typename TFieldBase,
typename TElement,
typename... TOptions>
125 comms::field::basic::ArrayList<
127 ArrayListStorageTypeT<TElement, OptionsParser<TOptions...> >
190template <
typename TFieldBase,
typename TElement,
typename... TOptions>
191class ArrayList :
public details::ArrayListBase<TFieldBase, TElement, TOptions...>
193 using BaseImpl = details::ArrayListBase<TFieldBase, TElement, TOptions...>;
199 using Endian =
typename BaseImpl::Endian;
260 : BaseImpl(
std::move(val))
283 return ParsedOptions::HasFailOnInvalid;
290 return ParsedOptions::HasIgnoreInvalid;
297 return ParsedOptions::HasEmptySerialization;
304 return ParsedOptions::HasFieldType;
311 return ParsedOptions::HasSequenceSizeFieldPrefix;
318 return ParsedOptions::HasSequenceSerLengthFieldPrefix;
325 return ParsedOptions::HasSequenceElemSerLengthFieldPrefix;
332 return ParsedOptions::HasSequenceElemFixedSerLengthFieldPrefix;
339 return ParsedOptions::HasSequenceTerminationFieldSuffix;
346 return ParsedOptions::HasSequenceTrailingFieldSuffix;
353 return ParsedOptions::HasSequenceFixedSize;
361 return ParsedOptions::SequenceFixedSize;
367 return BaseImpl::value();
373 return BaseImpl::value();
380 return BaseImpl::getValue();
385 template <
typename U>
388 BaseImpl::setValue(std::forward<U>(val));
394 return BaseImpl::length();
407 template <
typename TIter>
410 return BaseImpl::read(iter, len);
417 return BaseImpl::hasReadNoStatus();
425 template <
typename TIter>
428 BaseImpl::readNoStatus(iter);
434 return BaseImpl::canWrite();
449 template <
typename TIter>
452 return BaseImpl::write(iter, len);
459 return BaseImpl::hasWriteNoStatus();
467 template <
typename TIter>
470 BaseImpl::writeNoStatus(iter);
478 return BaseImpl::valid();
486 return BaseImpl::refresh();
492 return BaseImpl::minLength();
498 return BaseImpl::maxLength();
508 return BaseImpl::forceReadElemCount(count);
517 return BaseImpl::clearReadElemCount();
526 return BaseImpl::forceReadLength(count);
535 return BaseImpl::clearReadLengthForcing();
546 return BaseImpl::forceReadElemLength(count);
554 return BaseImpl::clearReadElemLengthForcing();
560 return ParsedOptions::HasCustomVersionUpdate || BaseImpl::isVersionDependent();
566 return BaseImpl::hasNonDefaultRefresh();
573 return BaseImpl::getVersion();
580 return BaseImpl::setVersion(
version);
583#ifdef FOR_DOXYGEN_DOC_ONLY
591 return BaseImpl::terminationFieldSuffix();
601 return BaseImpl::terminationFieldSuffix();
607 using BaseImpl::readData;
608 using BaseImpl::writeData;
611 static_assert(!ParsedOptions::HasSerOffset,
612 "comms::option::def::NumValueSerOffset option is not applicable to ArrayList field");
613 static_assert(!ParsedOptions::HasFixedLengthLimit,
614 "comms::option::def::FixedLength option is not applicable to ArrayList field");
615 static_assert(!ParsedOptions::HasFixedBitLengthLimit,
616 "comms::option::def::FixedBitLength option is not applicable to ArrayList field");
617 static_assert(!ParsedOptions::HasVarLengthLimits,
618 "comms::option::def::VarLength option is not applicable to ArrayList field");
619 static_assert(!ParsedOptions::HasAvailableLengthLimit,
620 "comms::option::def::AvailableLengthLimit option is not applicable to ArrayList field");
621 static_assert(!ParsedOptions::HasScalingRatio,
622 "comms::option::def::ScalingRatio option is not applicable to ArrayList field");
623 static_assert(!ParsedOptions::HasUnits,
624 "comms::option::def::Units option is not applicable to ArrayList field");
625 static_assert(!ParsedOptions::HasMultiRangeValidation,
626 "comms::option::def::ValidNumValueRange (or similar) option is not applicable to ArrayList field");
627 static_assert((!ParsedOptions::HasOrigDataView) || (std::is_integral<TElement>::value && (
sizeof(TElement) ==
sizeof(std::uint8_t))),
628 "Usage of comms::option::app::OrigDataView option is allowed only for raw binary data (std::uint8_t) types.");
629 static_assert(!ParsedOptions::HasVersionsRange,
630 "comms::option::def::ExistsBetweenVersions (or similar) option is not applicable to ArrayList field");
631 static_assert(!ParsedOptions::HasInvalidByDefault,
632 "comms::option::def::InvalidByDefault option is not applicable to ArrayList field");
633 static_assert(!ParsedOptions::HasMissingOnReadFail,
634 "comms::option::def::MissingOnReadFail option is not applicable to ArrayList field");
635 static_assert(!ParsedOptions::HasMissingOnInvalid,
636 "comms::option::def::MissingOnInvalid option is not applicable to ArrayList field");
645template <
typename TFieldBase,
typename TElement,
typename... TOptions>
650 return std::lexicographical_compare(
651 field1.value().begin(), field1.value().end(),
652 field2.value().begin(), field2.value().end());
660template <
typename TFieldBase,
typename TElement,
typename... TOptions>
665 auto& vec1 = field1.value();
666 auto& vec2 = field2.value();
667 if (vec1.size() != vec2.size()) {
671 for (
auto idx = 0U; idx < vec1.size(); ++idx) {
672 if (vec1[idx] != vec2[idx]) {
684template <
typename TFieldBase,
typename TElement,
typename... TOptions>
689 return !(field1 == field2);
701 std::is_same<typename T::CommsTag, tag::ArrayList>::value ||
702 std::is_same<typename T::CommsTag, tag::RawArrayList>::value;
708template <
typename TFieldBase,
typename TElement,
typename... TOptions>
710ArrayList<TFieldBase, TElement, TOptions...>&
719template <
typename TFieldBase,
typename TElement,
typename... TOptions>
721const ArrayList<TFieldBase, TElement, TOptions...>&
Contains comms::util::ArrayView class.
Contains various compiler related definitions.
This file contain definition of error statuses used by comms module.
Contains comms::util::StaticVector class.
Field that represents a sequential collection of fields.
Definition ArrayList.h:192
static constexpr bool hasEmptySerialization()
Compile time inquiry of whether comms::option::def::EmptySerialization option has been used.
Definition ArrayList.h:295
const ValueType & value() const
Get access to the value storage.
Definition ArrayList.h:371
static constexpr bool hasFixedSize()
Compile time inquiry of whether comms::option::def::SequenceFixedSize option has been used.
Definition ArrayList.h:351
typename BaseImpl::ElementType ElementType
Type of the element.
Definition ArrayList.h:218
typename BaseImpl::VersionType VersionType
Version type.
Definition ArrayList.h:202
static constexpr bool hasTrailingFieldSuffix()
Compile time inquiry of whether comms::option::def::SequenceTrailingFieldSuffix option has been used.
Definition ArrayList.h:344
void clearReadElemLengthForcing()
Clear forcing the serialisation length of the single element.
Definition ArrayList.h:552
static constexpr bool hasElemSerLengthFieldPrefix()
Compile time inquiry of whether comms::option::def::SequenceElemSerLengthFieldPrefix option has been ...
Definition ArrayList.h:323
void writeNoStatus(TIter &iter) const
Write current field value to output data sequence without error check and status report.
Definition ArrayList.h:468
typename ParsedOptions::SequenceTrailingFieldSuffix TrailingFieldSuffix
Type of trailing field suffix specified via comms::option::def::SequenceTrailingFieldSuffix.
Definition ArrayList.h:247
static constexpr bool hasFailOnInvalid()
Compile time inquiry of whether comms::option::def::FailOnInvalid option has been used.
Definition ArrayList.h:281
ErrorStatus read(TIter &iter, std::size_t len)
Read field value from input data sequence.
Definition ArrayList.h:408
static constexpr bool hasReadNoStatus()
Compile time check of whether the field has proper readNoStatus() member function.
Definition ArrayList.h:415
static constexpr bool isVersionDependent()
Compile time check if this class is version dependent.
Definition ArrayList.h:558
VersionType getVersion() const
Get version of the field.
Definition ArrayList.h:571
const ArrayList< TFieldBase, TElement, TOptions... > & toFieldBase(const ArrayList< TFieldBase, TElement, TOptions... > &field)
Upcast type of the field definition to its parent comms::field::ArrayList type in order to have acces...
Definition ArrayList.h:722
typename BaseImpl::Endian Endian
Endian used for serialisation.
Definition ArrayList.h:199
void clearReadLengthForcing()
Clear forcing of the available length in the next read() invocation.
Definition ArrayList.h:533
static constexpr bool hasTerminationFieldSuffix()
Compile time inquiry of whether comms::option::def::SequenceTerminationFieldSuffix option has been us...
Definition ArrayList.h:337
void setValue(U &&val)
Set value.
Definition ArrayList.h:386
ValueType & value()
Get access to the value storage.
Definition ArrayList.h:365
bool operator<(const ArrayList< TFieldBase, TElement, TOptions... > &field1, const ArrayList< TFieldBase, TElement, TOptions... > &field2) noexcept
Equivalence comparison operator.
Definition ArrayList.h:646
ArrayList(const ValueType &val)
Value constructor.
Definition ArrayList.h:253
void readNoStatus(TIter &iter)
Read field value from input data sequence without error check and status report.
Definition ArrayList.h:426
typename ParsedOptions::SequenceSizeFieldPrefix SizeFieldPrefix
Type of size field prefix specified via comms::option::def::SequenceSizeFieldPrefix.
Definition ArrayList.h:227
void forceReadElemCount(std::size_t count)
Force number of elements that must be read in the next read() invocation.
Definition ArrayList.h:506
typename ParsedOptions::SequenceElemSerLengthFieldPrefix ElemSerLengthFieldPrefix
Type of element's length field prefix specified via comms::option::def::SequenceElemSerLengthFieldPre...
Definition ArrayList.h:235
ArrayList(const ArrayList &)=default
Copy constructor.
constexpr std::size_t length() const
Get length of serialised data.
Definition ArrayList.h:392
void forceReadElemLength(std::size_t count)
Force serialisation length of a single element.
Definition ArrayList.h:544
static constexpr std::size_t minLength()
Get minimal length that is required to serialise field of this type.
Definition ArrayList.h:490
ArrayList< TFieldBase, TElement, TOptions... > & toFieldBase(ArrayList< TFieldBase, TElement, TOptions... > &field)
Upcast type of the field definition to its parent comms::field::ArrayList type in order to have acces...
Definition ArrayList.h:711
~ArrayList() noexcept=default
Destructor.
bool refresh()
Refresh the field.
Definition ArrayList.h:484
static constexpr std::size_t fixedSize()
Compile time inquiry of fixed size provided via comms::option::def::SequenceFixedSize option.
Definition ArrayList.h:359
typename BaseImpl::ValueType ValueType
Type of underlying value.
Definition ArrayList.h:215
constexpr bool isArrayList()
Compile time check function of whether a provided type is any variant of comms::field::ArrayList.
Definition ArrayList.h:698
bool setVersion(VersionType version)
Default implementation of version update.
Definition ArrayList.h:578
static constexpr bool hasSerLengthFieldPrefix()
Compile time inquiry of whether comms::option::def::SequenceSerLengthFieldPrefix option has been used...
Definition ArrayList.h:316
auto terminationFieldSuffix() const -> decltype(BaseImpl::terminationFieldSuffix())
Access list termination field (const variant)
Definition ArrayList.h:599
typename ParsedOptions::FieldType FieldType
Type of actual extending field specified via comms::option::def::FieldType.
Definition ArrayList.h:223
const ValueType & getValue() const
Get value.
Definition ArrayList.h:378
static constexpr bool hasElemFixedSerLengthFieldPrefix()
Compile time inquiry of whether comms::option::def::SequenceElemFixedSerLengthFieldPrefix option has ...
Definition ArrayList.h:330
static constexpr bool hasWriteNoStatus()
Compile time check of whether the field has proper writeNoStatus() member function.
Definition ArrayList.h:457
bool valid() const
Check validity of the field value.
Definition ArrayList.h:476
static constexpr bool hasIgnoreInvalid()
Compile time inquiry of whether comms::option::def::IgnoreInvalid option has been used.
Definition ArrayList.h:288
typename ParsedOptions::SequenceSerLengthFieldPrefix SerLengthFieldPrefix
Type of length field prefix specified via comms::option::def::SequenceSerLengthFieldPrefix.
Definition ArrayList.h:231
typename ParsedOptions::SequenceElemFixedSerLengthFieldPrefix ElemFixedSerLengthFieldPrefix
Type of element's fixed length field prefix specified via comms::option::def::SequenceElemFixedSerLen...
Definition ArrayList.h:239
TFieldBase FieldBase
Base class provided in the first template parameter.
Definition ArrayList.h:196
ErrorStatus write(TIter &iter, std::size_t len) const
Write current field value to output data sequence.
Definition ArrayList.h:450
auto terminationFieldSuffix() -> decltype(BaseImpl::terminationFieldSuffix())
Access list termination field.
Definition ArrayList.h:589
static constexpr bool hasFieldType()
Compile time inquiry of whether comms::option::def::FieldType option has been used.
Definition ArrayList.h:302
ArrayList(ArrayList &&)=default
Move constructor.
bool canWrite() const
Check of whether the field has a consistent value for writing.
Definition ArrayList.h:432
void clearReadElemCount()
Clear forcing of the number of elements that must be read in the next read() invocation.
Definition ArrayList.h:515
void forceReadLength(std::size_t count)
Force available length for the next read() invocation.
Definition ArrayList.h:524
static constexpr bool hasNonDefaultRefresh()
Compile time check if this class has non-default refresh functionality.
Definition ArrayList.h:564
static constexpr std::size_t maxLength()
Get maximal length that is required to serialise field of this type.
Definition ArrayList.h:496
bool operator!=(const ArrayList< TFieldBase, TElement, TOptions... > &field1, const ArrayList< TFieldBase, TElement, TOptions... > &field2) noexcept
Non-equality comparison operator.
Definition ArrayList.h:685
details::OptionsParser< TOptions... > ParsedOptions
All the options provided to this class bundled into struct.
Definition ArrayList.h:205
typename BaseImpl::CommsTag CommsTag
Tag indicating type of the field.
Definition ArrayList.h:208
typename ParsedOptions::SequenceTerminationFieldSuffix TerminationFieldSuffix
Type of termination field suffix specified via comms::option::def::SequenceTerminationFieldSuffix.
Definition ArrayList.h:243
ArrayList()=default
Default constructor.
bool operator==(const ArrayList< TFieldBase, TElement, TOptions... > &field1, const ArrayList< TFieldBase, TElement, TOptions... > &field2) noexcept
Equality comparison operator.
Definition ArrayList.h:661
ArrayList(ValueType &&val)
Value constructor.
Definition ArrayList.h:259
static constexpr bool hasSizeFieldPrefix()
Compile time inquiry of whether comms::option::def::SequenceSizeFieldPrefix option has been used.
Definition ArrayList.h:309
Describes an object that can refer to a constant contiguous sequence of other objects.
Definition ArrayView.h:31
Replacement to std::vector when no dynamic memory allocation is allowed.
Definition StaticVector.h:960
Main namespace for all classes / functions of COMMS library.
ErrorStatus
Error statuses reported by the Communication module.
Definition ErrorStatus.h:17
constexpr unsigned version()
Version of the COMMS library as single numeric value.
Definition version.h:64
Contains definition of all the options used by the COMMS library.
Replacement to some types from standard type_traits.