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/FieldOptionsParser.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>;
110template <
typename TFieldBase,
typename... TOptions>
113 using BaseImpl = TFieldBase;
115 using OptionsBundle = details::FieldOptionsParser<TOptions...>;
117 using IntValueType = details::BitmaskUndertlyingTypeT<OptionsBundle>;
119 using IntValueField =
131 using Endian =
typename BaseImpl::Endian;
176 return ParsedOptions::HasFailOnInvalid;
183 return ParsedOptions::HasIgnoreInvalid;
190 return ParsedOptions::HasEmptySerialization;
197 return ParsedOptions::HasFieldType;
204 return ParsedOptions::HasFixedValue;
211 return ParsedOptions::HasName;
218 return ParsedOptions::HasReadAlign;
225 return ParsedOptions::HasWritePadAlign;
232 return m_intValue.value();
239 return m_intValue.value();
245 return m_intValue.getValue();
249 template <
typename U>
252 m_intValue.setValue(std::forward<U>(val));
259 return m_intValue.length();
281 template <
typename TIter>
284 return m_intValue.read(iter, size);
291 return BaseImpl::hasReadNoStatus();
299 template <
typename TIter>
302 m_intValue.readNoStatus(iter);
308 return BaseImpl::canWrite();
316 template <
typename TIter>
319 return m_intValue.write(iter, size);
326 return BaseImpl::hasWriteNoStatus();
334 template <
typename TIter>
337 m_intValue.writeNoStatus(iter);
343 return m_intValue.valid();
350 return m_intValue.refresh();
358 return (
value() & mask) == mask;
366 return (
value() & mask) != 0;
374 return (
value() & mask) == 0U;
421 return BaseImpl::hasNonDefaultRefresh();
428 return m_intValue.getVersion();
435 return m_intValue.setVersion(
version);
447 m_intValue.setForcedLength(len);
454 return m_intValue.getForcedLength();
460 template <
typename TBitIdx>
463 return static_cast<ValueType>(
static_cast<ValueType>(1) <<
static_cast<unsigned>(idx));
467 using BaseImpl::readData;
468 using BaseImpl::writeData;
472 static_assert(!ParsedOptions::HasSerOffset,
473 "comms::option::def::NumValueSerOffset option is not applicable to BitmaskValue field");
474 static_assert(!ParsedOptions::HasVarLengthLimits,
475 "comms::option::def::VarLength option is not applicable to BitmaskValue field");
476 static_assert(!ParsedOptions::HasSequenceElemLengthForcing,
477 "comms::option::def::SequenceElemLengthForcingEnabled option is not applicable to BitmaskValue field");
478 static_assert(!ParsedOptions::HasSequenceSizeForcing,
479 "comms::option::def::SequenceSizeForcingEnabled option is not applicable to BitmaskValue field");
480 static_assert(!ParsedOptions::HasSequenceLengthForcing,
481 "comms::option::def::SequenceLengthForcingEnabled option is not applicable to BitmaskValue field");
482 static_assert(!ParsedOptions::HasSequenceFixedSize,
483 "comms::option::def::SequenceFixedSize option is not applicable to BitmaskValue field");
484 static_assert(!ParsedOptions::HasSequenceFixedSizeUseFixedSizeStorage,
485 "comms::option::app::SequenceFixedSizeUseFixedSizeStorage option is not applicable to BitmaskValue field");
486 static_assert(!ParsedOptions::HasSequenceSizeFieldPrefix,
487 "comms::option::def::SequenceSizeFieldPrefix option is not applicable to BitmaskValue field");
488 static_assert(!ParsedOptions::HasSequenceSerLengthFieldPrefix,
489 "comms::option::def::SequenceSerLengthFieldPrefix option is not applicable to BitmaskValue field");
490 static_assert(!ParsedOptions::HasSequenceElemSerLengthFieldPrefix,
491 "comms::option::def::SequenceElemSerLengthFieldPrefix option is not applicable to BitmaskValue field");
492 static_assert(!ParsedOptions::HasSequenceElemFixedSerLengthFieldPrefix,
493 "comms::option::def::SequenceElemSerLengthFixedFieldPrefix option is not applicable to BitmaskValue field");
494 static_assert(!ParsedOptions::HasSequenceTrailingFieldSuffix,
495 "comms::option::def::SequenceTrailingFieldSuffix option is not applicable to BitmaskValue field");
496 static_assert(!ParsedOptions::HasSequenceTerminationFieldSuffix,
497 "comms::option::def::SequenceTerminationFieldSuffix option is not applicable to BitmaskValue field");
498 static_assert(!ParsedOptions::HasFixedSizeStorage,
499 "comms::option::app::FixedSizeStorage option is not applicable to BitmaskValue field");
500 static_assert(!ParsedOptions::HasCustomStorageType,
501 "comms::option::app::CustomStorageType option is not applicable to BitmaskValue field");
502 static_assert(!ParsedOptions::HasScalingRatio,
503 "comms::option::def::ScalingRatio option is not applicable to BitmaskValue field");
504 static_assert(!ParsedOptions::HasUnits,
505 "comms::option::def::Units option is not applicable to BitmaskValue field");
506 static_assert(!ParsedOptions::HasOrigDataView,
507 "comms::option::app::OrigDataView option is not applicable to BitmaskValue field");
508 static_assert(!ParsedOptions::HasMultiRangeValidation,
509 "comms::option::def::ValidNumValueRange (or similar) option is not applicable to BitmaskValue field");
510 static_assert(!ParsedOptions::HasVersionsRange,
511 "comms::option::def::ExistsBetweenVersions (or similar) option is not applicable to BitmaskValue field");
512 static_assert(!ParsedOptions::HasInvalidByDefault,
513 "comms::option::def::InvalidByDefault option is not applicable to BitmaskValue field");
514 static_assert(!ParsedOptions::HasMissingOnReadFail,
515 "comms::option::def::MissingOnReadFail option is not applicable to BitmaskValue field");
516 static_assert(!ParsedOptions::HasMissingOnInvalid,
517 "comms::option::def::MissingOnInvalid option is not applicable to BitmaskValue field");
518 IntValueField m_intValue;
528template <
typename TFieldBase,
typename... TOptions>
533 return field1.value() == field2.value();
541template <
typename TFieldBase,
typename... TOptions>
546 return field1.value() != field2.value();
554template <
typename TFieldBase,
typename... TOptions>
559 return field1.value() < field2.value();
570 return std::is_same<typename T::CommsTag, tag::Bitmask>::value;
576template <
typename TFieldBase,
typename... TOptions>
587template <
typename TFieldBase,
typename... TOptions>
642#define COMMS_BITMASK_BITS(...) COMMS_DEFINE_ENUM(BitIdx, __VA_ARGS__)
735#define COMMS_BITMASK_BITS_ACCESS(...) \
736 COMMS_AS_BITMASK_FUNC { \
737 return comms::field::toFieldBase(*this); \
739 COMMS_AS_BITMASK_CONST_FUNC { \
740 return comms::field::toFieldBase(*this); \
742 COMMS_DO_BIT_ACC_FUNC(asBitmask(), __VA_ARGS__)
753#define COMMS_BITMASK_BITS_ACCESS_NOTEMPLATE(...) \
754 COMMS_DO_BIT_ACC_FUNC((*this), __VA_ARGS__)
824#define COMMS_BITMASK_BITS_SEQ(...) \
825 COMMS_BITMASK_BITS(__VA_ARGS__) \
826 COMMS_BITMASK_BITS_ACCESS(__VA_ARGS__)
838#define COMMS_BITMASK_BITS_SEQ_NOTEMPLATE(...) \
839 COMMS_BITMASK_BITS(__VA_ARGS__) \
840 COMMS_BITMASK_BITS_ACCESS_NOTEMPLATE(__VA_ARGS__)
893#define COMMS_BITMASK_MASK(...) \
894 COMMS_EXPAND(COMMS_DEFINE_BIT_MASK(__VA_ARGS__)) \
895 COMMS_EXPAND(COMMS_DO_MASK_FUNC(__VA_ARGS__))
Contains definition of comms::Field class.
Contains definition of comms::field::IntValue.
Bitmask value field.
Definition BitmaskValue.h:112
const ValueType & value() const
Get access to underlying mask value storage.
Definition BitmaskValue.h:230
static constexpr bool hasWritePadAlign()
Compile time inquiry of whether comms::option::def::WritePadAlign option has been used.
Definition BitmaskValue.h:223
void setForcedLength(int len)
Force serialization length of the field.
Definition BitmaskValue.h:445
void clearBits(ValueType mask)
Set all the provided bits.
Definition BitmaskValue.h:388
int getForcedLength() const
Get forced serialization length.
Definition BitmaskValue.h:452
void setValue(U &&val)
Set value.
Definition BitmaskValue.h:250
static constexpr ValueType bitAsMask(TBitIdx idx)
Convert bit index to the mask that can be used with setBits() or clearBits().
Definition BitmaskValue.h:461
VersionType getVersion() const
Get version of the field.
Definition BitmaskValue.h:426
ErrorStatus read(TIter &iter, std::size_t size)
Read field value from input data sequence.
Definition BitmaskValue.h:282
static constexpr bool hasFixedValue()
Compile time inquiry of whether comms::option::def::FixedValue option has been used.
Definition BitmaskValue.h:202
bool operator<(const BitmaskValue< TFieldBase, TOptions... > &field1, const BitmaskValue< TFieldBase, TOptions... > &field2) noexcept
Equivalence comparison operator.
Definition BitmaskValue.h:555
typename IntValueField::ValueType ValueType
Type of underlying integral value.
Definition BitmaskValue.h:145
bool getBitValue(unsigned bitNum) const
Get bit value.
Definition BitmaskValue.h:394
static constexpr bool hasWriteNoStatus()
Compile time check of whether the field has proper writeNoStatus() member function.
Definition BitmaskValue.h:324
static constexpr bool isVersionDependent()
Compile time check if this class is version dependent.
Definition BitmaskValue.h:413
static constexpr bool hasReadNoStatus()
Compile time check of whether the field has proper readNoStatus() member function.
Definition BitmaskValue.h:289
constexpr bool valid() const
Check validity of the field value.
Definition BitmaskValue.h:341
typename BaseImpl::VersionType VersionType
Version type.
Definition BitmaskValue.h:134
bool setVersion(VersionType version)
Default implementation of version update.
Definition BitmaskValue.h:433
void readNoStatus(TIter &iter)
Read field value from input data sequence without error check and status report.
Definition BitmaskValue.h:300
static constexpr bool hasEmptySerialization()
Compile time inquiry of whether comms::option::def::EmptySerialization option has been used.
Definition BitmaskValue.h:188
static constexpr std::size_t minLength()
Get minimal length that is required to serialise field of this type.
Definition BitmaskValue.h:271
static constexpr bool hasName()
Compile time inquiry of whether comms::option::def::HasName option has been used.
Definition BitmaskValue.h:209
constexpr bool isBitmaskValue()
Compile time check function of whether a provided type is any variant of comms::field::BitmaskValue.
Definition BitmaskValue.h:568
static constexpr bool hasFieldType()
Compile time inquiry of whether comms::option::def::FieldType option has been used.
Definition BitmaskValue.h:195
void setBitValue(unsigned bitNum, bool val)
Set bit value.
Definition BitmaskValue.h:401
ValueType & value()
Get access to underlying mask value storage.
Definition BitmaskValue.h:237
bool canWrite() const
Check of whether the field has a consistent value for writing.
Definition BitmaskValue.h:306
static constexpr bool hasIgnoreInvalid()
Compile time inquiry of whether comms::option::def::IgnoreInvalid option has been used.
Definition BitmaskValue.h:181
tag::Bitmask CommsTag
Tag indicating type of the field.
Definition BitmaskValue.h:140
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:590
~BitmaskValue() noexcept=default
Destructor.
bool hasAnyBitsSet(ValueType mask) const
Check whether any bits from provided mask are set.
Definition BitmaskValue.h:364
bool refresh()
Refresh contents of the field.
Definition BitmaskValue.h:348
typename ParsedOptions::FieldType FieldType
Type of actual extending field specified via comms::option::def::FieldType.
Definition BitmaskValue.h:150
bool hasAllBitsCleared(ValueType mask) const
Check whether all bits from provided mask are cleared.
Definition BitmaskValue.h:372
OptionsBundle ParsedOptions
All the options provided to this class bundled into struct.
Definition BitmaskValue.h:137
BitmaskValue(const ValueType &val)
Constructor.
Definition BitmaskValue.h:158
ErrorStatus write(TIter &iter, std::size_t size) const
Write current field value to output data sequence.
Definition BitmaskValue.h:317
constexpr std::size_t length() const
Get length required to serialise the current field value.
Definition BitmaskValue.h:257
BitmaskValue(const BitmaskValue &)=default
Copy constructor.
TFieldBase FieldBase
Base class provided in the first template parameter.
Definition BitmaskValue.h:128
bool operator!=(const BitmaskValue< TFieldBase, TOptions... > &field1, const BitmaskValue< TFieldBase, TOptions... > &field2) noexcept
Non-equality comparison operator.
Definition BitmaskValue.h:542
const ValueType & getValue() const
Get value.
Definition BitmaskValue.h:243
static constexpr std::size_t maxLength()
Get maximal length that is required to serialise field of this type.
Definition BitmaskValue.h:264
void setBits(ValueType mask)
Set all the provided bits.
Definition BitmaskValue.h:380
static constexpr bool hasFailOnInvalid()
Compile time inquiry of whether comms::option::def::FailOnInvalid option has been used.
Definition BitmaskValue.h:174
BitmaskValue()=default
Default constructor.
static constexpr bool hasNonDefaultRefresh()
Compile time check if this class has non-default refresh functionality.
Definition BitmaskValue.h:419
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:579
void writeNoStatus(TIter &iter) const
Write current field value to output data sequence without error check and status report.
Definition BitmaskValue.h:335
bool operator==(const BitmaskValue< TFieldBase, TOptions... > &field1, const BitmaskValue< TFieldBase, TOptions... > &field2) noexcept
Equality comparison operator.
Definition BitmaskValue.h:529
bool hasAllBitsSet(ValueType mask) const
Check whether all bits from provided mask are set.
Definition BitmaskValue.h:356
typename BaseImpl::Endian Endian
Endian used for serialisation.
Definition BitmaskValue.h:131
static constexpr bool hasReadAlign()
Compile time inquiry of whether comms::option::def::ReadAlign option has been used.
Definition BitmaskValue.h:216
Field that represent integral value.
Definition IntValue.h:82
typename BaseImpl::ValueType ValueType
Definition IntValue.h:103
static constexpr std::size_t maxLength()
Definition IntValue.h:343
static constexpr std::size_t minLength()
Definition IntValue.h:336
static constexpr bool isVersionDependent()
Definition IntValue.h:426
Contains definition of various tag classes.
Namespace that contains definitions of all message fields.
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