dsdlc: Union comparison operators

This commit is contained in:
Pavel Kirienko
2015-07-10 14:53:21 +03:00
parent 9fb7497add
commit ef8919942e
@@ -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
/* /*