15#include "comms/details/bits_access.h"
16#include "comms/details/gen_enum.h"
18#include "comms/field/details/AdaptBasicField.h"
19#include "comms/field/details/OptionsParser.h"
22#include "comms/util/SizeToType.h"
38template <
bool THasFixedLength>
39struct BitmaskUndertlyingType;
42struct BitmaskUndertlyingType<true>
44 template <
typename TOptionsBundle>
45 using Type =
typename comms::util::SizeToType<TOptionsBundle::FixedLength, false>::Type;
49struct BitmaskUndertlyingType<false>
51 template <
typename TOptionsBundle>
52 using Type = std::uintmax_t;
55template <
typename TOptionsBundle>
56using BitmaskUndertlyingTypeT =
57 typename BitmaskUndertlyingType<TOptionsBundle::HasFixedLengthLimit>::template Type<TOptionsBundle>;
107template <
typename TFieldBase,
typename... TOptions>
110 using BaseImpl = TFieldBase;
112 using OptionsBundle = details::OptionsParser<TOptions...>;
114 using IntValueType = details::BitmaskUndertlyingTypeT<OptionsBundle>;
128 using Endian =
typename BaseImpl::Endian;
173 return ParsedOptions::HasFailOnInvalid;
180 return ParsedOptions::HasIgnoreInvalid;
187 return ParsedOptions::HasEmptySerialization;
194 return ParsedOptions::HasFieldType;
201 return ParsedOptions::HasFixedValue;
208 return ParsedOptions::HasName;
215 return m_intValue.
value();
222 return m_intValue.
value();
232 template <
typename U>
235 m_intValue.
setValue(std::forward<U>(val));
242 return m_intValue.
length();
264 template <
typename TIter>
267 return m_intValue.
read(iter, size);
274 return BaseImpl::hasReadNoStatus();
282 template <
typename TIter>
291 return BaseImpl::canWrite();
299 template <
typename TIter>
302 return m_intValue.
write(iter, size);
309 return BaseImpl::hasWriteNoStatus();
317 template <
typename TIter>
326 return m_intValue.
valid();
341 return (
value() & mask) == mask;
349 return (
value() & mask) != 0;
396 return BaseImpl::hasNonDefaultRefresh();
433 using BaseImpl::readData;
434 using BaseImpl::writeData;
438 static_assert(!ParsedOptions::HasSerOffset,
439 "comms::option::def::NumValueSerOffset option is not applicable to BitmaskValue field");
440 static_assert(!ParsedOptions::HasVarLengthLimits,
441 "comms::option::def::VarLength option is not applicable to BitmaskValue field");
442 static_assert(!ParsedOptions::HasSequenceElemLengthForcing,
443 "comms::option::def::SequenceElemLengthForcingEnabled option is not applicable to BitmaskValue field");
444 static_assert(!ParsedOptions::HasSequenceSizeForcing,
445 "comms::option::def::SequenceSizeForcingEnabled option is not applicable to BitmaskValue field");
446 static_assert(!ParsedOptions::HasSequenceLengthForcing,
447 "comms::option::def::SequenceLengthForcingEnabled option is not applicable to BitmaskValue field");
448 static_assert(!ParsedOptions::HasSequenceFixedSize,
449 "comms::option::def::SequenceFixedSize option is not applicable to BitmaskValue field");
450 static_assert(!ParsedOptions::HasSequenceFixedSizeUseFixedSizeStorage,
451 "comms::option::app::SequenceFixedSizeUseFixedSizeStorage option is not applicable to BitmaskValue field");
452 static_assert(!ParsedOptions::HasSequenceSizeFieldPrefix,
453 "comms::option::def::SequenceSizeFieldPrefix option is not applicable to BitmaskValue field");
454 static_assert(!ParsedOptions::HasSequenceSerLengthFieldPrefix,
455 "comms::option::def::SequenceSerLengthFieldPrefix option is not applicable to BitmaskValue field");
456 static_assert(!ParsedOptions::HasSequenceElemSerLengthFieldPrefix,
457 "comms::option::def::SequenceElemSerLengthFieldPrefix option is not applicable to BitmaskValue field");
458 static_assert(!ParsedOptions::HasSequenceElemFixedSerLengthFieldPrefix,
459 "comms::option::def::SequenceElemSerLengthFixedFieldPrefix option is not applicable to BitmaskValue field");
460 static_assert(!ParsedOptions::HasSequenceTrailingFieldSuffix,
461 "comms::option::def::SequenceTrailingFieldSuffix option is not applicable to BitmaskValue field");
462 static_assert(!ParsedOptions::HasSequenceTerminationFieldSuffix,
463 "comms::option::def::SequenceTerminationFieldSuffix option is not applicable to BitmaskValue field");
464 static_assert(!ParsedOptions::HasFixedSizeStorage,
465 "comms::option::app::FixedSizeStorage option is not applicable to BitmaskValue field");
466 static_assert(!ParsedOptions::HasCustomStorageType,
467 "comms::option::app::CustomStorageType option is not applicable to BitmaskValue field");
468 static_assert(!ParsedOptions::HasScalingRatio,
469 "comms::option::def::ScalingRatio option is not applicable to BitmaskValue field");
470 static_assert(!ParsedOptions::HasUnits,
471 "comms::option::def::Units option is not applicable to BitmaskValue field");
472 static_assert(!ParsedOptions::HasOrigDataView,
473 "comms::option::app::OrigDataView option is not applicable to BitmaskValue field");
474 static_assert(!ParsedOptions::HasMultiRangeValidation,
475 "comms::option::def::ValidNumValueRange (or similar) option is not applicable to BitmaskValue field");
476 static_assert(!ParsedOptions::HasVersionsRange,
477 "comms::option::def::ExistsBetweenVersions (or similar) option is not applicable to BitmaskValue field");
478 static_assert(!ParsedOptions::HasInvalidByDefault,
479 "comms::option::def::InvalidByDefault option is not applicable to BitmaskValue field");
480 static_assert(!ParsedOptions::HasMissingOnReadFail,
481 "comms::option::def::MissingOnReadFail option is not applicable to BitmaskValue field");
482 static_assert(!ParsedOptions::HasMissingOnInvalid,
483 "comms::option::def::MissingOnInvalid option is not applicable to BitmaskValue field");
484 IntValueField m_intValue;
494template <
typename TFieldBase,
typename... TOptions>
499 return field1.value() == field2.value();
507template <
typename TFieldBase,
typename... TOptions>
512 return field1.value() != field2.value();
520template <
typename TFieldBase,
typename... TOptions>
525 return field1.value() < field2.value();
536 return std::is_same<typename T::CommsTag, tag::Bitmask>::value;
542template <
typename TFieldBase,
typename... TOptions>
553template <
typename TFieldBase,
typename... TOptions>
609#define COMMS_BITMASK_BITS(...) COMMS_DEFINE_ENUM(BitIdx, __VA_ARGS__)
703#define COMMS_BITMASK_BITS_ACCESS(...) \
704 COMMS_AS_BITMASK_FUNC { \
705 return comms::field::toFieldBase(*this); \
707 COMMS_AS_BITMASK_CONST_FUNC { \
708 return comms::field::toFieldBase(*this); \
710 COMMS_DO_BIT_ACC_FUNC(asBitmask(), __VA_ARGS__)
722#define COMMS_BITMASK_BITS_ACCESS_NOTEMPLATE(...) \
723 COMMS_DO_BIT_ACC_FUNC((*this), __VA_ARGS__)
794#define COMMS_BITMASK_BITS_SEQ(...) \
795 COMMS_BITMASK_BITS(__VA_ARGS__) \
796 COMMS_BITMASK_BITS_ACCESS(__VA_ARGS__)
809#define COMMS_BITMASK_BITS_SEQ_NOTEMPLATE(...) \
810 COMMS_BITMASK_BITS(__VA_ARGS__) \
811 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:109
const ValueType & value() const
Get access to underlying mask value storage.
Definition BitmaskValue.h:213
void setForcedLength(int len)
Force serialization length of the field.
Definition BitmaskValue.h:420
void clearBits(ValueType mask)
Set all the provided bits.
Definition BitmaskValue.h:363
int getForcedLength() const
Get forced serialization length.
Definition BitmaskValue.h:427
void setValue(U &&val)
Set value.
Definition BitmaskValue.h:233
VersionType getVersion() const
Get version of the field.
Definition BitmaskValue.h:401
ErrorStatus read(TIter &iter, std::size_t size)
Read field value from input data sequence.
Definition BitmaskValue.h:265
static constexpr bool hasFixedValue()
Compile time inquiry of whether comms::option::def::FixedValue option has been used.
Definition BitmaskValue.h:199
bool operator<(const BitmaskValue< TFieldBase, TOptions... > &field1, const BitmaskValue< TFieldBase, TOptions... > &field2) noexcept
Equivalence comparison operator.
Definition BitmaskValue.h:521
typename IntValueField::ValueType ValueType
Type of underlying integral value.
Definition BitmaskValue.h:142
bool getBitValue(unsigned bitNum) const
Get bit value.
Definition BitmaskValue.h:369
static constexpr bool hasWriteNoStatus()
Compile time check of whether the field has proper writeNoStatus() member function.
Definition BitmaskValue.h:307
static constexpr bool isVersionDependent()
Compile time check if this class is version dependent.
Definition BitmaskValue.h:388
static constexpr bool hasReadNoStatus()
Compile time check of whether the field has proper readNoStatus() member function.
Definition BitmaskValue.h:272
constexpr bool valid() const
Check validity of the field value.
Definition BitmaskValue.h:324
typename BaseImpl::VersionType VersionType
Version type.
Definition BitmaskValue.h:131
bool setVersion(VersionType version)
Default implementation of version update.
Definition BitmaskValue.h:408
void readNoStatus(TIter &iter)
Read field value from input data sequence without error check and status report.
Definition BitmaskValue.h:283
static constexpr bool hasEmptySerialization()
Compile time inquiry of whether comms::option::def::EmptySerialization option has been used.
Definition BitmaskValue.h:185
static constexpr std::size_t minLength()
Get minimal length that is required to serialise field of this type.
Definition BitmaskValue.h:254
static constexpr bool hasName()
Compile time inquiry of whether comms::option::def::HasName option has been used.
Definition BitmaskValue.h:206
constexpr bool isBitmaskValue()
Compile time check function of whether a provided type is any variant of comms::field::BitmaskValue.
Definition BitmaskValue.h:534
static constexpr bool hasFieldType()
Compile time inquiry of whether comms::option::def::FieldType option has been used.
Definition BitmaskValue.h:192
void setBitValue(unsigned bitNum, bool val)
Set bit value.
Definition BitmaskValue.h:376
ValueType & value()
Get access to underlying mask value storage.
Definition BitmaskValue.h:220
bool canWrite() const
Check of whether the field has a consistent value for writing.
Definition BitmaskValue.h:289
static constexpr bool hasIgnoreInvalid()
Compile time inquiry of whether comms::option::def::IgnoreInvalid option has been used.
Definition BitmaskValue.h:178
tag::Bitmask CommsTag
Tag indicating type of the field.
Definition BitmaskValue.h:137
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:556
~BitmaskValue() noexcept=default
Destructor.
bool hasAnyBitsSet(ValueType mask) const
Check whether any bits from provided mask are set.
Definition BitmaskValue.h:347
bool refresh()
Refresh contents of the field.
Definition BitmaskValue.h:331
typename ParsedOptions::FieldType FieldType
Type of actual extending field specified via comms::option::def::FieldType.
Definition BitmaskValue.h:147
OptionsBundle ParsedOptions
All the options provided to this class bundled into struct.
Definition BitmaskValue.h:134
BitmaskValue(const ValueType &val)
Constructor.
Definition BitmaskValue.h:155
ErrorStatus write(TIter &iter, std::size_t size) const
Write current field value to output data sequence.
Definition BitmaskValue.h:300
constexpr std::size_t length() const
Get length required to serialise the current field value.
Definition BitmaskValue.h:240
BitmaskValue(const BitmaskValue &)=default
Copy constructor.
TFieldBase FieldBase
Base class provided in the first template parameter.
Definition BitmaskValue.h:125
bool operator!=(const BitmaskValue< TFieldBase, TOptions... > &field1, const BitmaskValue< TFieldBase, TOptions... > &field2) noexcept
Non-equality comparison operator.
Definition BitmaskValue.h:508
const ValueType & getValue() const
Get value.
Definition BitmaskValue.h:226
static constexpr std::size_t maxLength()
Get maximal length that is required to serialise field of this type.
Definition BitmaskValue.h:247
void setBits(ValueType mask)
Set all the provided bits.
Definition BitmaskValue.h:355
static constexpr bool hasFailOnInvalid()
Compile time inquiry of whether comms::option::def::FailOnInvalid option has been used.
Definition BitmaskValue.h:171
BitmaskValue()=default
Default constructor.
static constexpr bool hasNonDefaultRefresh()
Compile time check if this class has non-default refresh functionality.
Definition BitmaskValue.h:394
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:545
void writeNoStatus(TIter &iter) const
Write current field value to output data sequence without error check and status report.
Definition BitmaskValue.h:318
bool operator==(const BitmaskValue< TFieldBase, TOptions... > &field1, const BitmaskValue< TFieldBase, TOptions... > &field2) noexcept
Equality comparison operator.
Definition BitmaskValue.h:495
bool hasAllBitsSet(ValueType mask) const
Check whether all bits from provided mask are set.
Definition BitmaskValue.h:339
typename BaseImpl::Endian Endian
Endian used for serialisation.
Definition BitmaskValue.h:128
typename BaseImpl::ValueType ValueType
Type of underlying integral value.
Definition IntValue.h:100
bool setVersion(VersionType version)
Default implementation of version update.
Definition IntValue.h:429
bool valid() const
Check validity of the field value.
Definition IntValue.h:332
int getForcedLength() const
Get forced serialization length.
Definition IntValue.h:448
VersionType getVersion() const
Get version of the field.
Definition IntValue.h:422
constexpr std::size_t length() const
Get length required to serialise the current field value.
Definition IntValue.h:312
static constexpr std::size_t maxLength()
Get maximal length that is required to serialise field of this type.
Definition IntValue.h:326
void readNoStatus(TIter &iter)
Read field value from input data sequence without error check and status report.
Definition IntValue.h:368
static constexpr std::size_t minLength()
Get minimal length that is required to serialise field of this type.
Definition IntValue.h:319
ErrorStatus read(TIter &iter, std::size_t size)
Read field value from input data sequence.
Definition IntValue.h:350
void setForcedLength(int len)
Force serialization length of the field.
Definition IntValue.h:441
void setValue(U &&val)
Set value.
Definition IntValue.h:276
ErrorStatus write(TIter &iter, std::size_t size) const
Write current field value to output data sequence.
Definition IntValue.h:385
const ValueType & value() const
Get access to integral value storage.
Definition IntValue.h:255
void writeNoStatus(TIter &iter) const
Write current field value to output data sequence without error check and status report.
Definition IntValue.h:403
static constexpr bool isVersionDependent()
Compile time check if this class is version dependent.
Definition IntValue.h:409
bool refresh()
Refresh the field's value.
Definition IntValue.h:339
const ValueType & getValue() const
Get value.
Definition IntValue.h:268
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:19
constexpr unsigned version()
Version of the COMMS library as single numeric value.
Definition version.h:66