15#include "basic/ArrayList.h"
22#include "details/AdaptBasicField.h"
23#include "details/OptionsParser.h"
31#if COMMS_HAS_CPP20_SPAN
44template <
bool THasOrigDataViewStorage>
45struct ArrayListOrigDataViewStorageType;
48struct ArrayListOrigDataViewStorageType<true>
50#if COMMS_HAS_CPP20_SPAN
51 template <
typename TElement>
52 using Type = std::span<TElement>;
54 template <
typename TElement>
60struct ArrayListOrigDataViewStorageType<false>
62 template <
typename TElement>
63 using Type = std::vector<TElement>;
66template <
bool THasSequenceFixedSizeUseFixedSizeStorage>
67struct ArrayListSequenceFixedSizeUseFixedSizeStorageType;
70struct ArrayListSequenceFixedSizeUseFixedSizeStorageType<true>
72 template <
typename TElement,
typename TOpt>
77struct ArrayListSequenceFixedSizeUseFixedSizeStorageType<false>
79 template <
typename TElement,
typename TOpt>
81 typename ArrayListOrigDataViewStorageType<
82 TOpt::HasOrigDataView && std::is_integral<TElement>::value && (
sizeof(TElement) ==
sizeof(std::uint8_t))
83 >::template Type<TElement>;
86template <
bool THasFixedSizeStorage>
87struct ArrayListFixedSizeStorageType;
90struct ArrayListFixedSizeStorageType<true>
92 template <
typename TElement,
typename TOpt>
97struct ArrayListFixedSizeStorageType<false>
99 template <
typename TElement,
typename TOpt>
101 typename ArrayListSequenceFixedSizeUseFixedSizeStorageType<TOpt::HasSequenceFixedSizeUseFixedSizeStorage>
102 ::template Type<TElement, TOpt>;
105template <
bool THasCustomStorage>
106struct ArrayListCustomArrayListStorageType;
109struct ArrayListCustomArrayListStorageType<true>
111 template <
typename TElement,
typename TOpt>
112 using Type =
typename TOpt::CustomStorageType;
116struct ArrayListCustomArrayListStorageType<false>
118 template <
typename TElement,
typename TOpt>
120 typename ArrayListFixedSizeStorageType<TOpt::HasFixedSizeStorage>::template Type<TElement, TOpt>;
123template <
typename TElement,
typename TOpt>
124using ArrayListStorageTypeT =
125 typename ArrayListCustomArrayListStorageType<TOpt::HasCustomStorageType>::template Type<TElement, TOpt>;
127template <
typename TFieldBase,
typename TElement,
typename... TOptions>
130 comms::field::basic::ArrayList<
132 ArrayListStorageTypeT<TElement, OptionsParser<TOptions...> >
198template <
typename TFieldBase,
typename TElement,
typename... TOptions>
199class ArrayList :
public details::ArrayListBase<TFieldBase, TElement, TOptions...>
201 using BaseImpl = details::ArrayListBase<TFieldBase, TElement, TOptions...>;
207 using Endian =
typename BaseImpl::Endian;
268 : BaseImpl(
std::move(val))
291 return ParsedOptions::HasFailOnInvalid;
298 return ParsedOptions::HasIgnoreInvalid;
305 return ParsedOptions::HasEmptySerialization;
312 return ParsedOptions::HasFieldType;
319 return ParsedOptions::HasSequenceSizeFieldPrefix;
326 return ParsedOptions::HasSequenceSerLengthFieldPrefix;
333 return ParsedOptions::HasSequenceElemSerLengthFieldPrefix;
340 return ParsedOptions::HasSequenceElemFixedSerLengthFieldPrefix;
347 return ParsedOptions::HasSequenceTerminationFieldSuffix;
354 return ParsedOptions::HasSequenceTrailingFieldSuffix;
361 return ParsedOptions::HasSequenceFixedSize;
368 return ParsedOptions::HasFixedValue;
375 return ParsedOptions::HasName;
383 return ParsedOptions::SequenceFixedSize;
389 return BaseImpl::value();
395 return BaseImpl::value();
402 return BaseImpl::getValue();
407 template <
typename U>
410 BaseImpl::setValue(std::forward<U>(val));
416 return BaseImpl::length();
429 template <
typename TIter>
432 return BaseImpl::read(iter, len);
439 return BaseImpl::hasReadNoStatus();
447 template <
typename TIter>
450 BaseImpl::readNoStatus(iter);
456 return BaseImpl::canWrite();
471 template <
typename TIter>
474 return BaseImpl::write(iter, len);
481 return BaseImpl::hasWriteNoStatus();
489 template <
typename TIter>
492 BaseImpl::writeNoStatus(iter);
500 return BaseImpl::valid();
508 return BaseImpl::refresh();
514 return BaseImpl::minLength();
520 return BaseImpl::maxLength();
530 return BaseImpl::forceReadElemCount(count);
539 return BaseImpl::clearReadElemCount();
548 return BaseImpl::forceReadLength(count);
557 return BaseImpl::clearReadLengthForcing();
568 return BaseImpl::forceReadElemLength(count);
576 return BaseImpl::clearReadElemLengthForcing();
582 return ParsedOptions::HasCustomVersionUpdate || BaseImpl::isVersionDependent();
588 return BaseImpl::hasNonDefaultRefresh();
595 return BaseImpl::getVersion();
602 return BaseImpl::setVersion(
version);
605#ifdef FOR_DOXYGEN_DOC_ONLY
613 return BaseImpl::terminationFieldSuffix();
623 return BaseImpl::terminationFieldSuffix();
629 using BaseImpl::readData;
630 using BaseImpl::writeData;
633 static_assert(!ParsedOptions::HasSerOffset,
634 "comms::option::def::NumValueSerOffset option is not applicable to ArrayList field");
635 static_assert(!ParsedOptions::HasFixedLengthLimit,
636 "comms::option::def::FixedLength option is not applicable to ArrayList field");
637 static_assert(!ParsedOptions::HasFixedBitLengthLimit,
638 "comms::option::def::FixedBitLength option is not applicable to ArrayList field");
639 static_assert(!ParsedOptions::HasVarLengthLimits,
640 "comms::option::def::VarLength option is not applicable to ArrayList field");
641 static_assert(!ParsedOptions::HasAvailableLengthLimit,
642 "comms::option::def::AvailableLengthLimit option is not applicable to ArrayList field");
643 static_assert(!ParsedOptions::HasScalingRatio,
644 "comms::option::def::ScalingRatio option is not applicable to ArrayList field");
645 static_assert(!ParsedOptions::HasUnits,
646 "comms::option::def::Units option is not applicable to ArrayList field");
647 static_assert(!ParsedOptions::HasMultiRangeValidation,
648 "comms::option::def::ValidNumValueRange (or similar) option is not applicable to ArrayList field");
649 static_assert((!ParsedOptions::HasOrigDataView) || (std::is_integral<TElement>::value && (
sizeof(TElement) ==
sizeof(std::uint8_t))),
650 "Usage of comms::option::app::OrigDataView option is allowed only for raw binary data (std::uint8_t) types.");
651 static_assert(!ParsedOptions::HasVersionsRange,
652 "comms::option::def::ExistsBetweenVersions (or similar) option is not applicable to ArrayList field");
653 static_assert(!ParsedOptions::HasInvalidByDefault,
654 "comms::option::def::InvalidByDefault option is not applicable to ArrayList field");
655 static_assert(!ParsedOptions::HasMissingOnReadFail,
656 "comms::option::def::MissingOnReadFail option is not applicable to ArrayList field");
657 static_assert(!ParsedOptions::HasMissingOnInvalid,
658 "comms::option::def::MissingOnInvalid option is not applicable to ArrayList field");
667template <
typename TFieldBase,
typename TElement,
typename... TOptions>
672 return std::lexicographical_compare(
673 field1.value().begin(), field1.value().end(),
674 field2.value().begin(), field2.value().end());
682template <
typename TFieldBase,
typename TElement,
typename... TOptions>
687 auto& vec1 = field1.value();
688 auto& vec2 = field2.value();
689 if (vec1.size() != vec2.size()) {
693 for (
auto idx = 0U; idx < vec1.size(); ++idx) {
694 if (vec1[idx] != vec2[idx]) {
706template <
typename TFieldBase,
typename TElement,
typename... TOptions>
711 return !(field1 == field2);
723 std::is_same<typename T::CommsTag, tag::ArrayList>::value ||
724 std::is_same<typename T::CommsTag, tag::RawArrayList>::value;
730template <
typename TFieldBase,
typename TElement,
typename... TOptions>
732ArrayList<TFieldBase, TElement, TOptions...>&
741template <
typename TFieldBase,
typename TElement,
typename... TOptions>
743const 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:200
static constexpr bool hasEmptySerialization()
Compile time inquiry of whether comms::option::def::EmptySerialization option has been used.
Definition ArrayList.h:303
const ValueType & value() const
Get access to the value storage.
Definition ArrayList.h:393
static constexpr bool hasFixedSize()
Compile time inquiry of whether comms::option::def::SequenceFixedSize option has been used.
Definition ArrayList.h:359
typename BaseImpl::ElementType ElementType
Type of the element.
Definition ArrayList.h:226
typename BaseImpl::VersionType VersionType
Version type.
Definition ArrayList.h:210
static constexpr bool hasTrailingFieldSuffix()
Compile time inquiry of whether comms::option::def::SequenceTrailingFieldSuffix option has been used.
Definition ArrayList.h:352
void clearReadElemLengthForcing()
Clear forcing the serialisation length of the single element.
Definition ArrayList.h:574
static constexpr bool hasElemSerLengthFieldPrefix()
Compile time inquiry of whether comms::option::def::SequenceElemSerLengthFieldPrefix option has been ...
Definition ArrayList.h:331
void writeNoStatus(TIter &iter) const
Write current field value to output data sequence without error check and status report.
Definition ArrayList.h:490
typename ParsedOptions::SequenceTrailingFieldSuffix TrailingFieldSuffix
Type of trailing field suffix specified via comms::option::def::SequenceTrailingFieldSuffix.
Definition ArrayList.h:255
static constexpr bool hasFailOnInvalid()
Compile time inquiry of whether comms::option::def::FailOnInvalid option has been used.
Definition ArrayList.h:289
ErrorStatus read(TIter &iter, std::size_t len)
Read field value from input data sequence.
Definition ArrayList.h:430
static constexpr bool hasName()
Compile time inquiry of whether comms::option::def::HasName option has been used.
Definition ArrayList.h:373
static constexpr bool hasReadNoStatus()
Compile time check of whether the field has proper readNoStatus() member function.
Definition ArrayList.h:437
static constexpr bool isVersionDependent()
Compile time check if this class is version dependent.
Definition ArrayList.h:580
VersionType getVersion() const
Get version of the field.
Definition ArrayList.h:593
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:744
typename BaseImpl::Endian Endian
Endian used for serialisation.
Definition ArrayList.h:207
void clearReadLengthForcing()
Clear forcing of the available length in the next read() invocation.
Definition ArrayList.h:555
static constexpr bool hasTerminationFieldSuffix()
Compile time inquiry of whether comms::option::def::SequenceTerminationFieldSuffix option has been us...
Definition ArrayList.h:345
void setValue(U &&val)
Set value.
Definition ArrayList.h:408
static constexpr bool hasFixedValue()
Compile time inquiry of whether comms::option::def::FixedValue option has been used.
Definition ArrayList.h:366
ValueType & value()
Get access to the value storage.
Definition ArrayList.h:387
bool operator<(const ArrayList< TFieldBase, TElement, TOptions... > &field1, const ArrayList< TFieldBase, TElement, TOptions... > &field2) noexcept
Equivalence comparison operator.
Definition ArrayList.h:668
ArrayList(const ValueType &val)
Value constructor.
Definition ArrayList.h:261
void readNoStatus(TIter &iter)
Read field value from input data sequence without error check and status report.
Definition ArrayList.h:448
typename ParsedOptions::SequenceSizeFieldPrefix SizeFieldPrefix
Type of size field prefix specified via comms::option::def::SequenceSizeFieldPrefix.
Definition ArrayList.h:235
void forceReadElemCount(std::size_t count)
Force number of elements that must be read in the next read() invocation.
Definition ArrayList.h:528
typename ParsedOptions::SequenceElemSerLengthFieldPrefix ElemSerLengthFieldPrefix
Type of element's length field prefix specified via comms::option::def::SequenceElemSerLengthFieldPre...
Definition ArrayList.h:243
ArrayList(const ArrayList &)=default
Copy constructor.
constexpr std::size_t length() const
Get length of serialised data.
Definition ArrayList.h:414
void forceReadElemLength(std::size_t count)
Force serialisation length of a single element.
Definition ArrayList.h:566
static constexpr std::size_t minLength()
Get minimal length that is required to serialise field of this type.
Definition ArrayList.h:512
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:733
~ArrayList() noexcept=default
Destructor.
bool refresh()
Refresh the field.
Definition ArrayList.h:506
static constexpr std::size_t fixedSize()
Compile time inquiry of fixed size provided via comms::option::def::SequenceFixedSize option.
Definition ArrayList.h:381
typename BaseImpl::ValueType ValueType
Type of underlying value.
Definition ArrayList.h:223
constexpr bool isArrayList()
Compile time check function of whether a provided type is any variant of comms::field::ArrayList.
Definition ArrayList.h:720
bool setVersion(VersionType version)
Default implementation of version update.
Definition ArrayList.h:600
static constexpr bool hasSerLengthFieldPrefix()
Compile time inquiry of whether comms::option::def::SequenceSerLengthFieldPrefix option has been used...
Definition ArrayList.h:324
auto terminationFieldSuffix() const -> decltype(BaseImpl::terminationFieldSuffix())
Access list termination field (const variant)
Definition ArrayList.h:621
typename ParsedOptions::FieldType FieldType
Type of actual extending field specified via comms::option::def::FieldType.
Definition ArrayList.h:231
const ValueType & getValue() const
Get value.
Definition ArrayList.h:400
static constexpr bool hasElemFixedSerLengthFieldPrefix()
Compile time inquiry of whether comms::option::def::SequenceElemFixedSerLengthFieldPrefix option has ...
Definition ArrayList.h:338
static constexpr bool hasWriteNoStatus()
Compile time check of whether the field has proper writeNoStatus() member function.
Definition ArrayList.h:479
bool valid() const
Check validity of the field value.
Definition ArrayList.h:498
static constexpr bool hasIgnoreInvalid()
Compile time inquiry of whether comms::option::def::IgnoreInvalid option has been used.
Definition ArrayList.h:296
typename ParsedOptions::SequenceSerLengthFieldPrefix SerLengthFieldPrefix
Type of length field prefix specified via comms::option::def::SequenceSerLengthFieldPrefix.
Definition ArrayList.h:239
typename ParsedOptions::SequenceElemFixedSerLengthFieldPrefix ElemFixedSerLengthFieldPrefix
Type of element's fixed length field prefix specified via comms::option::def::SequenceElemFixedSerLen...
Definition ArrayList.h:247
TFieldBase FieldBase
Base class provided in the first template parameter.
Definition ArrayList.h:204
ErrorStatus write(TIter &iter, std::size_t len) const
Write current field value to output data sequence.
Definition ArrayList.h:472
auto terminationFieldSuffix() -> decltype(BaseImpl::terminationFieldSuffix())
Access list termination field.
Definition ArrayList.h:611
static constexpr bool hasFieldType()
Compile time inquiry of whether comms::option::def::FieldType option has been used.
Definition ArrayList.h:310
ArrayList(ArrayList &&)=default
Move constructor.
bool canWrite() const
Check of whether the field has a consistent value for writing.
Definition ArrayList.h:454
void clearReadElemCount()
Clear forcing of the number of elements that must be read in the next read() invocation.
Definition ArrayList.h:537
void forceReadLength(std::size_t count)
Force available length for the next read() invocation.
Definition ArrayList.h:546
static constexpr bool hasNonDefaultRefresh()
Compile time check if this class has non-default refresh functionality.
Definition ArrayList.h:586
static constexpr std::size_t maxLength()
Get maximal length that is required to serialise field of this type.
Definition ArrayList.h:518
bool operator!=(const ArrayList< TFieldBase, TElement, TOptions... > &field1, const ArrayList< TFieldBase, TElement, TOptions... > &field2) noexcept
Non-equality comparison operator.
Definition ArrayList.h:707
details::OptionsParser< TOptions... > ParsedOptions
All the options provided to this class bundled into struct.
Definition ArrayList.h:213
typename BaseImpl::CommsTag CommsTag
Tag indicating type of the field.
Definition ArrayList.h:216
typename ParsedOptions::SequenceTerminationFieldSuffix TerminationFieldSuffix
Type of termination field suffix specified via comms::option::def::SequenceTerminationFieldSuffix.
Definition ArrayList.h:251
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:683
ArrayList(ValueType &&val)
Value constructor.
Definition ArrayList.h:267
static constexpr bool hasSizeFieldPrefix()
Compile time inquiry of whether comms::option::def::SequenceSizeFieldPrefix option has been used.
Definition ArrayList.h:317
Describes an object that can refer to a constant contiguous sequence of other objects.
Definition ArrayView.h:32
Replacement to std::vector when no dynamic memory allocation is allowed.
Definition StaticVector.h:961
Main namespace for all classes / functions of COMMS library.
ErrorStatus
Error statuses reported by the Communication module.
Definition ErrorStatus.h:19
constexpr unsigned version()
Version of the COMMS library as single numeric value.
Definition version.h:66
Contains definition of all the options used by the COMMS library.
Replacement to some types from standard type_traits.