Skip to content

Commit

Permalink
unify braces in jinja templates
Browse files Browse the repository at this point in the history
  • Loading branch information
jpbusch committed Nov 27, 2024
1 parent 7d939ec commit cc46068
Show file tree
Hide file tree
Showing 7 changed files with 108 additions and 108 deletions.
12 changes: 6 additions & 6 deletions utils/codegen/codegen-py/templates/RosMessageType.msg.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -26,25 +26,25 @@

# --- ASN.1 Definition ---------------------------------------------------------
{% for line in asn1_definition.split('\n') -%}
# {{ line }}
# {{line}}
{% endfor -%}
# ------------------------------------------------------------------------------

{% for comment in comments -%}
# {{ comment }}
# {{comment}}
{% endfor -%}
{% for member in members -%}
{{ member.ros_msg_type }} {{ member.ros_field_name }}
{{member.ros_msg_type}} {{member.ros_field_name}}
{% if member.optional -%}
bool {{ member.ros_field_name }}_is_present
bool {{member.ros_field_name}}_is_present
{% endif -%}
{% if member.default -%}
{{ member.default.ros_msg_type }} {{ member.default.ros_field_name }} = {{ member.default.ros_value }}
{{member.default.ros_msg_type}} {{member.default.ros_field_name}} = {{member.default.ros_value}}
{% endif -%}
{% if member.has_bits_unused -%}
uint8 bits_unused
{% endif -%}
{% for const in member.constants -%}
{{ const.ros_msg_type }} {{ const.ros_field_name }} = {{ const.ros_value }}
{{const.ros_msg_type}} {{const.ros_field_name}} = {{const.ros_value}}
{% endfor %}
{% endfor -%}
32 changes: 16 additions & 16 deletions utils/codegen/codegen-py/templates/convertChoiceType.h.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -26,31 +26,31 @@ SOFTWARE.

#pragma once

#include <etsi_its_{{ etsi_type }}_coding/{{ etsi_type }}_{{ asn1_type_name }}.h>
#include <etsi_its_{{etsi_type}}_coding/{{etsi_type}}_{{asn1_type_name}}.h>
{% for member in unique_sorted_members -%}
{%- if member.ros_field_name != "choice" -%}
#include <etsi_its_{{ etsi_type }}_conversion/convert{{ member.ros_msg_type|replace("[]", "") }}.h>
#include <etsi_its_{{etsi_type}}_conversion/convert{{member.ros_msg_type|replace("[]", "")}}.h>
{% endif -%}
{%- endfor -%}
#ifdef ROS1
#include <etsi_its_{{ etsi_type }}_msgs/{{ ros_msg_type }}.h>
namespace {{ etsi_type }}_msgs = etsi_its_{{ etsi_type }}_msgs;
#include <etsi_its_{{etsi_type}}_msgs/{{ros_msg_type}}.h>
namespace {{etsi_type}}_msgs = etsi_its_{{etsi_type}}_msgs;
#else
#include <etsi_its_{{ etsi_type }}_msgs/msg/{{ ros2_msg_type_file_name }}.hpp>
namespace {{ etsi_type }}_msgs = etsi_its_{{ etsi_type }}_msgs::msg;
#include <etsi_its_{{etsi_type}}_msgs/msg/{{ros2_msg_type_file_name}}.hpp>
namespace {{etsi_type}}_msgs = etsi_its_{{etsi_type}}_msgs::msg;
#endif


