13#include "comms/field/basic/EnumValue.h"
14#include "comms/field/details/AdaptBasicField.h"
15#include "comms/field/details/OptionsParser.h"
74template <
typename TFieldBase,
typename TEnum,
typename... TOptions>
75class EnumValue :
public details::AdaptBasicFieldT<basic::EnumValue<TFieldBase, TEnum>, TOptions...>
77 using BaseImpl = details::AdaptBasicFieldT<basic::EnumValue<TFieldBase, TEnum>, TOptions...>;
78 static_assert(std::is_enum<TEnum>::value,
"TEnum must be enum type");
85 using Endian =
typename BaseImpl::Endian;
127 return ParsedOptions::HasFailOnInvalid;
134 return ParsedOptions::HasIgnoreInvalid;
141 return ParsedOptions::HasEmptySerialization;
148 return ParsedOptions::HasFieldType;
155 return ParsedOptions::HasFixedValue;
162 return ParsedOptions::HasName;
168 return BaseImpl::value();
174 return BaseImpl::value();
181 return BaseImpl::getValue();
186 template <
typename U>
189 BaseImpl::setValue(std::forward<U>(val));
196 return BaseImpl::length();
203 return BaseImpl::minLength();
210 return BaseImpl::maxLength();
218 template <
typename TIter>
221 return BaseImpl::read(iter, size);
228 return BaseImpl::hasReadNoStatus();
236 template <
typename TIter>
239 BaseImpl::readNoStatus(iter);
245 return BaseImpl::canWrite();
253 template <
typename TIter>
256 return BaseImpl::write(iter, size);
263 return BaseImpl::hasWriteNoStatus();
271 template <
typename TIter>
274 BaseImpl::writeNoStatus(iter);
280 return BaseImpl::valid();
287 return BaseImpl::refresh();
293 return ParsedOptions::HasCustomVersionUpdate || BaseImpl::isVersionDependent();
299 return BaseImpl::hasNonDefaultRefresh();
306 return BaseImpl::getVersion();
313 return BaseImpl::setVersion(
version);
325 BaseImpl::setForcedLength(len);
332 return BaseImpl::getForcedLength();
336 using BaseImpl::readData;
337 using BaseImpl::writeData;
339 static_assert(!ParsedOptions::HasSequenceElemLengthForcing,
340 "comms::option::def::SequenceElemLengthForcingEnabled option is not applicable to EnumValue field");
341 static_assert(!ParsedOptions::HasSequenceSizeForcing,
342 "comms::option::def::SequenceSizeForcingEnabled option is not applicable to EnumValue field");
343 static_assert(!ParsedOptions::HasSequenceLengthForcing,
344 "comms::option::def::SequenceLengthForcingEnabled option is not applicable to EnumValue field");
345 static_assert(!ParsedOptions::HasSequenceFixedSize,
346 "comms::option::def::SequenceFixedSize option is not applicable to EnumValue field");
347 static_assert(!ParsedOptions::HasSequenceFixedSizeUseFixedSizeStorage,
348 "comms::option::app::SequenceFixedSizeUseFixedSizeStorage option is not applicable to EnumValue field");
349 static_assert(!ParsedOptions::HasSequenceSizeFieldPrefix,
350 "comms::option::def::SequenceSizeFieldPrefix option is not applicable to EnumValue field");
351 static_assert(!ParsedOptions::HasSequenceSerLengthFieldPrefix,
352 "comms::option::def::SequenceSerLengthFieldPrefix option is not applicable to EnumValue field");
353 static_assert(!ParsedOptions::HasSequenceElemSerLengthFieldPrefix,
354 "comms::option::def::SequenceElemSerLengthFieldPrefix option is not applicable to EnumValue field");
355 static_assert(!ParsedOptions::HasSequenceElemFixedSerLengthFieldPrefix,
356 "comms::option::def::SequenceElemSerLengthFixedFieldPrefix option is not applicable to EnumValue field");
357 static_assert(!ParsedOptions::HasSequenceTrailingFieldSuffix,
358 "comms::option::def::SequenceTrailingFieldSuffix option is not applicable to EnumValue field");
359 static_assert(!ParsedOptions::HasSequenceTerminationFieldSuffix,
360 "comms::option::def::SequenceTerminationFieldSuffix option is not applicable to EnumValue field");
361 static_assert(!ParsedOptions::HasFixedSizeStorage,
362 "comms::option::app::FixedSizeStorage option is not applicable to EnumValue field");
363 static_assert(!ParsedOptions::HasCustomStorageType,
364 "comms::option::app::CustomStorageType option is not applicable to EnumValue field");
365 static_assert(!ParsedOptions::HasScalingRatio,
366 "comms::option::def::ScalingRatio option is not applicable to EnumValue field");
367 static_assert(!ParsedOptions::HasUnits,
368 "comms::option::def::Units option is not applicable to EnumValue field");
369 static_assert(!ParsedOptions::HasOrigDataView,
370 "comms::option::app::OrigDataView option is not applicable to EnumValue field");
371 static_assert(!ParsedOptions::HasVersionsRange,
372 "comms::option::def::ExistsBetweenVersions (or similar) option is not applicable to EnumValue field");
373 static_assert(!ParsedOptions::HasMissingOnReadFail,
374 "comms::option::def::MissingOnReadFail option is not applicable to EnumValue field");
375 static_assert(!ParsedOptions::HasMissingOnInvalid,
376 "comms::option::def::MissingOnInvalid option is not applicable to EnumValue field");
386template <
typename TFieldBase,
typename TEnum,
typename... TOptions>
391 return field1.value() == field2.value();
399template <
typename TFieldBase,
typename TEnum,
typename... TOptions>
404 return field1.value() != field2.value();
412template <
typename TFieldBase,
typename TEnum,
typename... TOptions>
417 return field1.value() < field2.value();
428 return std::is_same<typename T::CommsTag, tag::Enum>::value;
434template <
typename TFieldBase,
typename TEnum,
typename... TOptions>
436EnumValue<TFieldBase, TEnum, TOptions...>&
445template <
typename TFieldBase,
typename TEnum,
typename... TOptions>
447const EnumValue<TFieldBase, TEnum, TOptions...>&
Enumerator value field.
Definition EnumValue.h:76
ValueType & value()
Get access to enum value storage.
Definition EnumValue.h:172
constexpr bool isEnumValue()
Compile time check function of whether a provided type is any variant of comms::field::EnumValue.
Definition EnumValue.h:426
bool operator!=(const EnumValue< TFieldBase, TEnum, TOptions... > &field1, const EnumValue< TFieldBase, TEnum, TOptions... > &field2) noexcept
Non-equality comparison operator.
Definition EnumValue.h:400
void writeNoStatus(TIter &iter) const
Write current field value to output data sequence without error check and status report.
Definition EnumValue.h:272
typename BaseImpl::VersionType VersionType
Version type.
Definition EnumValue.h:88
static constexpr std::size_t maxLength()
Get maximal length that is required to serialise field of this type.
Definition EnumValue.h:208
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:448
VersionType getVersion() const
Get version of the field.
Definition EnumValue.h:304
static constexpr bool hasNonDefaultRefresh()
Compile time check if this class has non-default refresh functionality.
Definition EnumValue.h:297
bool valid() const
Check validity of the field value.
Definition EnumValue.h:278
void readNoStatus(TIter &iter)
Read field value from input data sequence without error check and status report.
Definition EnumValue.h:237
typename BaseImpl::CommsTag CommsTag
Tag indicating type of the field.
Definition EnumValue.h:94
void setValue(U &&val)
Set value.
Definition EnumValue.h:187
const ValueType & getValue() const
Get value.
Definition EnumValue.h:179
static constexpr bool hasReadNoStatus()
Compile time check of whether the field has proper readNoStatus() member function.
Definition EnumValue.h:226
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:413
TFieldBase FieldBase
Base class provided in the first template parameter.
Definition EnumValue.h:82
static constexpr bool hasFixedValue()
Compile time inquiry of whether comms::option::def::FixedValue option has been used.
Definition EnumValue.h:153
static constexpr bool hasIgnoreInvalid()
Compile time inquiry of whether comms::option::def::IgnoreInvalid option has been used.
Definition EnumValue.h:132
int getForcedLength() const
Get forced serialization length.
Definition EnumValue.h:330
ErrorStatus read(TIter &iter, std::size_t size)
Read field value from input data sequence.
Definition EnumValue.h:219
constexpr std::size_t length() const
Get length required to serialise the current field value.
Definition EnumValue.h:194
bool refresh()
Refresh the field's value.
Definition EnumValue.h:285
typename ParsedOptions::FieldType FieldType
Type of actual extending field specified via comms::option::def::FieldType.
Definition EnumValue.h:103
static constexpr bool hasWriteNoStatus()
Compile time check of whether the field has proper writeNoStatus() member function.
Definition EnumValue.h:261
static constexpr bool hasEmptySerialization()
Compile time inquiry of whether comms::option::def::EmptySerialization option has been used.
Definition EnumValue.h:139
EnumValue(const ValueType &val)
Constructor.
Definition EnumValue.h:109
ErrorStatus write(TIter &iter, std::size_t size) const
Write current field value to output data sequence.
Definition EnumValue.h:254
typename BaseImpl::ValueType ValueType
Type of underlying enum value.
Definition EnumValue.h:98
static constexpr bool isVersionDependent()
Compile time check if this class is version dependent.
Definition EnumValue.h:291
static constexpr bool hasFieldType()
Compile time inquiry of whether comms::option::def::FieldType option has been used.
Definition EnumValue.h:146
static constexpr std::size_t minLength()
Get minimal length that is required to serialise field of this type.
Definition EnumValue.h:201
~EnumValue() noexcept=default
Destructor.
void setForcedLength(int len)
Force serialization length of the field.
Definition EnumValue.h:323
details::OptionsParser< TOptions... > ParsedOptions
All the options provided to this class bundled into struct.
Definition EnumValue.h:91
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:387
bool canWrite() const
Check of whether the field has a consistent value for writing.
Definition EnumValue.h:243
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:437
static constexpr bool hasFailOnInvalid()
Compile time inquiry of whether comms::option::def::FailOnInvalid option has been used.
Definition EnumValue.h:125
static constexpr bool hasName()
Compile time inquiry of whether comms::option::def::HasName option has been used.
Definition EnumValue.h:160
typename BaseImpl::Endian Endian
Endian used for serialisation.
Definition EnumValue.h:85
bool setVersion(VersionType version)
Default implementation of version update.
Definition EnumValue.h:311
const ValueType & value() const
Get access to enum value storage.
Definition EnumValue.h:166
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
Contains definition of all the options used by the COMMS library.