15#include "comms/field/basic/EnumValue.h"
16#include "comms/field/details/AdaptBasicField.h"
17#include "comms/field/details/OptionsParser.h"
77template <
typename TFieldBase,
typename TEnum,
typename... TOptions>
78class EnumValue :
public details::AdaptBasicFieldT<basic::EnumValue<TFieldBase, TEnum>, TOptions...>
80 using BaseImpl = details::AdaptBasicFieldT<basic::EnumValue<TFieldBase, TEnum>, TOptions...>;
81 static_assert(std::is_enum<TEnum>::value,
"TEnum must be enum type");
88 using Endian =
typename BaseImpl::Endian;
130 return ParsedOptions::HasFailOnInvalid;
137 return ParsedOptions::HasIgnoreInvalid;
144 return ParsedOptions::HasEmptySerialization;
151 return ParsedOptions::HasFieldType;
158 return ParsedOptions::HasFixedValue;
165 return ParsedOptions::HasName;
171 return BaseImpl::value();
177 return BaseImpl::value();
184 return BaseImpl::getValue();
189 template <
typename U>
192 BaseImpl::setValue(std::forward<U>(val));
199 return BaseImpl::length();
206 return BaseImpl::minLength();
213 return BaseImpl::maxLength();
221 template <
typename TIter>
224 return BaseImpl::read(iter, size);
231 return BaseImpl::hasReadNoStatus();
239 template <
typename TIter>
242 BaseImpl::readNoStatus(iter);
248 return BaseImpl::canWrite();
256 template <
typename TIter>
259 return BaseImpl::write(iter, size);
266 return BaseImpl::hasWriteNoStatus();
274 template <
typename TIter>
277 BaseImpl::writeNoStatus(iter);
283 return BaseImpl::valid();
290 return BaseImpl::refresh();
296 return ParsedOptions::HasCustomVersionUpdate || BaseImpl::isVersionDependent();
302 return BaseImpl::hasNonDefaultRefresh();
309 return BaseImpl::getVersion();
316 return BaseImpl::setVersion(
version);
328 BaseImpl::setForcedLength(len);
335 return BaseImpl::getForcedLength();
339 using BaseImpl::readData;
340 using BaseImpl::writeData;
342 static_assert(!ParsedOptions::HasSequenceElemLengthForcing,
343 "comms::option::def::SequenceElemLengthForcingEnabled option is not applicable to EnumValue field");
344 static_assert(!ParsedOptions::HasSequenceSizeForcing,
345 "comms::option::def::SequenceSizeForcingEnabled option is not applicable to EnumValue field");
346 static_assert(!ParsedOptions::HasSequenceLengthForcing,
347 "comms::option::def::SequenceLengthForcingEnabled option is not applicable to EnumValue field");
348 static_assert(!ParsedOptions::HasSequenceFixedSize,
349 "comms::option::def::SequenceFixedSize option is not applicable to EnumValue field");
350 static_assert(!ParsedOptions::HasSequenceFixedSizeUseFixedSizeStorage,
351 "comms::option::app::SequenceFixedSizeUseFixedSizeStorage option is not applicable to EnumValue field");
352 static_assert(!ParsedOptions::HasSequenceSizeFieldPrefix,
353 "comms::option::def::SequenceSizeFieldPrefix option is not applicable to EnumValue field");
354 static_assert(!ParsedOptions::HasSequenceSerLengthFieldPrefix,
355 "comms::option::def::SequenceSerLengthFieldPrefix option is not applicable to EnumValue field");
356 static_assert(!ParsedOptions::HasSequenceElemSerLengthFieldPrefix,
357 "comms::option::def::SequenceElemSerLengthFieldPrefix option is not applicable to EnumValue field");
358 static_assert(!ParsedOptions::HasSequenceElemFixedSerLengthFieldPrefix,
359 "comms::option::def::SequenceElemSerLengthFixedFieldPrefix option is not applicable to EnumValue field");
360 static_assert(!ParsedOptions::HasSequenceTrailingFieldSuffix,
361 "comms::option::def::SequenceTrailingFieldSuffix option is not applicable to EnumValue field");
362 static_assert(!ParsedOptions::HasSequenceTerminationFieldSuffix,
363 "comms::option::def::SequenceTerminationFieldSuffix option is not applicable to EnumValue field");
364 static_assert(!ParsedOptions::HasFixedSizeStorage,
365 "comms::option::app::FixedSizeStorage option is not applicable to EnumValue field");
366 static_assert(!ParsedOptions::HasCustomStorageType,
367 "comms::option::app::CustomStorageType option is not applicable to EnumValue field");
368 static_assert(!ParsedOptions::HasScalingRatio,
369 "comms::option::def::ScalingRatio option is not applicable to EnumValue field");
370 static_assert(!ParsedOptions::HasUnits,
371 "comms::option::def::Units option is not applicable to EnumValue field");
372 static_assert(!ParsedOptions::HasOrigDataView,
373 "comms::option::app::OrigDataView option is not applicable to EnumValue field");
374 static_assert(!ParsedOptions::HasVersionsRange,
375 "comms::option::def::ExistsBetweenVersions (or similar) option is not applicable to EnumValue field");
376 static_assert(!ParsedOptions::HasMissingOnReadFail,
377 "comms::option::def::MissingOnReadFail option is not applicable to EnumValue field");
378 static_assert(!ParsedOptions::HasMissingOnInvalid,
379 "comms::option::def::MissingOnInvalid option is not applicable to EnumValue field");
389template <
typename TFieldBase,
typename TEnum,
typename... TOptions>
394 return field1.value() == field2.value();
402template <
typename TFieldBase,
typename TEnum,
typename... TOptions>
407 return field1.value() != field2.value();
415template <
typename TFieldBase,
typename TEnum,
typename... TOptions>
420 return field1.value() < field2.value();
431 return std::is_same<typename T::CommsTag, tag::Enum>::value;
437template <
typename TFieldBase,
typename TEnum,
typename... TOptions>
439EnumValue<TFieldBase, TEnum, TOptions...>&
448template <
typename TFieldBase,
typename TEnum,
typename... TOptions>
450const EnumValue<TFieldBase, TEnum, TOptions...>&
Enumerator value field.
Definition EnumValue.h:79
ValueType & value()
Get access to enum value storage.
Definition EnumValue.h:175
constexpr bool isEnumValue()
Compile time check function of whether a provided type is any variant of comms::field::EnumValue.
Definition EnumValue.h:429
bool operator!=(const EnumValue< TFieldBase, TEnum, TOptions... > &field1, const EnumValue< TFieldBase, TEnum, TOptions... > &field2) noexcept
Non-equality comparison operator.
Definition EnumValue.h:403
void writeNoStatus(TIter &iter) const
Write current field value to output data sequence without error check and status report.
Definition EnumValue.h:275
typename BaseImpl::VersionType VersionType
Version type.
Definition EnumValue.h:91
static constexpr std::size_t maxLength()
Get maximal length that is required to serialise field of this type.
Definition EnumValue.h:211
const EnumValue< TFieldBase, TEnum, TOptions... > & toFieldBase(const EnumValue< TFieldBase, TEnum, TOptions... > &field)
Upcast type of the field definition to its parent comms::field::EnumValue type in order to have acces...
Definition EnumValue.h:451
VersionType getVersion() const
Get version of the field.
Definition EnumValue.h:307
static constexpr bool hasNonDefaultRefresh()
Compile time check if this class has non-default refresh functionality.
Definition EnumValue.h:300
bool valid() const
Check validity of the field value.
Definition EnumValue.h:281
void readNoStatus(TIter &iter)
Read field value from input data sequence without error check and status report.
Definition EnumValue.h:240
typename BaseImpl::CommsTag CommsTag
Tag indicating type of the field.
Definition EnumValue.h:97
void setValue(U &&val)
Set value.
Definition EnumValue.h:190
const ValueType & getValue() const
Get value.
Definition EnumValue.h:182
static constexpr bool hasReadNoStatus()
Compile time check of whether the field has proper readNoStatus() member function.
Definition EnumValue.h:229
EnumValue(const EnumValue &)=default
Copy constructor.
bool operator<(const EnumValue< TFieldBase, TEnum, TOptions... > &field1, const EnumValue< TFieldBase, TEnum, TOptions... > &field2) noexcept
Equivalence comparison operator.
Definition EnumValue.h:416
TFieldBase FieldBase
Base class provided in the first template parameter.
Definition EnumValue.h:85
static constexpr bool hasFixedValue()
Compile time inquiry of whether comms::option::def::FixedValue option has been used.
Definition EnumValue.h:156
static constexpr bool hasIgnoreInvalid()
Compile time inquiry of whether comms::option::def::IgnoreInvalid option has been used.
Definition EnumValue.h:135
int getForcedLength() const
Get forced serialization length.
Definition EnumValue.h:333
ErrorStatus read(TIter &iter, std::size_t size)
Read field value from input data sequence.
Definition EnumValue.h:222
constexpr std::size_t length() const
Get length required to serialise the current field value.
Definition EnumValue.h:197
bool refresh()
Refresh the field's value.
Definition EnumValue.h:288
typename ParsedOptions::FieldType FieldType
Type of actual extending field specified via comms::option::def::FieldType.
Definition EnumValue.h:106
static constexpr bool hasWriteNoStatus()
Compile time check of whether the field has proper writeNoStatus() member function.
Definition EnumValue.h:264
static constexpr bool hasEmptySerialization()
Compile time inquiry of whether comms::option::def::EmptySerialization option has been used.
Definition EnumValue.h:142
EnumValue(const ValueType &val)
Constructor.
Definition EnumValue.h:112
ErrorStatus write(TIter &iter, std::size_t size) const
Write current field value to output data sequence.
Definition EnumValue.h:257
typename BaseImpl::ValueType ValueType
Type of underlying enum value.
Definition EnumValue.h:101
static constexpr bool isVersionDependent()
Compile time check if this class is version dependent.
Definition EnumValue.h:294
static constexpr bool hasFieldType()
Compile time inquiry of whether comms::option::def::FieldType option has been used.
Definition EnumValue.h:149
static constexpr std::size_t minLength()
Get minimal length that is required to serialise field of this type.
Definition EnumValue.h:204
~EnumValue() noexcept=default
Destructor.
void setForcedLength(int len)
Force serialization length of the field.
Definition EnumValue.h:326
details::OptionsParser< TOptions... > ParsedOptions
All the options provided to this class bundled into struct.
Definition EnumValue.h:94
EnumValue()=default
Default constructor.
bool operator==(const EnumValue< TFieldBase, TEnum, TOptions... > &field1, const EnumValue< TFieldBase, TEnum, TOptions... > &field2) noexcept
Equality comparison operator.
Definition EnumValue.h:390
bool canWrite() const
Check of whether the field has a consistent value for writing.
Definition EnumValue.h:246
EnumValue< TFieldBase, TEnum, TOptions... > & toFieldBase(EnumValue< TFieldBase, TEnum, TOptions... > &field)
Upcast type of the field definition to its parent comms::field::EnumValue type in order to have acces...
Definition EnumValue.h:440
static constexpr bool hasFailOnInvalid()
Compile time inquiry of whether comms::option::def::FailOnInvalid option has been used.
Definition EnumValue.h:128
static constexpr bool hasName()
Compile time inquiry of whether comms::option::def::HasName option has been used.
Definition EnumValue.h:163
typename BaseImpl::Endian Endian
Endian used for serialisation.
Definition EnumValue.h:88
bool setVersion(VersionType version)
Default implementation of version update.
Definition EnumValue.h:314
const ValueType & value() const
Get access to enum value storage.
Definition EnumValue.h:169
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
Contains definition of all the options used by the COMMS library.