Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(432)

Unified Diff: mojo/public/tools/bindings/generators/cpp_templates/struct_macros.tmpl

Issue 294833002: Mojo: more idiomatic C++ bindings (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix windows bustage Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: mojo/public/tools/bindings/generators/cpp_templates/struct_macros.tmpl
diff --git a/mojo/public/tools/bindings/generators/cpp_templates/struct_macros.tmpl b/mojo/public/tools/bindings/generators/cpp_templates/struct_macros.tmpl
index 106a18d8c99a5c6bf4db8370f1728921d44363e4..96be82fc0663766436b5e9dd0cc9d98fd1c70f2b 100644
--- a/mojo/public/tools/bindings/generators/cpp_templates/struct_macros.tmpl
+++ b/mojo/public/tools/bindings/generators/cpp_templates/struct_macros.tmpl
@@ -1,40 +1,12 @@
-{%- macro setters(struct) %}
-{% for packed_field in struct.packed.packed_fields %}
-{%- set type = packed_field.field.kind|cpp_type %}
-{%- set name = packed_field.field.name %}
-{%- if packed_field.field.kind|is_object_kind %}
- void set_{{name}}({{type}} {{name}}) { {{name}}_.ptr = {{name}}; }
-{%- else %}
- void set_{{name}}({{type}} {{name}}) { {{name}}_ = {{name}}; }
-{%- endif %}
-{%- endfor %}
-{%- endmacro %}
-
-{%- macro getters(struct) %}
-{% for packed_field in struct.packed.packed_fields %}
-{%- set type = packed_field.field.kind|cpp_type %}
-{%- set name = packed_field.field.name %}
-{%- if packed_field.field.kind|is_object_kind %}
- const {{type}} {{name}}() const { return {{name}}_.ptr; }
-{%- elif packed_field.field.kind|is_handle_kind %}
- {{type}}* {{name}}() const { return &{{name}}_; }
-{%- else %}
- {{type}} {{name}}() const { return {{name}}_; }
-{%- endif %}
-{%- endfor %}
-{%- endmacro %}
-
{%- macro field_line(field) %}
{%- set type = field.kind|cpp_field_type %}
{%- set name = field.name -%}
{%- if field.kind.spec == 'b' -%}
- uint8_t {{name}}_ : 1;
-{%- elif field.kind|is_handle_kind -%}
- mutable {{type}} {{name}}_;
+ uint8_t {{name}} : 1;
{%- elif field.kind|is_enum_kind -%}
- int32_t {{name}}_;
+ int32_t {{name}};
{%- else -%}
- {{type}} {{name}}_;
+ {{type}} {{name}};
{%- endif %}
{%- endmacro %}
@@ -45,7 +17,7 @@
{%- set next_pf = struct.packed.packed_fields[loop.index0 + 1] %}
{%- set pad = next_pf.offset - (packed_field.offset + packed_field.size) %}
{%- if pad > 0 %}
- uint8_t _pad{{loop.index0}}_[{{pad}}];
+ uint8_t pad{{loop.index0}}_[{{pad}}];
{%- endif %}
{%- endif %}
{%- endfor -%}
@@ -56,27 +28,27 @@
{%- set offset = last_field.offset + last_field.size %}
{%- set pad = offset|get_pad(8) -%}
{%- if pad > 0 %}
- uint8_t _padfinal_[{{pad}}];
+ uint8_t padfinal_[{{pad}}];
{%- endif %}
{%- endif %}
{%- endmacro %}
{%- macro encodes(struct) -%}
{%- for pf in struct.packed.packed_fields if pf.field.kind|is_object_kind -%}
-mojo::internal::Encode(&{{pf.field.name}}_, handles);
+mojo::internal::Encode(&{{pf.field.name}}, handles);
{% endfor %}
{%- for pf in struct.packed.packed_fields if pf.field.kind|is_handle_kind -%}
-mojo::internal::EncodeHandle(&{{pf.field.name}}_, handles);
+mojo::internal::EncodeHandle(&{{pf.field.name}}, handles);
{% endfor %}
{%- endmacro -%}
{%- macro decodes(struct) -%}
{%- for pf in struct.packed.packed_fields if pf.field.kind|is_object_kind -%}
-if (!mojo::internal::Decode(&{{pf.field.name}}_, message))
+if (!mojo::internal::Decode(&{{pf.field.name}}, message))
return false;
{% endfor %}
{%- for pf in struct.packed.packed_fields if pf.field.kind|is_handle_kind -%}
-if (!mojo::internal::DecodeHandle(&{{pf.field.name}}_,
+if (!mojo::internal::DecodeHandle(&{{pf.field.name}},
message->mutable_handles()))
return false;
{% endfor %}

Powered by Google App Engine
This is Rietveld 408576698