namespace etsi_its_{{ etsi_type }}_conversion {
namespace etsi_its_{{etsi_type}}_conversion {

void toRos_{{ ros_msg_type }}(const {{ etsi_type }}_{{ asn1_type_name }}_t& in, {{ etsi_type}}_msgs::{{ ros_msg_type }}& out) {
void toRos_{{ros_msg_type}}(const {{etsi_type}}_{{asn1_type_name}}_t& in, {{etsi_type}}_msgs::{{ros_msg_type}}& out) {
switch (in.present) {
{%- for member in members %}
{%- if member.ros_field_name != "choice" -%}
{% for const in member.constants %}
case {{etsi_type}}_{{ asn1_type_name }}_PR_{{ member.c_field_name }}:
toRos_{{ member.ros_msg_type|replace("[]", "") }}(in.choice.{{ member.c_field_name }}, out.{{ member.ros_field_name }});
out.choice = {{ etsi_type}}_msgs::{{ ros_msg_type }}::{{ const.ros_field_name }};
case {{etsi_type}}_{{asn1_type_name}}_PR_{{member.c_field_name}}:
toRos_{{member.ros_msg_type|replace("[]", "")}}(in.choice.{{member.c_field_name}}, out.{{member.ros_field_name}});
out.choice = {{etsi_type}}_msgs::{{ros_msg_type}}::{{const.ros_field_name}};
break;
{%- endfor %}
{%- endif %}
Expand All @@ -59,16 +59,16 @@ void toRos_{{ ros_msg_type }}(const {{ etsi_type }}_{{ asn1_type_name }}_t& in,
}
}

void toStruct_{{ ros_msg_type }}(const {{ etsi_type}}_msgs::{{ ros_msg_type }}& in, {{ etsi_type }}_{{ asn1_type_name }}_t& out) {
memset(&out, 0, sizeof({{etsi_type}}_{{ asn1_type_name }}_t));
void toStruct_{{ros_msg_type}}(const {{etsi_type}}_msgs::{{ros_msg_type}}& in, {{etsi_type}}_{{asn1_type_name}}_t& out) {
memset(&out, 0, sizeof({{etsi_type}}_{{asn1_type_name}}_t));

switch (in.choice) {
{%- for member in members %}
{%- if member.ros_field_name != "choice" -%}
{% for const in member.constants %}
case {{ etsi_type }}_msgs::{{ ros_msg_type }}::{{ const.ros_field_name }}:
toStruct_{{ member.ros_msg_type|replace("[]", "") }}(in.{{ member.ros_field_name }}, out.choice.{{ member.c_field_name }});
out.present = {{etsi_type}}_{{ asn1_type_name }}_PR::{{etsi_type}}_{{ asn1_type_name }}_PR_{{ member.c_field_name }};
case {{etsi_type}}_msgs::{{ros_msg_type}}::{{const.ros_field_name}}:
toStruct_{{member.ros_msg_type|replace("[]", "")}}(in.{{member.ros_field_name}}, out.choice.{{member.c_field_name}});
out.present = {{etsi_type}}_{{asn1_type_name}}_PR::{{etsi_type}}_{{asn1_type_name}}_PR_{{member.c_field_name}};
break;
{%- endfor %}
{%- endif %}
Expand Down
24 changes: 12 additions & 12 deletions utils/codegen/codegen-py/templates/convertCustomType.h.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -26,31 +26,31 @@ SOFTWARE.

#pragma once

#include <etsi_its_{{ etsi_type }}_coding/{{ etsi_type }}_{{ asn1_type_name }}.h>
#include <etsi_its_{{etsi_type}}_coding/{{etsi_type}}_{{asn1_type_name}}.h>
{% for member in members -%}
#include <etsi_its_{{ etsi_type }}_conversion/convert{{ member.ros_msg_type }}.h>
#include <etsi_its_{{etsi_type}}_conversion/convert{{member.ros_msg_type}}.h>
{% endfor -%}
#ifdef ROS1
#include <etsi_its_{{ etsi_type }}_msgs/{{ ros_msg_type }}.h>
namespace {{ etsi_type }}_msgs = etsi_its_{{ etsi_type }}_msgs;
#include <etsi_its_{{etsi_type}}_msgs/{{ros_msg_type}}.h>
namespace {{etsi_type}}_msgs = etsi_its_{{etsi_type}}_msgs;
#else
#include <etsi_its_{{ etsi_type }}_msgs/msg/{{ ros2_msg_type_file_name }}.hpp>
namespace {{ etsi_type }}_msgs = etsi_its_{{ etsi_type }}_msgs::msg;
#include <etsi_its_{{etsi_type}}_msgs/msg/{{ros2_msg_type_file_name}}.hpp>
namespace {{etsi_type}}_msgs = etsi_its_{{etsi_type}}_msgs::msg;
#endif


namespace etsi_its_{{ etsi_type }}_conversion {
namespace etsi_its_{{etsi_type}}_conversion {

void toRos_{{ ros_msg_type }}(const {{ etsi_type }}_{{ asn1_type_name }}_t& in, {{ etsi_type}}_msgs::{{ ros_msg_type }}& out) {
void toRos_{{ros_msg_type}}(const {{etsi_type}}_{{asn1_type_name}}_t& in, {{etsi_type}}_msgs::{{ros_msg_type}}& out) {
{%- for member in members %}
toRos_{{ member.ros_msg_type }}(in, out.{{ member.c_field_name }});
toRos_{{member.ros_msg_type}}(in, out.{{member.c_field_name}});
{% endfor -%}
}

void toStruct_{{ ros_msg_type }}(const {{ etsi_type}}_msgs::{{ ros_msg_type }}& in, {{ etsi_type }}_{{ asn1_type_name }}_t& out) {
memset(&out, 0, sizeof({{ etsi_type}}_{{ asn1_type_name }}_t));
void toStruct_{{ros_msg_type}}(const {{etsi_type}}_msgs::{{ros_msg_type}}& in, {{etsi_type}}_{{asn1_type_name}}_t& out) {
memset(&out, 0, sizeof({{etsi_type}}_{{asn1_type_name}}_t));
{% for member in members %}
toStruct_{{ member.ros_msg_type }}(in.{{ member.ros_field_name }}, out);
toStruct_{{member.ros_msg_type}}(in.{{member.ros_field_name}}, out);
{% endfor -%}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,25 +26,25 @@ SOFTWARE.

#pragma once

#include <etsi_its_{{ etsi_type }}_coding/{{ etsi_type }}_{{ asn1_type_name }}.h>
#include <etsi_its_{{etsi_type}}_coding/{{etsi_type}}_{{asn1_type_name}}.h>

#ifdef ROS1
#include <etsi_its_{{ etsi_type }}_msgs/{{ ros_msg_type }}.h>
namespace {{ etsi_type }}_msgs = etsi_its_{{ etsi_type }}_msgs;
#include <etsi_its_{{etsi_type}}_msgs/{{ros_msg_type}}.h>
namespace {{etsi_type}}_msgs = etsi_its_{{etsi_type}}_msgs;
#else
#include <etsi_its_{{ etsi_type }}_msgs/msg/{{ ros2_msg_type_file_name }}.hpp>
namespace {{ etsi_type }}_msgs = etsi_its_{{ etsi_type }}_msgs::msg;
#include <etsi_its_{{etsi_type}}_msgs/msg/{{ros2_msg_type_file_name}}.hpp>
namespace {{etsi_type}}_msgs = etsi_its_{{etsi_type}}_msgs::msg;
#endif


namespace etsi_its_{{ etsi_type }}_conversion {
namespace etsi_its_{{etsi_type}}_conversion {

void toRos_{{ ros_msg_type }}(const {{ etsi_type }}_{{ asn1_type_name }}_t& in, {{ etsi_type}}_msgs::{{ ros_msg_type }}& out) {
void toRos_{{ros_msg_type}}(const {{etsi_type}}_{{asn1_type_name}}_t& in, {{etsi_type}}_msgs::{{ros_msg_type}}& out) {
out.value = in;
}

void toStruct_{{ ros_msg_type }}(const {{ etsi_type}}_msgs::{{ ros_msg_type }}& in, {{ etsi_type }}_{{ asn1_type_name }}_t& out) {
memset(&out, 0, sizeof({{etsi_type}}_{{ asn1_type_name }}_t));
void toStruct_{{ros_msg_type}}(const {{etsi_type}}_msgs::{{ros_msg_type}}& in, {{etsi_type}}_{{asn1_type_name}}_t& out) {
memset(&out, 0, sizeof({{etsi_type}}_{{asn1_type_name}}_t));

out = in.value;
}
Expand Down
26 changes: 13 additions & 13 deletions utils/codegen/codegen-py/templates/convertPrimitiveType.h.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -26,34 +26,34 @@ SOFTWARE.

#pragma once

#include <etsi_its_{{ etsi_type }}_coding/{{ etsi_type }}_{{ asn1_type_name }}.h>
#include <etsi_its_{{ etsi_type }}_coding/{{ asn1_type_type }}.h>
#include <etsi_its_primitives_conversion/convert{{ asn1_type_type }}.h>
#include <etsi_its_{{etsi_type}}_coding/{{etsi_type}}_{{asn1_type_name}}.h>
#include <etsi_its_{{etsi_type}}_coding/{{asn1_type_type}}.h>
#include <etsi_its_primitives_conversion/convert{{asn1_type_type}}.h>
#ifdef ROS1
#include <etsi_its_{{ etsi_type }}_msgs/{{ ros_msg_type }}.h>
namespace {{ etsi_type }}_msgs = etsi_its_{{ etsi_type }}_msgs;
#include <etsi_its_{{etsi_type}}_msgs/{{ros_msg_type}}.h>
namespace {{etsi_type}}_msgs = etsi_its_{{etsi_type}}_msgs;
#else
#include <etsi_its_{{ etsi_type }}_msgs/msg/{{ ros2_msg_type_file_name }}.hpp>
namespace {{ etsi_type }}_msgs = etsi_its_{{ etsi_type }}_msgs::msg;
#include <etsi_its_{{etsi_type}}_msgs/msg/{{ros2_msg_type_file_name}}.hpp>
namespace {{etsi_type}}_msgs = etsi_its_{{etsi_type}}_msgs::msg;
#endif


namespace etsi_its_{{ etsi_type }}_conversion {
namespace etsi_its_{{etsi_type}}_conversion {

void toRos_{{ ros_msg_type }}(const {{etsi_type}}_{{ asn1_type_name|replace("-", "_") }}_t& in, {{ etsi_type}}_msgs::{{ ros_msg_type }}& out) {
void toRos_{{ros_msg_type}}(const {{etsi_type}}_{{asn1_type_name|replace("-", "_")}}_t& in, {{etsi_type}}_msgs::{{ros_msg_type}}& out) {
{%- for member in members %}
etsi_its_primitives_conversion::toRos_{{ asn1_type_type }}(in, out.{{ member.ros_field_name }});
etsi_its_primitives_conversion::toRos_{{asn1_type_type}}(in, out.{{member.ros_field_name}});
{%- if member.has_bits_unused %}
out.bits_unused = in.bits_unused;
{%- endif %}
{%- endfor %}
}

void toStruct_{{ ros_msg_type }}(const {{ etsi_type}}_msgs::{{ ros_msg_type }}& in, {{ etsi_type}}_{{ asn1_type_name|replace("-", "_") }}_t& out) {
void toStruct_{{ros_msg_type}}(const {{etsi_type}}_msgs::{{ros_msg_type}}& in, {{etsi_type}}_{{asn1_type_name|replace("-", "_")}}_t& out) {
{%- for member in members %}
memset(&out, 0, sizeof({{ etsi_type}}_{{ asn1_type_name|replace("-", "_") }}_t));
memset(&out, 0, sizeof({{etsi_type}}_{{asn1_type_name|replace("-", "_")}}_t));

etsi_its_primitives_conversion::toStruct_{{ asn1_type_type }}(in.{{ member.ros_field_name }}, out);
etsi_its_primitives_conversion::toStruct_{{asn1_type_type}}(in.{{member.ros_field_name}}, out);
{%- if member.has_bits_unused %}
out.bits_unused = in.bits_unused;
{%- endif %}
Expand Down
36 changes: 18 additions & 18 deletions utils/codegen/codegen-py/templates/convertSequenceOfType.h.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -28,45 +28,45 @@ SOFTWARE.

#include <stdexcept>

#include <etsi_its_{{ etsi_type }}_coding/asn_SEQUENCE_OF.h>
#include <etsi_its_{{ etsi_type }}_coding/{{ etsi_type }}_{{ asn1_type_name }}.h>
#include <etsi_its_{{etsi_type}}_coding/asn_SEQUENCE_OF.h>
#include <etsi_its_{{etsi_type}}_coding/{{etsi_type}}_{{asn1_type_name}}.h>
{% for member in members -%}
#include <etsi_its_{{ etsi_type }}_coding/{{etsi_type}}_{{ member.ros_msg_type|replace("[]", "") }}.h>
#include <etsi_its_{{ etsi_type }}_conversion/convert{{ member.ros_msg_type|replace("[]", "") }}.h>
#include <etsi_its_{{etsi_type}}_coding/{{etsi_type}}_{{member.ros_msg_type|replace("[]", "")}}.h>
#include <etsi_its_{{etsi_type}}_conversion/convert{{member.ros_msg_type|replace("[]", "")}}.h>
{% endfor -%}
#ifdef ROS1
{% for member in members -%}
#include <etsi_its_{{ etsi_type }}_msgs/{{ member.ros_msg_type|replace("[]", "") }}.h>
#include <etsi_its_{{etsi_type}}_msgs/{{member.ros_msg_type|replace("[]", "")}}.h>
{% endfor -%}
#include <etsi_its_{{ etsi_type }}_msgs/{{ ros_msg_type }}.h>
namespace {{ etsi_type }}_msgs = etsi_its_{{ etsi_type }}_msgs;
#include <etsi_its_{{etsi_type}}_msgs/{{ros_msg_type}}.h>
namespace {{etsi_type}}_msgs = etsi_its_{{etsi_type}}_msgs;
#else
{% for member in members -%}
#include <etsi_its_{{ etsi_type }}_msgs/msg/{{ member.ros2_msg_type_file_name }}.hpp>
#include <etsi_its_{{etsi_type}}_msgs/msg/{{member.ros2_msg_type_file_name}}.hpp>
{% endfor -%}
#include <etsi_its_{{ etsi_type }}_msgs/msg/{{ ros2_msg_type_file_name }}.hpp>
namespace {{ etsi_type }}_msgs = etsi_its_{{ etsi_type }}_msgs::msg;
#include <etsi_its_{{etsi_type}}_msgs/msg/{{ros2_msg_type_file_name}}.hpp>
namespace {{etsi_type}}_msgs = etsi_its_{{etsi_type}}_msgs::msg;
#endif


namespace etsi_its_{{ etsi_type }}_conversion {
namespace etsi_its_{{etsi_type}}_conversion {

void toRos_{{ ros_msg_type }}(const {{ etsi_type }}_{{ asn1_type_name }}_t& in, {{ etsi_type}}_msgs::{{ ros_msg_type }}& out) {
void toRos_{{ros_msg_type}}(const {{etsi_type}}_{{asn1_type_name}}_t& in, {{etsi_type}}_msgs::{{ros_msg_type}}& out) {
{%- for member in members %}
for (int i = 0; i < in.list.count; ++i) {
{{ etsi_type}}_msgs::{{ member.ros_msg_type|replace("[]", "") }} el;
toRos_{{ member.ros_msg_type|replace("[]", "") }}(*(in.list.array[i]), el);
{{etsi_type}}_msgs::{{member.ros_msg_type|replace("[]", "")}} el;
toRos_{{member.ros_msg_type|replace("[]", "")}}(*(in.list.array[i]), el);
out.array.push_back(el);
}
{% endfor -%}
}

void toStruct_{{ ros_msg_type }}(const {{ etsi_type}}_msgs::{{ ros_msg_type }}& in, {{ etsi_type }}_{{ asn1_type_name }}_t& out) {
memset(&out, 0, sizeof({{etsi_type}}_{{ asn1_type_name }}_t));
void toStruct_{{ros_msg_type}}(const {{etsi_type}}_msgs::{{ros_msg_type}}& in, {{etsi_type}}_{{asn1_type_name}}_t& out) {
memset(&out, 0, sizeof({{etsi_type}}_{{asn1_type_name}}_t));
{% for member in members %}
for (int i = 0; i < in.array.size(); ++i) {
{{etsi_type}}_{{ member.ros_msg_type|replace("[]", "") }}_t* el = ({{etsi_type}}_{{ member.ros_msg_type|replace("[]", "") }}_t*) calloc(1, sizeof({{etsi_type}}_{{ member.ros_msg_type|replace("[]", "") }}_t));
toStruct_{{ member.ros_msg_type|replace("[]", "") }}(in.array[i], *el);
{{etsi_type}}_{{member.ros_msg_type|replace("[]", "")}}_t* el = ({{etsi_type}}_{{member.ros_msg_type|replace("[]", "")}}_t*) calloc(1, sizeof({{etsi_type}}_{{member.ros_msg_type|replace("[]", "")}}_t));
toStruct_{{member.ros_msg_type|replace("[]", "")}}(in.array[i], *el);
if (asn_sequence_add(&out, el)) throw std::invalid_argument("Failed to add to A_SEQUENCE_OF");
}
{%- endfor %}
Expand Down
Loading

0 comments on commit cc46068

Please sign in to comment.