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"
37template <
bool THasFixedLength>
38struct BitmaskUndertlyingType;
41struct BitmaskUndertlyingType<true>
43 template <
typename TOptionsBundle>
44 using Type =
typename comms::util::SizeToType<TOptionsBundle::FixedLength, false>::Type;
48struct BitmaskUndertlyingType<false>
50 template <
typename TOptionsBundle>
51 using Type = unsigned;
54template <
typename TOptionsBundle>
55using BitmaskUndertlyingTypeT =
56 typename BitmaskUndertlyingType<TOptionsBundle::HasFixedLengthLimit>::template Type<TOptionsBundle>;
106template <
typename TFieldBase,
typename... TOptions>
109 using BaseImpl = TFieldBase;
111 using OptionsBundle = details::OptionsParser<TOptions...>;
113 using IntValueType = details::BitmaskUndertlyingTypeT<OptionsBundle>;
127 using Endian =
typename BaseImpl::Endian;
172 return ParsedOptions::HasFailOnInvalid;
179 return ParsedOptions::HasIgnoreInvalid;
186 return ParsedOptions::HasEmptySerialization;
193 return ParsedOptions::HasFieldType;
200 return ParsedOptions::HasFixedValue;
207 return ParsedOptions::HasName;
214 return m_intValue.
value();
221 return m_intValue.
value();
231 template <
typename U>
234 m_intValue.
setValue(std::forward<U>(val));
241 return m_intValue.
length();
263 template <
typename TIter>
266 return m_intValue.
read(iter, size);
273 return BaseImpl::hasReadNoStatus();
281 template <
typename TIter>
290 return BaseImpl::canWrite();
298 template <
typename TIter>
301 return m_intValue.
write(iter, size);
308 return BaseImpl::hasWriteNoStatus();
316 template <
typename TIter>
325 return m_intValue.
valid();
340 return (
value() & mask) == mask;
348 return (
value() & mask) != 0;
395 return BaseImpl::hasNonDefaultRefresh();
432 using BaseImpl::readData;
433 using BaseImpl::writeData;
437 static_assert(!ParsedOptions::HasSerOffset,
438 "comms::option::def::NumValueSerOffset option is not applicable to BitmaskValue field");
439 static_assert(!ParsedOptions::HasVarLengthLimits,
440 "comms::option::def::VarLength option is not applicable to BitmaskValue field");
441 static_assert(!ParsedOptions::HasSequenceElemLengthForcing,
442 "comms::option::def::SequenceElemLengthForcingEnabled option is not applicable to BitmaskValue field");
443 static_assert(!ParsedOptions::HasSequenceSizeForcing,
444 "comms::option::def::SequenceSizeForcingEnabled option is not applicable to BitmaskValue field");
445 static_assert(!ParsedOptions::HasSequenceLengthForcing,
446 "comms::option::def::SequenceLengthForcingEnabled option is not applicable to BitmaskValue field");
447 static_assert(!ParsedOptions::HasSequenceFixedSize,
448 "comms::option::def::SequenceFixedSize option is not applicable to BitmaskValue field");
449 static_assert(!ParsedOptions::HasSequenceFixedSizeUseFixedSizeStorage,
450 "comms::option::app::SequenceFixedSizeUseFixedSizeStorage option is not applicable to BitmaskValue field");
451 static_assert(!ParsedOptions::HasSequenceSizeFieldPrefix,
452 "comms::option::def::SequenceSizeFieldPrefix option is not applicable to BitmaskValue field");
453 static_assert(!ParsedOptions::HasSequenceSerLengthFieldPrefix,
454 "comms::option::def::SequenceSerLengthFieldPrefix option is not applicable to BitmaskValue field");
455 static_assert(!ParsedOptions::HasSequenceElemSerLengthFieldPrefix,
456 "comms::option::def::SequenceElemSerLengthFieldPrefix option is not applicable to BitmaskValue field");
457 static_assert(!ParsedOptions::HasSequenceElemFixedSerLengthFieldPrefix,
458 "comms::option::def::SequenceElemSerLengthFixedFieldPrefix option is not applicable to BitmaskValue field");
459 static_assert(!ParsedOptions::HasSequenceTrailingFieldSuffix,
460 "comms::option::def::SequenceTrailingFieldSuffix option is not applicable to BitmaskValue field");
461 static_assert(!ParsedOptions::HasSequenceTerminationFieldSuffix,
462 "comms::option::def::SequenceTerminationFieldSuffix option is not applicable to BitmaskValue field");
463 static_assert(!ParsedOptions::HasFixedSizeStorage,
464 "comms::option::app::FixedSizeStorage option is not applicable to BitmaskValue field");
465 static_assert(!ParsedOptions::HasCustomStorageType,
466 "comms::option::app::CustomStorageType option is not applicable to BitmaskValue field");
467 static_assert(!ParsedOptions::HasScalingRatio,
468 "comms::option::def::ScalingRatio option is not applicable to BitmaskValue field");
469 static_assert(!ParsedOptions::HasUnits,
470 "comms::option::def::Units option is not applicable to BitmaskValue field");
471 static_assert(!ParsedOptions::HasOrigDataView,
472 "comms::option::app::OrigDataView option is not applicable to BitmaskValue field");
473 static_assert(!ParsedOptions::HasMultiRangeValidation,
474 "comms::option::def::ValidNumValueRange (or similar) option is not applicable to BitmaskValue field");
475 static_assert(!ParsedOptions::HasVersionsRange,
476 "comms::option::def::ExistsBetweenVersions (or similar) option is not applicable to BitmaskValue field");
477 static_assert(!ParsedOptions::HasInvalidByDefault,
478 "comms::option::def::InvalidByDefault option is not applicable to BitmaskValue field");
479 static_assert(!ParsedOptions::HasMissingOnReadFail,
480 "comms::option::def::MissingOnReadFail option is not applicable to BitmaskValue field");
481 static_assert(!ParsedOptions::HasMissingOnInvalid,
482 "comms::option::def::MissingOnInvalid option is not applicable to BitmaskValue field");
483 IntValueField m_intValue;
493template <
typename TFieldBase,
typename... TOptions>
498 return field1.value() == field2.value();
506template <
typename TFieldBase,
typename... TOptions>
511 return field1.value() != field2.value();
519template <
typename TFieldBase,
typename... TOptions>
524 return field1.value() < field2.value();
535 return std::is_same<typename T::CommsTag, tag::Bitmask>::value;
541template <
typename TFieldBase,
typename... TOptions>
552template <
typename TFieldBase,
typename... TOptions>
608#define COMMS_BITMASK_BITS(...) COMMS_DEFINE_ENUM(BitIdx, __VA_ARGS__)
702#define COMMS_BITMASK_BITS_ACCESS(...) \
703 COMMS_AS_BITMASK_FUNC { \
704 return comms::field::toFieldBase(*this); \
706 COMMS_AS_BITMASK_CONST_FUNC { \
707 return comms::field::toFieldBase(*this); \
709 COMMS_DO_BIT_ACC_FUNC(asBitmask(), __VA_ARGS__)
721#define COMMS_BITMASK_BITS_ACCESS_NOTEMPLATE(...) \
722 COMMS_DO_BIT_ACC_FUNC((*this), __VA_ARGS__)
793#define COMMS_BITMASK_BITS_SEQ(...) \
794 COMMS_BITMASK_BITS(__VA_ARGS__) \
795 COMMS_BITMASK_BITS_ACCESS(__VA_ARGS__)
808#define COMMS_BITMASK_BITS_SEQ_NOTEMPLATE(...) \
809 COMMS_BITMASK_BITS(__VA_ARGS__) \
810 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:108
const ValueType & value() const
Get access to underlying mask value storage.
Definition BitmaskValue.h:212
void setForcedLength(int len)
Force serialization length of the field.
Definition BitmaskValue.h:419
void clearBits(ValueType mask)
Set all the provided bits.
Definition BitmaskValue.h:362
int getForcedLength() const
Get forced serialization length.
Definition BitmaskValue.h:426
void setValue(U &&val)
Set value.
Definition BitmaskValue.h:232
VersionType getVersion() const
Get version of the field.
Definition BitmaskValue.h:400
ErrorStatus read(TIter &iter, std::size_t size)
Read field value from input data sequence.
Definition BitmaskValue.h:264
static constexpr bool hasFixedValue()
Compile time inquiry of whether comms::option::def::FixedValue option has been used.
Definition BitmaskValue.h:198
bool operator<(const BitmaskValue< TFieldBase, TOptions... > &field1, const BitmaskValue< TFieldBase, TOptions... > &field2) noexcept
Equivalence comparison operator.
Definition BitmaskValue.h:520
typename IntValueField::ValueType ValueType
Type of underlying integral value.
Definition BitmaskValue.h:141
bool getBitValue(unsigned bitNum) const
Get bit value.
Definition BitmaskValue.h:368
static constexpr bool hasWriteNoStatus()
Compile time check of whether the field has proper writeNoStatus() member function.
Definition BitmaskValue.h:306
static constexpr bool isVersionDependent()
Compile time check if this class is version dependent.
Definition BitmaskValue.h:387
static constexpr bool hasReadNoStatus()
Compile time check of whether the field has proper readNoStatus() member function.
Definition BitmaskValue.h:271
constexpr bool valid() const
Check validity of the field value.
Definition BitmaskValue.h:323
typename BaseImpl::VersionType VersionType
Version type.
Definition BitmaskValue.h:130
bool setVersion(VersionType version)
Default implementation of version update.
Definition BitmaskValue.h:407
void readNoStatus(TIter &iter)
Read field value from input data sequence without error check and status report.
Definition BitmaskValue.h:282
static constexpr bool hasEmptySerialization()
Compile time inquiry of whether comms::option::def::EmptySerialization option has been used.
Definition BitmaskValue.h:184
static constexpr std::size_t minLength()
Get minimal length that is required to serialise field of this type.
Definition BitmaskValue.h:253
static constexpr bool hasName()
Compile time inquiry of whether comms::option::def::HasName option has been used.
Definition BitmaskValue.h:205
constexpr bool isBitmaskValue()
Compile time check function of whether a provided type is any variant of comms::field::BitmaskValue.
Definition BitmaskValue.h:533
static constexpr bool hasFieldType()
Compile time inquiry of whether comms::option::def::FieldType option has been used.
Definition BitmaskValue.h:191
void setBitValue(unsigned bitNum, bool val)
Set bit value.
Definition BitmaskValue.h:375
ValueType & value()
Get access to underlying mask value storage.
Definition BitmaskValue.h:219
bool canWrite() const
Check of whether the field has a consistent value for writing.
Definition BitmaskValue.h:288
static constexpr bool hasIgnoreInvalid()
Compile time inquiry of whether comms::option::def::IgnoreInvalid option has been used.
Definition BitmaskValue.h:177
tag::Bitmask CommsTag
Tag indicating type of the field.
Definition BitmaskValue.h:136
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:555
~BitmaskValue() noexcept=default
Destructor.
bool hasAnyBitsSet(ValueType mask) const
Check whether any bits from provided mask are set.
Definition BitmaskValue.h:346
bool refresh()
Refresh contents of the field.
Definition BitmaskValue.h:330
typename ParsedOptions::FieldType FieldType
Type of actual extending field specified via comms::option::def::FieldType.
Definition BitmaskValue.h:146
OptionsBundle ParsedOptions
All the options provided to this class bundled into struct.
Definition BitmaskValue.h:133
BitmaskValue(const ValueType &val)
Constructor.
Definition BitmaskValue.h:154
ErrorStatus write(TIter &iter, std::size_t size) const
Write current field value to output data sequence.
Definition BitmaskValue.h:299
constexpr std::size_t length() const
Get length required to serialise the current field value.
Definition BitmaskValue.h:239
BitmaskValue(const BitmaskValue &)=default
Copy constructor.
TFieldBase FieldBase
Base class provided in the first template parameter.
Definition BitmaskValue.h:124
bool operator!=(const BitmaskValue< TFieldBase, TOptions... > &field1, const BitmaskValue< TFieldBase, TOptions... > &field2) noexcept
Non-equality comparison operator.
Definition BitmaskValue.h:507
const ValueType & getValue() const
Get value.
Definition BitmaskValue.h:225
static constexpr std::size_t maxLength()
Get maximal length that is required to serialise field of this type.
Definition BitmaskValue.h:246
void setBits(ValueType mask)
Set all the provided bits.
Definition BitmaskValue.h:354
static constexpr bool hasFailOnInvalid()
Compile time inquiry of whether comms::option::def::FailOnInvalid option has been used.
Definition BitmaskValue.h:170
BitmaskValue()=default
Default constructor.
static constexpr bool hasNonDefaultRefresh()
Compile time check if this class has non-default refresh functionality.
Definition BitmaskValue.h:393
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:544
void writeNoStatus(TIter &iter) const
Write current field value to output data sequence without error check and status report.
Definition BitmaskValue.h:317
bool operator==(const BitmaskValue< TFieldBase, TOptions... > &field1, const BitmaskValue< TFieldBase, TOptions... > &field2) noexcept
Equality comparison operator.
Definition BitmaskValue.h:494
bool hasAllBitsSet(ValueType mask) const
Check whether all bits from provided mask are set.
Definition BitmaskValue.h:338
typename BaseImpl::Endian Endian
Endian used for serialisation.
Definition BitmaskValue.h:127
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