13#include "comms/details/bits_access.h"
14#include "comms/details/gen_enum.h"
16#include "comms/field/details/AdaptBasicField.h"
17#include "comms/field/details/OptionsParser.h"
20#include "comms/util/SizeToType.h"
34template <
bool THasFixedLength>
35struct BitmaskUndertlyingType;
38struct BitmaskUndertlyingType<true>
40 template <
typename TOptionsBundle>
41 using Type =
typename comms::util::SizeToType<TOptionsBundle::FixedLength, false>::Type;
45struct BitmaskUndertlyingType<false>
47 template <
typename TOptionsBundle>
48 using Type = unsigned;
51template <
typename TOptionsBundle>
52using BitmaskUndertlyingTypeT =
53 typename BitmaskUndertlyingType<TOptionsBundle::HasFixedLengthLimit>::template Type<TOptionsBundle>;
104template <
typename TFieldBase,
typename... TOptions>
107 using BaseImpl = TFieldBase;
109 using OptionsBundle = details::OptionsParser<TOptions...>;
111 using IntValueType = details::BitmaskUndertlyingTypeT<OptionsBundle>;
125 using Endian =
typename BaseImpl::Endian;
170 return ParsedOptions::HasFailOnInvalid;
177 return ParsedOptions::HasIgnoreInvalid;
184 return ParsedOptions::HasEmptySerialization;
191 return ParsedOptions::HasFieldType;
198 return ParsedOptions::HasFixedValue;
205 return ParsedOptions::HasName;
212 return m_intValue.
value();
219 return m_intValue.
value();
229 template <
typename U>
232 m_intValue.
setValue(std::forward<U>(val));
239 return m_intValue.
length();
261 template <
typename TIter>
264 return m_intValue.
read(iter, size);
271 return BaseImpl::hasReadNoStatus();
279 template <
typename TIter>
288 return BaseImpl::canWrite();
296 template <
typename TIter>
299 return m_intValue.
write(iter, size);
306 return BaseImpl::hasWriteNoStatus();
314 template <
typename TIter>
323 return m_intValue.
valid();
338 return (
value() & mask) == mask;
346 return (
value() & mask) != 0;
393 return BaseImpl::hasNonDefaultRefresh();
430 using BaseImpl::readData;
431 using BaseImpl::writeData;
435 static_assert(!ParsedOptions::HasSerOffset,
436 "comms::option::def::NumValueSerOffset option is not applicable to BitmaskValue field");
437 static_assert(!ParsedOptions::HasVarLengthLimits,
438 "comms::option::def::VarLength option is not applicable to BitmaskValue field");
439 static_assert(!ParsedOptions::HasSequenceElemLengthForcing,
440 "comms::option::def::SequenceElemLengthForcingEnabled option is not applicable to BitmaskValue field");
441 static_assert(!ParsedOptions::HasSequenceSizeForcing,
442 "comms::option::def::SequenceSizeForcingEnabled option is not applicable to BitmaskValue field");
443 static_assert(!ParsedOptions::HasSequenceLengthForcing,
444 "comms::option::def::SequenceLengthForcingEnabled option is not applicable to BitmaskValue field");
445 static_assert(!ParsedOptions::HasSequenceFixedSize,
446 "comms::option::def::SequenceFixedSize option is not applicable to BitmaskValue field");
447 static_assert(!ParsedOptions::HasSequenceFixedSizeUseFixedSizeStorage,
448 "comms::option::app::SequenceFixedSizeUseFixedSizeStorage option is not applicable to BitmaskValue field");
449 static_assert(!ParsedOptions::HasSequenceSizeFieldPrefix,
450 "comms::option::def::SequenceSizeFieldPrefix option is not applicable to BitmaskValue field");
451 static_assert(!ParsedOptions::HasSequenceSerLengthFieldPrefix,
452 "comms::option::def::SequenceSerLengthFieldPrefix option is not applicable to BitmaskValue field");
453 static_assert(!ParsedOptions::HasSequenceElemSerLengthFieldPrefix,
454 "comms::option::def::SequenceElemSerLengthFieldPrefix option is not applicable to BitmaskValue field");
455 static_assert(!ParsedOptions::HasSequenceElemFixedSerLengthFieldPrefix,
456 "comms::option::def::SequenceElemSerLengthFixedFieldPrefix option is not applicable to BitmaskValue field");
457 static_assert(!ParsedOptions::HasSequenceTrailingFieldSuffix,
458 "comms::option::def::SequenceTrailingFieldSuffix option is not applicable to BitmaskValue field");
459 static_assert(!ParsedOptions::HasSequenceTerminationFieldSuffix,
460 "comms::option::def::SequenceTerminationFieldSuffix option is not applicable to BitmaskValue field");
461 static_assert(!ParsedOptions::HasFixedSizeStorage,
462 "comms::option::app::FixedSizeStorage option is not applicable to BitmaskValue field");
463 static_assert(!ParsedOptions::HasCustomStorageType,
464 "comms::option::app::CustomStorageType option is not applicable to BitmaskValue field");
465 static_assert(!ParsedOptions::HasScalingRatio,
466 "comms::option::def::ScalingRatio option is not applicable to BitmaskValue field");
467 static_assert(!ParsedOptions::HasUnits,
468 "comms::option::def::Units option is not applicable to BitmaskValue field");
469 static_assert(!ParsedOptions::HasOrigDataView,
470 "comms::option::app::OrigDataView option is not applicable to BitmaskValue field");
471 static_assert(!ParsedOptions::HasMultiRangeValidation,
472 "comms::option::def::ValidNumValueRange (or similar) option is not applicable to BitmaskValue field");
473 static_assert(!ParsedOptions::HasVersionsRange,
474 "comms::option::def::ExistsBetweenVersions (or similar) option is not applicable to BitmaskValue field");
475 static_assert(!ParsedOptions::HasInvalidByDefault,
476 "comms::option::def::InvalidByDefault option is not applicable to BitmaskValue field");
477 static_assert(!ParsedOptions::HasMissingOnReadFail,
478 "comms::option::def::MissingOnReadFail option is not applicable to BitmaskValue field");
479 static_assert(!ParsedOptions::HasMissingOnInvalid,
480 "comms::option::def::MissingOnInvalid option is not applicable to BitmaskValue field");
481 IntValueField m_intValue;
491template <
typename TFieldBase,
typename... TOptions>
496 return field1.value() == field2.value();
504template <
typename TFieldBase,
typename... TOptions>
509 return field1.value() != field2.value();
517template <
typename TFieldBase,
typename... TOptions>
522 return field1.value() < field2.value();
533 return std::is_same<typename T::CommsTag, tag::Bitmask>::value;
539template <
typename TFieldBase,
typename... TOptions>
550template <
typename TFieldBase,
typename... TOptions>
607#define COMMS_BITMASK_BITS(...) COMMS_DEFINE_ENUM(BitIdx, __VA_ARGS__)
701#define COMMS_BITMASK_BITS_ACCESS(...) \
702 COMMS_AS_BITMASK_FUNC { \
703 return comms::field::toFieldBase(*this); \
705 COMMS_AS_BITMASK_CONST_FUNC { \
706 return comms::field::toFieldBase(*this); \
708 COMMS_DO_BIT_ACC_FUNC(asBitmask(), __VA_ARGS__)
720#define COMMS_BITMASK_BITS_ACCESS_NOTEMPLATE(...) \
721 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:106
const ValueType & value() const
Get access to underlying mask value storage.
Definition BitmaskValue.h:210
void setForcedLength(int len)
Force serialization length of the field.
Definition BitmaskValue.h:417
void clearBits(ValueType mask)
Set all the provided bits.
Definition BitmaskValue.h:360
int getForcedLength() const
Get forced serialization length.
Definition BitmaskValue.h:424
void setValue(U &&val)
Set value.
Definition BitmaskValue.h:230
VersionType getVersion() const
Get version of the field.
Definition BitmaskValue.h:398
ErrorStatus read(TIter &iter, std::size_t size)
Read field value from input data sequence.
Definition BitmaskValue.h:262
static constexpr bool hasFixedValue()
Compile time inquiry of whether comms::option::def::FixedValue option has been used.
Definition BitmaskValue.h:196
bool operator<(const BitmaskValue< TFieldBase, TOptions... > &field1, const BitmaskValue< TFieldBase, TOptions... > &field2) noexcept
Equivalence comparison operator.
Definition BitmaskValue.h:518
typename IntValueField::ValueType ValueType
Type of underlying integral value.
Definition BitmaskValue.h:139
bool getBitValue(unsigned bitNum) const
Get bit value.
Definition BitmaskValue.h:366
static constexpr bool hasWriteNoStatus()
Compile time check of whether the field has proper writeNoStatus() member function.
Definition BitmaskValue.h:304
static constexpr bool isVersionDependent()
Compile time check if this class is version dependent.
Definition BitmaskValue.h:385
static constexpr bool hasReadNoStatus()
Compile time check of whether the field has proper readNoStatus() member function.
Definition BitmaskValue.h:269
constexpr bool valid() const
Check validity of the field value.
Definition BitmaskValue.h:321
typename BaseImpl::VersionType VersionType
Version type.
Definition BitmaskValue.h:128
bool setVersion(VersionType version)
Default implementation of version update.
Definition BitmaskValue.h:405
void readNoStatus(TIter &iter)
Read field value from input data sequence without error check and status report.
Definition BitmaskValue.h:280
static constexpr bool hasEmptySerialization()
Compile time inquiry of whether comms::option::def::EmptySerialization option has been used.
Definition BitmaskValue.h:182
static constexpr std::size_t minLength()
Get minimal length that is required to serialise field of this type.
Definition BitmaskValue.h:251
static constexpr bool hasName()
Compile time inquiry of whether comms::option::def::HasName option has been used.
Definition BitmaskValue.h:203
constexpr bool isBitmaskValue()
Compile time check function of whether a provided type is any variant of comms::field::BitmaskValue.
Definition BitmaskValue.h:531
static constexpr bool hasFieldType()
Compile time inquiry of whether comms::option::def::FieldType option has been used.
Definition BitmaskValue.h:189
void setBitValue(unsigned bitNum, bool val)
Set bit value.
Definition BitmaskValue.h:373
ValueType & value()
Get access to underlying mask value storage.
Definition BitmaskValue.h:217
bool canWrite() const
Check of whether the field has a consistent value for writing.
Definition BitmaskValue.h:286
static constexpr bool hasIgnoreInvalid()
Compile time inquiry of whether comms::option::def::IgnoreInvalid option has been used.
Definition BitmaskValue.h:175
tag::Bitmask CommsTag
Tag indicating type of the field.
Definition BitmaskValue.h:134
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:553
~BitmaskValue() noexcept=default
Destructor.
bool hasAnyBitsSet(ValueType mask) const
Check whether any bits from provided mask are set.
Definition BitmaskValue.h:344
bool refresh()
Refresh contents of the field.
Definition BitmaskValue.h:328
typename ParsedOptions::FieldType FieldType
Type of actual extending field specified via comms::option::def::FieldType.
Definition BitmaskValue.h:144
OptionsBundle ParsedOptions
All the options provided to this class bundled into struct.
Definition BitmaskValue.h:131
BitmaskValue(const ValueType &val)
Constructor.
Definition BitmaskValue.h:152
ErrorStatus write(TIter &iter, std::size_t size) const
Write current field value to output data sequence.
Definition BitmaskValue.h:297
constexpr std::size_t length() const
Get length required to serialise the current field value.
Definition BitmaskValue.h:237
BitmaskValue(const BitmaskValue &)=default
Copy constructor.
TFieldBase FieldBase
Base class provided in the first template parameter.
Definition BitmaskValue.h:122
bool operator!=(const BitmaskValue< TFieldBase, TOptions... > &field1, const BitmaskValue< TFieldBase, TOptions... > &field2) noexcept
Non-equality comparison operator.
Definition BitmaskValue.h:505
const ValueType & getValue() const
Get value.
Definition BitmaskValue.h:223
static constexpr std::size_t maxLength()
Get maximal length that is required to serialise field of this type.
Definition BitmaskValue.h:244
void setBits(ValueType mask)
Set all the provided bits.
Definition BitmaskValue.h:352
static constexpr bool hasFailOnInvalid()
Compile time inquiry of whether comms::option::def::FailOnInvalid option has been used.
Definition BitmaskValue.h:168
BitmaskValue()=default
Default constructor.
static constexpr bool hasNonDefaultRefresh()
Compile time check if this class has non-default refresh functionality.
Definition BitmaskValue.h:391
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:542
void writeNoStatus(TIter &iter) const
Write current field value to output data sequence without error check and status report.
Definition BitmaskValue.h:315
bool operator==(const BitmaskValue< TFieldBase, TOptions... > &field1, const BitmaskValue< TFieldBase, TOptions... > &field2) noexcept
Equality comparison operator.
Definition BitmaskValue.h:492
bool hasAllBitsSet(ValueType mask) const
Check whether all bits from provided mask are set.
Definition BitmaskValue.h:336
typename BaseImpl::Endian Endian
Endian used for serialisation.
Definition BitmaskValue.h:125
typename BaseImpl::ValueType ValueType
Type of underlying integral value.
Definition IntValue.h:97
bool setVersion(VersionType version)
Default implementation of version update.
Definition IntValue.h:426
bool valid() const
Check validity of the field value.
Definition IntValue.h:329
int getForcedLength() const
Get forced serialization length.
Definition IntValue.h:445
VersionType getVersion() const
Get version of the field.
Definition IntValue.h:419
constexpr std::size_t length() const
Get length required to serialise the current field value.
Definition IntValue.h:309
static constexpr std::size_t maxLength()
Get maximal length that is required to serialise field of this type.
Definition IntValue.h:323
void readNoStatus(TIter &iter)
Read field value from input data sequence without error check and status report.
Definition IntValue.h:365
static constexpr std::size_t minLength()
Get minimal length that is required to serialise field of this type.
Definition IntValue.h:316
ErrorStatus read(TIter &iter, std::size_t size)
Read field value from input data sequence.
Definition IntValue.h:347
void setForcedLength(int len)
Force serialization length of the field.
Definition IntValue.h:438
void setValue(U &&val)
Set value.
Definition IntValue.h:273
ErrorStatus write(TIter &iter, std::size_t size) const
Write current field value to output data sequence.
Definition IntValue.h:382
const ValueType & value() const
Get access to integral value storage.
Definition IntValue.h:252
void writeNoStatus(TIter &iter) const
Write current field value to output data sequence without error check and status report.
Definition IntValue.h:400
static constexpr bool isVersionDependent()
Compile time check if this class is version dependent.
Definition IntValue.h:406
bool refresh()
Refresh the field's value.
Definition IntValue.h:336
const ValueType & getValue() const
Get value.
Definition IntValue.h:265
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