26template <
typename TFieldBase,
typename T>
27class EnumValue :
public TFieldBase
29 static_assert(std::is_enum<T>::value,
"T must be enum");
31 using UnderlyingType =
typename std::underlying_type<T>::type;
33 using BaseImpl = TFieldBase;
41 using IntValueType =
typename IntValueField::ValueType;
46 using SerialisedType =
typename IntValueField::ValueType;
48 using ScalingRatio =
typename IntValueField::ScalingRatio;
50 using CommsTag = comms::field::tag::Enum;
52 EnumValue() =
default;
54 explicit EnumValue(ValueType val)
59 EnumValue(
const EnumValue&) =
default;
60 EnumValue(EnumValue&&) =
default;
61 ~EnumValue() noexcept = default;
63 EnumValue& operator=(const EnumValue&) = default;
64 EnumValue& operator=(EnumValue&&) = default;
66 const ValueType& value()
const
76 const ValueType& getValue()
const
82 void setValue(U&& val)
84 value() =
static_cast<ValueType
>(std::forward<U>(val));
87 static constexpr std::size_t length()
89 return IntValueField::length();
92 static constexpr std::size_t minLength()
97 static constexpr std::size_t maxLength()
102 static constexpr SerialisedType toSerialised(ValueType val)
104 return IntValueField::toSerialised(
static_cast<IntValueType
>(val));
107 static constexpr ValueType fromSerialised(SerialisedType val)
109 return static_cast<ValueType
>(IntValueField::fromSerialised(val));
112 template <
typename TIter>
115 IntValueField intField;
116 auto es = intField.read(iter, size);
118 value_ =
static_cast<decltype(value_)
>(intField.value());
123 template <
typename TIter>
124 void readNoStatus(TIter& iter)
126 IntValueField intField;
127 intField.readNoStatus(iter);
128 value_ =
static_cast<decltype(value_)
>(intField.value());
131 template <
typename TIter>
132 ErrorStatus write(TIter& iter, std::size_t size)
const
134 return IntValueField(
static_cast<IntValueType
>(value_)).write(iter, size);
137 template <
typename TIter>
138 void writeNoStatus(TIter& iter)
const
140 IntValueField(
static_cast<IntValueType
>(value_)).writeNoStatus(iter);
144 ValueType value_ =
static_cast<ValueType
>(0);
This file contain definition of error statuses used by comms module.
Contains definition of comms::field::IntValue.
Contains definition of various tag classes.
comms::option::def::ScalingRatio< TNum, TDenom > ScalingRatio
Same as comms::option::def::ScalingRatio.
Definition options.h:1504
Main namespace for all classes / functions of COMMS library.
ErrorStatus
Error statuses reported by the Communication module.
Definition ErrorStatus.h:17
@ Success
Used to indicate successful outcome of the operation.