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>;
101template <
typename TFieldBase,
typename... TOptions>
104 using BaseImpl = TFieldBase;
106 using OptionsBundle = details::OptionsParser<TOptions...>;
108 using IntValueType = details::BitmaskUndertlyingTypeT<OptionsBundle>;
122 using Endian =
typename BaseImpl::Endian;
167 return ParsedOptions::HasFailOnInvalid;
174 return ParsedOptions::HasIgnoreInvalid;
181 return ParsedOptions::HasEmptySerialization;
188 return ParsedOptions::HasFieldType;
195 return intValue_.
value();
202 return intValue_.
value();
212 template <
typename U>
215 intValue_.
setValue(std::forward<U>(val));
222 return intValue_.
length();
244 template <
typename TIter>
247 return intValue_.
read(iter, size);
254 return BaseImpl::hasReadNoStatus();
262 template <
typename TIter>
271 return BaseImpl::canWrite();
279 template <
typename TIter>
282 return intValue_.
write(iter, size);
289 return BaseImpl::hasWriteNoStatus();
297 template <
typename TIter>
306 return intValue_.
valid();
321 return (
value() & mask) == mask;
329 return (
value() & mask) != 0;
376 return BaseImpl::hasNonDefaultRefresh();
413 using BaseImpl::readData;
414 using BaseImpl::writeData;
418 static_assert(!ParsedOptions::HasSerOffset,
419 "comms::option::def::NumValueSerOffset option is not applicable to BitmaskValue field");
420 static_assert(!ParsedOptions::HasVarLengthLimits,
421 "comms::option::def::VarLength option is not applicable to BitmaskValue field");
422 static_assert(!ParsedOptions::HasSequenceElemLengthForcing,
423 "comms::option::def::SequenceElemLengthForcingEnabled option is not applicable to BitmaskValue field");
424 static_assert(!ParsedOptions::HasSequenceSizeForcing,
425 "comms::option::def::SequenceSizeForcingEnabled option is not applicable to BitmaskValue field");
426 static_assert(!ParsedOptions::HasSequenceLengthForcing,
427 "comms::option::def::SequenceLengthForcingEnabled option is not applicable to BitmaskValue field");
428 static_assert(!ParsedOptions::HasSequenceFixedSize,
429 "comms::option::def::SequenceFixedSize option is not applicable to BitmaskValue field");
430 static_assert(!ParsedOptions::HasSequenceFixedSizeUseFixedSizeStorage,
431 "comms::option::app::SequenceFixedSizeUseFixedSizeStorage option is not applicable to BitmaskValue field");
432 static_assert(!ParsedOptions::HasSequenceSizeFieldPrefix,
433 "comms::option::def::SequenceSizeFieldPrefix option is not applicable to BitmaskValue field");
434 static_assert(!ParsedOptions::HasSequenceSerLengthFieldPrefix,
435 "comms::option::def::SequenceSerLengthFieldPrefix option is not applicable to BitmaskValue field");
436 static_assert(!ParsedOptions::HasSequenceElemSerLengthFieldPrefix,
437 "comms::option::def::SequenceElemSerLengthFieldPrefix option is not applicable to BitmaskValue field");
438 static_assert(!ParsedOptions::HasSequenceElemFixedSerLengthFieldPrefix,
439 "comms::option::def::SequenceElemSerLengthFixedFieldPrefix option is not applicable to BitmaskValue field");
440 static_assert(!ParsedOptions::HasSequenceTrailingFieldSuffix,
441 "comms::option::def::SequenceTrailingFieldSuffix option is not applicable to BitmaskValue field");
442 static_assert(!ParsedOptions::HasSequenceTerminationFieldSuffix,
443 "comms::option::def::SequenceTerminationFieldSuffix option is not applicable to BitmaskValue field");
444 static_assert(!ParsedOptions::HasFixedSizeStorage,
445 "comms::option::app::FixedSizeStorage option is not applicable to BitmaskValue field");
446 static_assert(!ParsedOptions::HasCustomStorageType,
447 "comms::option::app::CustomStorageType option is not applicable to BitmaskValue field");
448 static_assert(!ParsedOptions::HasScalingRatio,
449 "comms::option::def::ScalingRatio option is not applicable to BitmaskValue field");
450 static_assert(!ParsedOptions::HasUnits,
451 "comms::option::def::Units option is not applicable to BitmaskValue field");
452 static_assert(!ParsedOptions::HasOrigDataView,
453 "comms::option::app::OrigDataView option is not applicable to BitmaskValue field");
454 static_assert(!ParsedOptions::HasMultiRangeValidation,
455 "comms::option::def::ValidNumValueRange (or similar) option is not applicable to BitmaskValue field");
456 static_assert(!ParsedOptions::HasVersionsRange,
457 "comms::option::def::ExistsBetweenVersions (or similar) option is not applicable to BitmaskValue field");
458 static_assert(!ParsedOptions::HasInvalidByDefault,
459 "comms::option::def::InvalidByDefault option is not applicable to BitmaskValue field");
460 static_assert(!ParsedOptions::HasMissingOnReadFail,
461 "comms::option::def::MissingOnReadFail option is not applicable to BitmaskValue field");
462 static_assert(!ParsedOptions::HasMissingOnInvalid,
463 "comms::option::def::MissingOnInvalid option is not applicable to BitmaskValue field");
464 IntValueField intValue_;
474template <
typename TFieldBase,
typename... TOptions>
479 return field1.value() == field2.value();
487template <
typename TFieldBase,
typename... TOptions>
492 return field1.value() != field2.value();
500template <
typename TFieldBase,
typename... TOptions>
505 return field1.value() < field2.value();
516 return std::is_same<typename T::CommsTag, tag::Bitmask>::value;
522template <
typename TFieldBase,
typename... TOptions>
533template <
typename TFieldBase,
typename... TOptions>
590#define COMMS_BITMASK_BITS(...) COMMS_DEFINE_ENUM(BitIdx, __VA_ARGS__)
684#define COMMS_BITMASK_BITS_ACCESS(...) \
685 COMMS_AS_BITMASK_FUNC { \
686 return comms::field::toFieldBase(*this); \
688 COMMS_AS_BITMASK_CONST_FUNC { \
689 return comms::field::toFieldBase(*this); \
691 COMMS_DO_BIT_ACC_FUNC(asBitmask(), __VA_ARGS__)
703#define COMMS_BITMASK_BITS_ACCESS_NOTEMPLATE(...) \
704 COMMS_DO_BIT_ACC_FUNC((*this), __VA_ARGS__)
776#define COMMS_BITMASK_BITS_SEQ(...) \
777 COMMS_BITMASK_BITS(__VA_ARGS__) \
778 COMMS_BITMASK_BITS_ACCESS(__VA_ARGS__)
791#define COMMS_BITMASK_BITS_SEQ_NOTEMPLATE(...) \
792 COMMS_BITMASK_BITS(__VA_ARGS__) \
793 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:103
const ValueType & value() const
Get access to underlying mask value storage.
Definition BitmaskValue.h:193
void setForcedLength(int len)
Force serialization length of the field.
Definition BitmaskValue.h:400
void clearBits(ValueType mask)
Set all the provided bits.
Definition BitmaskValue.h:343
int getForcedLength() const
Get forced serialization length.
Definition BitmaskValue.h:407
void setValue(U &&val)
Set value.
Definition BitmaskValue.h:213
VersionType getVersion() const
Get version of the field.
Definition BitmaskValue.h:381
ErrorStatus read(TIter &iter, std::size_t size)
Read field value from input data sequence.
Definition BitmaskValue.h:245
bool operator<(const BitmaskValue< TFieldBase, TOptions... > &field1, const BitmaskValue< TFieldBase, TOptions... > &field2) noexcept
Equivalence comparison operator.
Definition BitmaskValue.h:501
typename IntValueField::ValueType ValueType
Type of underlying integral value.
Definition BitmaskValue.h:136
bool getBitValue(unsigned bitNum) const
Get bit value.
Definition BitmaskValue.h:349
static constexpr bool hasWriteNoStatus()
Compile time check of whether the field has proper writeNoStatus() member function.
Definition BitmaskValue.h:287
static constexpr bool isVersionDependent()
Compile time check if this class is version dependent.
Definition BitmaskValue.h:368
static constexpr bool hasReadNoStatus()
Compile time check of whether the field has proper readNoStatus() member function.
Definition BitmaskValue.h:252
constexpr bool valid() const
Check validity of the field value.
Definition BitmaskValue.h:304
typename BaseImpl::VersionType VersionType
Version type.
Definition BitmaskValue.h:125
bool setVersion(VersionType version)
Default implementation of version update.
Definition BitmaskValue.h:388
void readNoStatus(TIter &iter)
Read field value from input data sequence without error check and status report.
Definition BitmaskValue.h:263
static constexpr bool hasEmptySerialization()
Compile time inquiry of whether comms::option::def::EmptySerialization option has been used.
Definition BitmaskValue.h:179
static constexpr std::size_t minLength()
Get minimal length that is required to serialise field of this type.
Definition BitmaskValue.h:234
constexpr bool isBitmaskValue()
Compile time check function of whether a provided type is any variant of comms::field::BitmaskValue.
Definition BitmaskValue.h:514
static constexpr bool hasFieldType()
Compile time inquiry of whether comms::option::def::FieldType option has been used.
Definition BitmaskValue.h:186
void setBitValue(unsigned bitNum, bool val)
Set bit value.
Definition BitmaskValue.h:356
ValueType & value()
Get access to underlying mask value storage.
Definition BitmaskValue.h:200
bool canWrite() const
Check of whether the field has a consistent value for writing.
Definition BitmaskValue.h:269
static constexpr bool hasIgnoreInvalid()
Compile time inquiry of whether comms::option::def::IgnoreInvalid option has been used.
Definition BitmaskValue.h:172
tag::Bitmask CommsTag
Tag indicating type of the field.
Definition BitmaskValue.h:131
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:536
~BitmaskValue() noexcept=default
Destructor.
bool hasAnyBitsSet(ValueType mask) const
Check whether any bits from provided mask are set.
Definition BitmaskValue.h:327
bool refresh()
Refresh contents of the field.
Definition BitmaskValue.h:311
typename ParsedOptions::FieldType FieldType
Type of actual extending field specified via comms::option::def::FieldType.
Definition BitmaskValue.h:141
OptionsBundle ParsedOptions
All the options provided to this class bundled into struct.
Definition BitmaskValue.h:128
BitmaskValue(const ValueType &val)
Constructor.
Definition BitmaskValue.h:149
ErrorStatus write(TIter &iter, std::size_t size) const
Write current field value to output data sequence.
Definition BitmaskValue.h:280
constexpr std::size_t length() const
Get length required to serialise the current field value.
Definition BitmaskValue.h:220
BitmaskValue(const BitmaskValue &)=default
Copy constructor.
TFieldBase FieldBase
Base class provided in the first template parameter.
Definition BitmaskValue.h:119
bool operator!=(const BitmaskValue< TFieldBase, TOptions... > &field1, const BitmaskValue< TFieldBase, TOptions... > &field2) noexcept
Non-equality comparison operator.
Definition BitmaskValue.h:488
const ValueType & getValue() const
Get value.
Definition BitmaskValue.h:206
static constexpr std::size_t maxLength()
Get maximal length that is required to serialise field of this type.
Definition BitmaskValue.h:227
void setBits(ValueType mask)
Set all the provided bits.
Definition BitmaskValue.h:335
static constexpr bool hasFailOnInvalid()
Compile time inquiry of whether comms::option::def::FailOnInvalid option has been used.
Definition BitmaskValue.h:165
BitmaskValue()=default
Default constructor.
static constexpr bool hasNonDefaultRefresh()
Compile time check if this class has non-default refresh functionality.
Definition BitmaskValue.h:374
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:525
void writeNoStatus(TIter &iter) const
Write current field value to output data sequence without error check and status report.
Definition BitmaskValue.h:298
bool operator==(const BitmaskValue< TFieldBase, TOptions... > &field1, const BitmaskValue< TFieldBase, TOptions... > &field2) noexcept
Equality comparison operator.
Definition BitmaskValue.h:475
bool hasAllBitsSet(ValueType mask) const
Check whether all bits from provided mask are set.
Definition BitmaskValue.h:319
typename BaseImpl::Endian Endian
Endian used for serialisation.
Definition BitmaskValue.h:122
typename BaseImpl::ValueType ValueType
Type of underlying integral value.
Definition IntValue.h:93
bool setVersion(VersionType version)
Default implementation of version update.
Definition IntValue.h:384
bool valid() const
Check validity of the field value.
Definition IntValue.h:287
int getForcedLength() const
Get forced serialization length.
Definition IntValue.h:403
VersionType getVersion() const
Get version of the field.
Definition IntValue.h:377
constexpr std::size_t length() const
Get length required to serialise the current field value.
Definition IntValue.h:267
static constexpr std::size_t maxLength()
Get maximal length that is required to serialise field of this type.
Definition IntValue.h:281
void readNoStatus(TIter &iter)
Read field value from input data sequence without error check and status report.
Definition IntValue.h:323
static constexpr std::size_t minLength()
Get minimal length that is required to serialise field of this type.
Definition IntValue.h:274
ErrorStatus read(TIter &iter, std::size_t size)
Read field value from input data sequence.
Definition IntValue.h:305
void setForcedLength(int len)
Force serialization length of the field.
Definition IntValue.h:396
void setValue(U &&val)
Set value.
Definition IntValue.h:248
ErrorStatus write(TIter &iter, std::size_t size) const
Write current field value to output data sequence.
Definition IntValue.h:340
const ValueType & value() const
Get access to integral value storage.
Definition IntValue.h:227
void writeNoStatus(TIter &iter) const
Write current field value to output data sequence without error check and status report.
Definition IntValue.h:358
static constexpr bool isVersionDependent()
Compile time check if this class is version dependent.
Definition IntValue.h:364
bool refresh()
Refresh the field's value.
Definition IntValue.h:294
const ValueType & getValue() const
Get value.
Definition IntValue.h:240
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