14#include "comms/util/SizeToType.h"
30template <
typename TFieldBase,
typename T>
31class FloatValue :
public TFieldBase
33 static_assert(std::is_floating_point<T>::value,
"T must be floating point value");
35 using BaseImpl = TFieldBase;
39 using SerialisedType =
typename comms::util::SizeToType<
sizeof(ValueType),
false>::Type;
41 using CommsTag = comms::field::tag::Float;
43 FloatValue() =
default;
45 explicit FloatValue(ValueType val)
50 FloatValue(
const FloatValue&) =
default;
51 FloatValue(FloatValue&&) =
default;
52 ~FloatValue() noexcept = default;
54 FloatValue& operator=(const FloatValue&) = default;
55 FloatValue& operator=(FloatValue&&) = default;
57 const ValueType& value()
const
67 const ValueType& getValue()
const
73 void setValue(U&& val)
75 value() =
static_cast<ValueType
>(std::forward<U>(val));
78 static constexpr std::size_t length()
80 return sizeof(SerialisedType);
83 static constexpr std::size_t minLength()
88 static constexpr std::size_t maxLength()
93 static SerialisedType toSerialised(ValueType val)
95 CastUnion<> castUnion;
96 castUnion.m_value = val;
97 return castUnion.m_serValue;
100 static ValueType fromSerialised(SerialisedType val)
102 CastUnion<> castUnion;
103 castUnion.m_serValue = val;
104 return castUnion.m_value;
107 template <
typename TIter>
110 if (size < length()) {
118 template <
typename TIter>
119 void readNoStatus(TIter& iter)
121 auto serialisedValue =
122 BaseImpl::template readData<SerialisedType>(iter);
123 m_value = fromSerialised(serialisedValue);
126 template <
typename TIter>
127 ErrorStatus write(TIter& iter, std::size_t size)
const
129 if (size < length()) {
137 template <
typename TIter>
138 void writeNoStatus(TIter& iter)
const
140 BaseImpl::writeData(toSerialised(m_value), iter);
144 template<
typename...>
148 SerialisedType m_serValue;
151 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:1557
Main namespace for all classes / functions of COMMS library.
ErrorStatus
Error statuses reported by the Communication module.
Definition ErrorStatus.h:19
@ Success
Used to indicate successful outcome of the operation.