mirror of
https://gitee.com/mirrors_PX4/PX4-Autopilot.git
synced 2026-10-23 05:13:34 +08:00
dsdlc: Union comparison operators
This commit is contained in:
@@ -181,33 +181,63 @@ private:
|
|||||||
/*
|
/*
|
||||||
* Out of line struct method definitions
|
* Out of line struct method definitions
|
||||||
*/
|
*/
|
||||||
<!--(macro define_out_of_line_struct_methods)--> #! scope_prefix, fields
|
<!--(macro define_out_of_line_struct_methods)--> #! scope_prefix, fields, union
|
||||||
|
|
||||||
template <int _tmpl>
|
template <int _tmpl>
|
||||||
bool ${scope_prefix}<_tmpl>::operator==(ParameterType rhs) const
|
bool ${scope_prefix}<_tmpl>::operator==(ParameterType rhs) const
|
||||||
{
|
{
|
||||||
% if fields:
|
% if union:
|
||||||
return
|
if (_tag_ != rhs._tag_)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
% for idx,a in enumerate(fields):
|
% for idx,a in enumerate(fields):
|
||||||
${a.name} == rhs.${a.name}${' &&' if (idx + 1) < len(fields) else ';'}
|
if (_tag_ == ${idx})
|
||||||
|
{
|
||||||
|
return ${a.name} == rhs.${a.name};
|
||||||
|
}
|
||||||
% endfor
|
% endfor
|
||||||
|
UAVCAN_ASSERT(0); // Invalid tag
|
||||||
|
return false;
|
||||||
% else:
|
% else:
|
||||||
|
% if fields:
|
||||||
|
return
|
||||||
|
% for idx,a in enumerate(fields):
|
||||||
|
${a.name} == rhs.${a.name}${' &&' if (idx + 1) < len(fields) else ';'}
|
||||||
|
% endfor
|
||||||
|
% else:
|
||||||
(void)rhs;
|
(void)rhs;
|
||||||
return true;
|
return true;
|
||||||
|
% endif
|
||||||
% endif
|
% endif
|
||||||
}
|
}
|
||||||
|
|
||||||
template <int _tmpl>
|
template <int _tmpl>
|
||||||
bool ${scope_prefix}<_tmpl>::isClose(ParameterType rhs) const
|
bool ${scope_prefix}<_tmpl>::isClose(ParameterType rhs) const
|
||||||
{
|
{
|
||||||
% if fields:
|
% if union:
|
||||||
return
|
if (_tag_ != rhs._tag_)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
% for idx,a in enumerate(fields):
|
% for idx,a in enumerate(fields):
|
||||||
::uavcan::areClose(${a.name}, rhs.${a.name})${' &&' if (idx + 1) < len(fields) else ';'}
|
if (_tag_ == ${idx})
|
||||||
|
{
|
||||||
|
return ::uavcan::areClose(${a.name}, rhs.${a.name});
|
||||||
|
}
|
||||||
% endfor
|
% endfor
|
||||||
|
UAVCAN_ASSERT(0); // Invalid tag
|
||||||
|
return false;
|
||||||
% else:
|
% else:
|
||||||
|
% if fields:
|
||||||
|
return
|
||||||
|
% for idx,a in enumerate(fields):
|
||||||
|
::uavcan::areClose(${a.name}, rhs.${a.name})${' &&' if (idx + 1) < len(fields) else ';'}
|
||||||
|
% endfor
|
||||||
|
% else:
|
||||||
(void)rhs;
|
(void)rhs;
|
||||||
return true;
|
return true;
|
||||||
|
% endif
|
||||||
% endif
|
% endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -238,10 +268,10 @@ ${generate_codec_calls_per_field(call_name='decode', self_parameter_type='Refere
|
|||||||
<!--(end)-->
|
<!--(end)-->
|
||||||
|
|
||||||
% if t.kind == t.KIND_SERVICE:
|
% if t.kind == t.KIND_SERVICE:
|
||||||
${define_out_of_line_struct_methods(scope_prefix=t.cpp_type_name + '::Request_', fields=t.request_fields)}
|
${define_out_of_line_struct_methods(scope_prefix=t.cpp_type_name + '::Request_', fields=t.request_fields, union=t.request_union)}
|
||||||
${define_out_of_line_struct_methods(scope_prefix=t.cpp_type_name + '::Response_', fields=t.response_fields)}
|
${define_out_of_line_struct_methods(scope_prefix=t.cpp_type_name + '::Response_', fields=t.response_fields, union=t.response_union)}
|
||||||
% else:
|
% else:
|
||||||
${define_out_of_line_struct_methods(scope_prefix=t.cpp_type_name, fields=t.fields)}
|
${define_out_of_line_struct_methods(scope_prefix=t.cpp_type_name, fields=t.fields, union=t.union)}
|
||||||
% endif
|
% endif
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|||||||
Reference in New Issue
Block a user