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

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

Issue 1065653006: Array and map members for unions. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 5 years, 8 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 {%- import "validation_macros.tmpl" as validation_macros %} 1 {%- import "validation_macros.tmpl" as validation_macros %}
2 {%- set class_name = union.name ~ "_Data" %} 2 {%- set class_name = union.name ~ "_Data" %}
3 {%- set enum_name = union.name ~ "_Tag" -%} 3 {%- set enum_name = union.name ~ "_Tag" -%}
4 4
5 // static 5 // static
6 {{class_name}}* {{class_name}}::New(mojo::internal::Buffer* buf) { 6 {{class_name}}* {{class_name}}::New(mojo::internal::Buffer* buf) {
7 return new (buf->Allocate(sizeof({{class_name}}))) {{class_name}}(); 7 return new (buf->Allocate(sizeof({{class_name}}))) {{class_name}}();
8 } 8 }
9 9
10 // static 10 // static
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
50 size = 0U; 50 size = 0U;
51 tag = static_cast<{{enum_name}}>(0); 51 tag = static_cast<{{enum_name}}>(0);
52 data.unknown = 0U; 52 data.unknown = 0U;
53 } 53 }
54 54
55 {{class_name}}::{{class_name}}() { 55 {{class_name}}::{{class_name}}() {
56 } 56 }
57 57
58 void {{class_name}}::EncodePointersAndHandles( 58 void {{class_name}}::EncodePointersAndHandles(
59 std::vector<mojo::Handle>* handles) { 59 std::vector<mojo::Handle>* handles) {
60 // TODO(azani): Implement pointers and handles. 60 switch (tag) {
61 {%- for field in union.fields %}
62 case {{enum_name}}::{{field.name|upper}}: {
63 {%- if field.kind|is_object_kind and not field.kind|is_union_kind %}
64 mojo::internal::Encode(
65 reinterpret_cast<{{field.kind|cpp_field_type}}*>(&data),
yzshen1 2015/04/21 07:25:22 is it better to use &data.f_{{field.name}} instead
azani 2015/04/21 17:43:33 Maybe it's a bit more readable if we include the f
66 handles);
67 {%- elif field.kind|is_any_handle_kind %}
68 mojo::internal::EncodeHandle(&data.f_{{field.name}}, handles);
yzshen1 2015/04/21 07:25:23 wrong indent.
azani 2015/04/21 17:43:33 Done.
69 {%- endif %}
70 return;
71 }
72 {%- endfor %}
73 }
61 } 74 }
62 75
63 void {{class_name}}::DecodePointersAndHandles( 76 void {{class_name}}::DecodePointersAndHandles(
64 std::vector<mojo::Handle>* handles) { 77 std::vector<mojo::Handle>* handles) {
65 // TODO(azani): Implement pointers and handles. 78 switch (tag) {
79 {%- for field in union.fields %}
80 case {{enum_name}}::{{field.name|upper}}: {
81 {%- if field.kind|is_object_kind and not field.kind|is_union_kind %}
82 mojo::internal::Decode(
83 reinterpret_cast<{{field.kind|cpp_field_type}}*>(&data),
yzshen1 2015/04/21 07:25:22 is it better to use &data.f_{{field.name}} instead
azani 2015/04/21 17:43:33 Done.
84 handles);
85 {%- elif field.kind|is_any_handle_kind %}
86 mojo::internal::DecodeHandle(&data.f_{{field.name}}, handles);
87 {%- endif %}
88 return;
89 }
90 {%- endfor %}
91 }
66 } 92 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698