14#include "comms/util/SizeToType.h"
26template <
typename TFieldBase,
typename T>
27class FloatValue :
public TFieldBase
29 static_assert(std::is_floating_point<T>::value,
"T must be floating point value");
31 using BaseImpl = TFieldBase;
35 using SerialisedType =
typename comms::util::SizeToType<
sizeof(ValueType),
false>::Type;
37 using CommsTag = comms::field::tag::Float;
39 FloatValue() =
default;
41 explicit FloatValue(ValueType val)
46 FloatValue(
const FloatValue&) =
default;
47 FloatValue(FloatValue&&) =
default;
48 ~FloatValue() noexcept = default;
50 FloatValue& operator=(const FloatValue&) = default;
51 FloatValue& operator=(FloatValue&&) = default;
53 const ValueType& value()
const
63 const ValueType& getValue()
const
69 void setValue(U&& val)
71 value() =
static_cast<ValueType
>(std::forward<U>(val));
74 static constexpr std::size_t length()
76 return sizeof(SerialisedType);
79 static constexpr std::size_t minLength()
84 static constexpr std::size_t maxLength()
89 static SerialisedType toSerialised(ValueType val)
91 CastUnion<> castUnion;
92 castUnion.value_ = val;
93 return castUnion.serValue_;
96 static ValueType fromSerialised(SerialisedType val)
98 CastUnion<> castUnion;
99 castUnion.serValue_ = val;
100 return castUnion.value_;
103 template <
typename TIter>
106 if (size < length()) {
114 template <
typename TIter>
115 void readNoStatus(TIter& iter)
117 auto serialisedValue =
118 BaseImpl::template readData<SerialisedType>(iter);
119 value_ = fromSerialised(serialisedValue);
122 template <
typename TIter>
123 ErrorStatus write(TIter& iter, std::size_t size)
const
125 if (size < length()) {
133 template <
typename TIter>
134 void writeNoStatus(TIter& iter)
const
136 BaseImpl::writeData(toSerialised(value_), iter);
140 template<
typename...>
144 SerialisedType serValue_;
147 ValueType 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: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.