12#include "comms/util/SizeToType.h"
27template <
typename TFieldBase,
typename T>
28class FloatValue :
public TFieldBase
30 static_assert(std::is_floating_point<T>::value,
"T must be floating point value");
32 using BaseImpl = TFieldBase;
36 using SerialisedType =
typename comms::util::SizeToType<
sizeof(ValueType),
false>::Type;
38 using CommsTag = comms::field::tag::Float;
40 FloatValue() =
default;
42 explicit FloatValue(ValueType val)
47 FloatValue(
const FloatValue&) =
default;
48 FloatValue(FloatValue&&) =
default;
49 ~FloatValue() noexcept = default;
51 FloatValue& operator=(const FloatValue&) = default;
52 FloatValue& operator=(FloatValue&&) = default;
54 const ValueType& value()
const
64 const ValueType& getValue()
const
70 void setValue(U&& val)
72 value() =
static_cast<ValueType
>(std::forward<U>(val));
75 static constexpr std::size_t length()
77 return sizeof(SerialisedType);
80 static constexpr std::size_t minLength()
85 static constexpr std::size_t maxLength()
90 static SerialisedType toSerialised(ValueType val)
92 CastUnion<> castUnion;
93 castUnion.m_value = val;
94 return castUnion.m_serValue;
97 static ValueType fromSerialised(SerialisedType val)
99 CastUnion<> castUnion;
100 castUnion.m_serValue = val;
101 return castUnion.m_value;
104 template <
typename TIter>
107 if (size < length()) {
115 template <
typename TIter>
116 void readNoStatus(TIter& iter)
118 auto serialisedValue =
119 BaseImpl::template readData<SerialisedType>(iter);
120 m_value = fromSerialised(serialisedValue);
123 template <
typename TIter>
124 ErrorStatus write(TIter& iter, std::size_t size)
const
126 if (size < length()) {
134 template <
typename TIter>
135 void writeNoStatus(TIter& iter)
const
137 BaseImpl::writeData(toSerialised(m_value), iter);
141 template<
typename...>
145 SerialisedType m_serValue;
148 ValueType m_value =
static_cast<ValueType
>(0.0);
This file contain definition of error statuses used by comms module.
Contains definition of various tag classes.
comms::option::def::ScalingRatio< TNum, TDenom > ScalingRatio
Same as comms::option::def::ScalingRatio.
Definition options.h:1544
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.