mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-10-23 17:13:33 +08:00
areClose(), isClose()
This commit is contained in:
@@ -107,13 +107,15 @@ struct UAVCAN_EXPORT ${t.cpp_type_name}
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
* Comparison operators are based on @ref uavcan::areClose(),
|
||||
* which allows to safely compare floating point values.
|
||||
*/
|
||||
bool operator==(ParameterType rhs) const;
|
||||
bool operator!=(ParameterType rhs) const { return !operator==(rhs); }
|
||||
|
||||
/**
|
||||
* This comparison is based on @ref uavcan::areClose(), which ensures proper comparison of
|
||||
* floating point fields at any depth.
|
||||
*/
|
||||
bool isClose(ParameterType rhs) const;
|
||||
|
||||
static int encode(ParameterType self, ::uavcan::ScalarCodec& codec,
|
||||
::uavcan::TailArrayOptimizationMode tao_mode = ::uavcan::TailArrayOptEnabled);
|
||||
|
||||
@@ -182,6 +184,20 @@ UAVCAN_PACKED_END
|
||||
|
||||
template <int _tmpl>
|
||||
bool ${scope_prefix}<_tmpl>::operator==(ParameterType rhs) const
|
||||
{
|
||||
% if fields:
|
||||
return
|
||||
% for idx,a in enumerate(fields):
|
||||
${a.name} == rhs.${a.name}${' &&' if (idx + 1) < len(fields) else ';'}
|
||||
% endfor
|
||||
% else:
|
||||
(void)rhs;
|
||||
return true;
|
||||
% endif
|
||||
}
|
||||
|
||||
template <int _tmpl>
|
||||
bool ${scope_prefix}<_tmpl>::isClose(ParameterType rhs) const
|
||||
{
|
||||
% if fields:
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user