16#include "comms/util/SizeToType.h"
17#include "details/AdaptBasicField.h"
18#include "details/OptionsParser.h"
19#include "comms/details/gen_enum.h"
20#include "comms/details/bits_access.h"
33template <
bool THasFixedLength>
34struct BitmaskUndertlyingType;
37struct BitmaskUndertlyingType<true>
39 template <
typename TOptionsBundle>
40 using Type =
typename comms::util::SizeToType<TOptionsBundle::FixedLength, false>::Type;
44struct BitmaskUndertlyingType<false>
46 template <
typename TOptionsBundle>
47 using Type = unsigned;
50template <
typename TOptionsBundle>
51using BitmaskUndertlyingTypeT =
52 typename BitmaskUndertlyingType<TOptionsBundle::HasFixedLengthLimit>::template Type<TOptionsBundle>;
103template <
typename TFieldBase,
typename... TOptions>
106 using BaseImpl = TFieldBase;
108 using OptionsBundle = details::OptionsParser<TOptions...>;
110 using IntValueType = details::BitmaskUndertlyingTypeT<OptionsBundle>;
124 using Endian =
typename BaseImpl::Endian;
169 return ParsedOptions::HasFailOnInvalid;
176 return ParsedOptions::HasIgnoreInvalid;
183 return ParsedOptions::HasEmptySerialization;
190 return ParsedOptions::HasFieldType;
197 return ParsedOptions::HasFixedValue;
204 return ParsedOptions::HasName;
211 return intValue_.
value();
218 return intValue_.
value();
228 template <
typename U>
231 intValue_.
setValue(std::forward<U>(val));
238 return intValue_.
length();
260 template <
typename TIter>
263 return intValue_.
read(iter, size);
270 return BaseImpl::hasReadNoStatus();
278 template <
typename TIter>
287 return BaseImpl::canWrite();
295 template <
typename TIter>
298 return intValue_.
write(iter, size);
305 return BaseImpl::hasWriteNoStatus();
313 template <
typename TIter>
322 return intValue_.
valid();
337 return (
value() & mask) == mask;
345 return (
value() & mask) != 0;
392 return BaseImpl::hasNonDefaultRefresh();
429 using BaseImpl::readData;
430 using BaseImpl::writeData;
434 static_assert(!ParsedOptions::HasSerOffset,
435 "comms::option::def::NumValueSerOffset option is not applicable to BitmaskValue field");
436 static_assert(!ParsedOptions::HasVarLengthLimits,
437 "comms::option::def::VarLength option is not applicable to BitmaskValue field");
438 static_assert(!ParsedOptions::HasSequenceElemLengthForcing,
439 "comms::option::def::SequenceElemLengthForcingEnabled option is not applicable to BitmaskValue field");
440 static_assert(!ParsedOptions::HasSequenceSizeForcing,
441 "comms::option::def::SequenceSizeForcingEnabled option is not applicable to BitmaskValue field");
442 static_assert(!ParsedOptions::HasSequenceLengthForcing,
443 "comms::option::def::SequenceLengthForcingEnabled option is not applicable to BitmaskValue field");
444 static_assert(!ParsedOptions::HasSequenceFixedSize,
445 "comms::option::def::SequenceFixedSize option is not applicable to BitmaskValue field");
446 static_assert(!ParsedOptions::HasSequenceFixedSizeUseFixedSizeStorage,
447 "comms::option::app::SequenceFixedSizeUseFixedSizeStorage option is not applicable to BitmaskValue field");
448 static_assert(!ParsedOptions::HasSequenceSizeFieldPrefix,
449 "comms::option::def::SequenceSizeFieldPrefix option is not applicable to BitmaskValue field");
450 static_assert(!ParsedOptions::HasSequenceSerLengthFieldPrefix,
451 "comms::option::def::SequenceSerLengthFieldPrefix option is not applicable to BitmaskValue field");
452 static_assert(!ParsedOptions::HasSequenceElemSerLengthFieldPrefix,
453 "comms::option::def::SequenceElemSerLengthFieldPrefix option is not applicable to BitmaskValue field");
454 static_assert(!ParsedOptions::HasSequenceElemFixedSerLengthFieldPrefix,
455 "comms::option::def::SequenceElemSerLengthFixedFieldPrefix option is not applicable to BitmaskValue field");
456 static_assert(!ParsedOptions::HasSequenceTrailingFieldSuffix,
457 "comms::option::def::SequenceTrailingFieldSuffix option is not applicable to BitmaskValue field");
458 static_assert(!ParsedOptions::HasSequenceTerminationFieldSuffix,
459 "comms::option::def::SequenceTerminationFieldSuffix option is not applicable to BitmaskValue field");
460 static_assert(!ParsedOptions::HasFixedSizeStorage,
461 "comms::option::app::FixedSizeStorage option is not applicable to BitmaskValue field");
462 static_assert(!ParsedOptions::HasCustomStorageType,
463 "comms::option::app::CustomStorageType option is not applicable to BitmaskValue field");
464 static_assert(!ParsedOptions::HasScalingRatio,
465 "comms::option::def::ScalingRatio option is not applicable to BitmaskValue field");
466 static_assert(!ParsedOptions::HasUnits,
467 "comms::option::def::Units option is not applicable to BitmaskValue field");
468 static_assert(!ParsedOptions::HasOrigDataView,
469 "comms::option::app::OrigDataView option is not applicable to BitmaskValue field");
470 static_assert(!ParsedOptions::HasMultiRangeValidation,
471 "comms::option::def::ValidNumValueRange (or similar) option is not applicable to BitmaskValue field");
472 static_assert(!ParsedOptions::HasVersionsRange,
473 "comms::option::def::ExistsBetweenVersions (or similar) option is not applicable to BitmaskValue field");
474 static_assert(!ParsedOptions::HasInvalidByDefault,
475 "comms::option::def::InvalidByDefault option is not applicable to BitmaskValue field");
476 static_assert(!ParsedOptions::HasMissingOnReadFail,
477 "comms::option::def::MissingOnReadFail option is not applicable to BitmaskValue field");
478 static_assert(!ParsedOptions::HasMissingOnInvalid,
479 "comms::option::def::MissingOnInvalid option is not applicable to BitmaskValue field");
480 IntValueField intValue_;
490template <
typename TFieldBase,
typename... TOptions>
495 return field1.value() == field2.value();
503template <
typename TFieldBase,
typename... TOptions>
508 return field1.value() != field2.value();
516template <
typename TFieldBase,
typename... TOptions>
521 return field1.value() < field2.value();
532 return std::is_same<typename T::CommsTag, tag::Bitmask>::value;
538template <
typename TFieldBase,
typename... TOptions>
549template <
typename TFieldBase,
typename... TOptions>
606#define COMMS_BITMASK_BITS(...) COMMS_DEFINE_ENUM(BitIdx, __VA_ARGS__)
700#define COMMS_BITMASK_BITS_ACCESS(...) \
701 COMMS_AS_BITMASK_FUNC { \
702 return comms::field::toFieldBase(*this); \
704 COMMS_AS_BITMASK_CONST_FUNC { \
705 return comms::field::toFieldBase(*this); \
707 COMMS_DO_BIT_ACC_FUNC(asBitmask(), __VA_ARGS__)
719#define COMMS_BITMASK_BITS_ACCESS_NOTEMPLATE(...) \
720 COMMS_DO_BIT_ACC_FUNC((*this), __VA_ARGS__)
792#define COMMS_BITMASK_BITS_SEQ(...) \
793 COMMS_BITMASK_BITS(__VA_ARGS__) \
794 COMMS_BITMASK_BITS_ACCESS(__VA_ARGS__)
807#define COMMS_BITMASK_BITS_SEQ_NOTEMPLATE(...) \
808 COMMS_BITMASK_BITS(__VA_ARGS__) \
809 COMMS_BITMASK_BITS_ACCESS_NOTEMPLATE(__VA_ARGS__)
Contains definition of comms::Field class.
Contains definition of comms::field::IntValue.
Bitmask value field.
Definition BitmaskValue.h:105
const ValueType & value() const
Get access to underlying mask value storage.
Definition BitmaskValue.h:209
void setForcedLength(int len)
Force serialization length of the field.
Definition BitmaskValue.h:416
void clearBits(ValueType mask)
Set all the provided bits.
Definition BitmaskValue.h:359
int getForcedLength() const
Get forced serialization length.
Definition BitmaskValue.h:423
void setValue(U &&val)
Set value.
Definition BitmaskValue.h:229
VersionType getVersion() const
Get version of the field.
Definition BitmaskValue.h:397
ErrorStatus read(TIter &iter, std::size_t size)
Read field value from input data sequence.
Definition BitmaskValue.h:261
static constexpr bool hasFixedValue()
Compile time inquiry of whether comms::option::def::FixedValue option has been used.
Definition BitmaskValue.h:195
bool operator<(const BitmaskValue< TFieldBase, TOptions... > &field1, const BitmaskValue< TFieldBase, TOptions... > &field2) noexcept
Equivalence comparison operator.
Definition BitmaskValue.h:517
typename IntValueField::ValueType ValueType
Type of underlying integral value.
Definition BitmaskValue.h:138
bool getBitValue(unsigned bitNum) const
Get bit value.
Definition BitmaskValue.h:365
static constexpr bool hasWriteNoStatus()
Compile time check of whether the field has proper writeNoStatus() member function.
Definition BitmaskValue.h:303
static constexpr bool isVersionDependent()
Compile time check if this class is version dependent.
Definition BitmaskValue.h:384
static constexpr bool hasReadNoStatus()
Compile time check of whether the field has proper readNoStatus() member function.
Definition BitmaskValue.h:268
constexpr bool valid() const
Check validity of the field value.
Definition BitmaskValue.h:320
typename BaseImpl::VersionType VersionType
Version type.
Definition BitmaskValue.h:127
bool setVersion(VersionType version)
Default implementation of version update.
Definition BitmaskValue.h:404
void readNoStatus(TIter &iter)
Read field value from input data sequence without error check and status report.
Definition BitmaskValue.h:279
static constexpr bool hasEmptySerialization()
Compile time inquiry of whether comms::option::def::EmptySerialization option has been used.
Definition BitmaskValue.h:181
static constexpr std::size_t minLength()
Get minimal length that is required to serialise field of this type.
Definition BitmaskValue.h:250
static constexpr bool hasName()
Compile time inquiry of whether comms::option::def::HasName option has been used.
Definition BitmaskValue.h:202
constexpr bool isBitmaskValue()
Compile time check function of whether a provided type is any variant of comms::field::BitmaskValue.
Definition BitmaskValue.h:530
static constexpr bool hasFieldType()
Compile time inquiry of whether comms::option::def::FieldType option has been used.
Definition BitmaskValue.h:188
void setBitValue(unsigned bitNum, bool val)
Set bit value.
Definition BitmaskValue.h:372
ValueType & value()
Get access to underlying mask value storage.
Definition BitmaskValue.h:216
bool canWrite() const
Check of whether the field has a consistent value for writing.
Definition BitmaskValue.h:285
static constexpr bool hasIgnoreInvalid()
Compile time inquiry of whether comms::option::def::IgnoreInvalid option has been used.
Definition BitmaskValue.h:174
tag::Bitmask CommsTag
Tag indicating type of the field.
Definition BitmaskValue.h:133
const BitmaskValue< TFieldBase, TOptions... > & toFieldBase(const BitmaskValue< TFieldBase, TOptions... > &field)
Upcast type of the field definition to its parent comms::field::BitmaskValue type in order to have ac...
Definition BitmaskValue.h:552
~BitmaskValue() noexcept=default
Destructor.
bool hasAnyBitsSet(ValueType mask) const
Check whether any bits from provided mask are set.
Definition BitmaskValue.h:343
bool refresh()
Refresh contents of the field.
Definition BitmaskValue.h:327
typename ParsedOptions::FieldType FieldType
Type of actual extending field specified via comms::option::def::FieldType.
Definition BitmaskValue.h:143
OptionsBundle ParsedOptions
All the options provided to this class bundled into struct.
Definition BitmaskValue.h:130
BitmaskValue(const ValueType &val)
Constructor.
Definition BitmaskValue.h:151
ErrorStatus write(TIter &iter, std::size_t size) const
Write current field value to output data sequence.
Definition BitmaskValue.h:296
constexpr std::size_t length() const
Get length required to serialise the current field value.
Definition BitmaskValue.h:236
BitmaskValue(const BitmaskValue &)=default
Copy constructor.
TFieldBase FieldBase
Base class provided in the first template parameter.
Definition BitmaskValue.h:121
bool operator!=(const BitmaskValue< TFieldBase, TOptions... > &field1, const BitmaskValue< TFieldBase, TOptions... > &field2) noexcept
Non-equality comparison operator.
Definition BitmaskValue.h:504
const ValueType & getValue() const
Get value.
Definition BitmaskValue.h:222
static constexpr std::size_t maxLength()
Get maximal length that is required to serialise field of this type.
Definition BitmaskValue.h:243
void setBits(ValueType mask)
Set all the provided bits.
Definition BitmaskValue.h:351
static constexpr bool hasFailOnInvalid()
Compile time inquiry of whether comms::option::def::FailOnInvalid option has been used.
Definition BitmaskValue.h:167
BitmaskValue()=default
Default constructor.
static constexpr bool hasNonDefaultRefresh()
Compile time check if this class has non-default refresh functionality.
Definition BitmaskValue.h:390
BitmaskValue< TFieldBase, TOptions... > & toFieldBase(BitmaskValue< TFieldBase, TOptions... > &field)
Upcast type of the field definition to its parent comms::field::BitmaskValue type in order to have ac...
Definition BitmaskValue.h:541
void writeNoStatus(TIter &iter) const
Write current field value to output data sequence without error check and status report.
Definition BitmaskValue.h:314
bool operator==(const BitmaskValue< TFieldBase, TOptions... > &field1, const BitmaskValue< TFieldBase, TOptions... > &field2) noexcept
Equality comparison operator.
Definition BitmaskValue.h:491
bool hasAllBitsSet(ValueType mask) const
Check whether all bits from provided mask are set.
Definition BitmaskValue.h:335
typename BaseImpl::Endian Endian
Endian used for serialisation.
Definition BitmaskValue.h:124
typename BaseImpl::ValueType ValueType
Type of underlying integral value.
Definition IntValue.h:96
bool setVersion(VersionType version)
Default implementation of version update.
Definition IntValue.h:425
bool valid() const
Check validity of the field value.
Definition IntValue.h:328
int getForcedLength() const
Get forced serialization length.
Definition IntValue.h:444
VersionType getVersion() const
Get version of the field.
Definition IntValue.h:418
constexpr std::size_t length() const
Get length required to serialise the current field value.
Definition IntValue.h:308
static constexpr std::size_t maxLength()
Get maximal length that is required to serialise field of this type.
Definition IntValue.h:322
void readNoStatus(TIter &iter)
Read field value from input data sequence without error check and status report.
Definition IntValue.h:364
static constexpr std::size_t minLength()
Get minimal length that is required to serialise field of this type.
Definition IntValue.h:315
ErrorStatus read(TIter &iter, std::size_t size)
Read field value from input data sequence.
Definition IntValue.h:346
void setForcedLength(int len)
Force serialization length of the field.
Definition IntValue.h:437
void setValue(U &&val)
Set value.
Definition IntValue.h:272
ErrorStatus write(TIter &iter, std::size_t size) const
Write current field value to output data sequence.
Definition IntValue.h:381
const ValueType & value() const
Get access to integral value storage.
Definition IntValue.h:251
void writeNoStatus(TIter &iter) const
Write current field value to output data sequence without error check and status report.
Definition IntValue.h:399
static constexpr bool isVersionDependent()
Compile time check if this class is version dependent.
Definition IntValue.h:405
bool refresh()
Refresh the field's value.
Definition IntValue.h:335
const ValueType & getValue() const
Get value.
Definition IntValue.h:264
Contains definition of various tag classes.
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