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

Side by Side Diff: mojo/public/tools/bindings/generators/cpp_templates/struct_declaration.tmpl

Issue 2247083003: Mojo C++ bindings: extract code shared by different variants. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: . Created 4 years, 4 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 unified diff | Download patch
OLDNEW
1 {%- set class_name = struct.name ~ "_Data" -%} 1 {%- set class_name = struct.name ~ "_Data" -%}
2 2
3 class {{class_name}} { 3 class {{class_name}} {
4 public: 4 public:
5 static {{class_name}}* New(mojo::internal::Buffer* buf) { 5 static {{class_name}}* New(mojo::internal::Buffer* buf) {
6 return new (buf->Allocate(sizeof({{class_name}}))) {{class_name}}(); 6 return new (buf->Allocate(sizeof({{class_name}}))) {{class_name}}();
7 } 7 }
8 8
9 static bool Validate(const void* data, 9 static bool Validate(const void* data,
10 mojo::internal::ValidationContext* validation_context); 10 mojo::internal::ValidationContext* validation_context);
11 11
12 {% from "enum_macros.tmpl" import enum_data_decl -%}
13 {#--- Enums #}
14 {%- for enum in struct.enums -%}
15 {%- if enum|is_native_only_kind %}
16 using {{enum.name}}_Data = mojo::internal::NativeEnum_Data;
17 {%- else %}
18 {{enum_data_decl(enum)|indent(2)}}
19 {%- endif %}
20 {%- endfor %}
21
22 mojo::internal::StructHeader header_; 12 mojo::internal::StructHeader header_;
23 {%- for packed_field in struct.packed.packed_fields %} 13 {%- for packed_field in struct.packed.packed_fields %}
24 {%- set name = packed_field.field.name %} 14 {%- set name = packed_field.field.name %}
25 {%- set kind = packed_field.field.kind %} 15 {%- set kind = packed_field.field.kind %}
26 {%- if kind.spec == 'b' %} 16 {%- if kind.spec == 'b' %}
27 uint8_t {{name}} : 1; 17 uint8_t {{name}} : 1;
28 {%- else %} 18 {%- else %}
29 {{kind|cpp_field_type}} {{name}}; 19 {{kind|cpp_field_type}} {{name}};
30 {%- endif %} 20 {%- endif %}
31 {%- if not loop.last %} 21 {%- if not loop.last %}
(...skipping 15 matching lines...) Expand all
47 {%- endif %} 37 {%- endif %}
48 {%- endif %} 38 {%- endif %}
49 39
50 private: 40 private:
51 {{class_name}}() : header_({sizeof(*this), {{struct.versions[-1].version}}}) { 41 {{class_name}}() : header_({sizeof(*this), {{struct.versions[-1].version}}}) {
52 } 42 }
53 ~{{class_name}}() = delete; 43 ~{{class_name}}() = delete;
54 }; 44 };
55 static_assert(sizeof({{class_name}}) == {{struct.versions[-1].num_bytes}}, 45 static_assert(sizeof({{class_name}}) == {{struct.versions[-1].num_bytes}},
56 "Bad sizeof({{class_name}})"); 46 "Bad sizeof({{class_name}})");
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698