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

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

Issue 1375313006: For c++, Generate enum classes instead of enum from mojom. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 5 years, 2 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 {# TODO(yzshen): Make these templates more readable. #} 1 {# TODO(yzshen): Make these templates more readable. #}
2 2
3 {# Computes the serialized size for the specified struct. 3 {# Computes the serialized size for the specified struct.
4 |struct| is the struct definition. 4 |struct| is the struct definition.
5 |input_field_pattern| should be a pattern that contains one string 5 |input_field_pattern| should be a pattern that contains one string
6 placeholder, for example, "input->%s", "p_%s". The placeholder will be 6 placeholder, for example, "input->%s", "p_%s". The placeholder will be
7 substituted with struct field names to refer to the input fields. 7 substituted with struct field names to refer to the input fields.
8 This macro is expanded to compute seriailized size for both: 8 This macro is expanded to compute seriailized size for both:
9 - user-defined structs: the input is an instance of the corresponding struct 9 - user-defined structs: the input is an instance of the corresponding struct
10 wrapper class. 10 wrapper class.
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
88 {%- if not kind|is_nullable_kind %} 88 {%- if not kind|is_nullable_kind %}
89 MOJO_INTERNAL_DLOG_SERIALIZATION_WARNING( 89 MOJO_INTERNAL_DLOG_SERIALIZATION_WARNING(
90 {%- if kind|is_interface_kind %} 90 {%- if kind|is_interface_kind %}
91 !{{output}}->{{name}}.handle.is_valid(), 91 !{{output}}->{{name}}.handle.is_valid(),
92 {%- else %} 92 {%- else %}
93 !{{output}}->{{name}}.is_valid(), 93 !{{output}}->{{name}}.is_valid(),
94 {%- endif %} 94 {%- endif %}
95 mojo::internal::VALIDATION_ERROR_UNEXPECTED_INVALID_HANDLE, 95 mojo::internal::VALIDATION_ERROR_UNEXPECTED_INVALID_HANDLE,
96 "invalid {{name}} in {{struct_display_name}}"); 96 "invalid {{name}} in {{struct_display_name}}");
97 {%- endif %} 97 {%- endif %}
98 {%- elif kind|is_enum_kind %}
99 {{output}}->{{name}} =
100 static_cast<int32_t>({{input_field}});
98 {%- else %} 101 {%- else %}
99 {{output}}->{{name}} = {{input_field}}; 102 {{output}}->{{name}} = {{input_field}};
100 {%- endif %} 103 {%- endif %}
101 {%- endfor %} 104 {%- endfor %}
102 {%- endmacro -%} 105 {%- endmacro -%}
103 106
104 {# Deserializes the specified struct. 107 {# Deserializes the specified struct.
105 |struct| is the struct definition. 108 |struct| is the struct definition.
106 |input| is the name of the input struct instance. 109 |input| is the name of the input struct instance.
107 |output_field_pattern| should be a pattern that contains one string 110 |output_field_pattern| should be a pattern that contains one string
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
150 {%- elif kind|is_any_handle_kind %} 153 {%- elif kind|is_any_handle_kind %}
151 {{output_field}}.reset(mojo::internal::FetchAndReset(&{{input}}->{{name}})); 154 {{output_field}}.reset(mojo::internal::FetchAndReset(&{{input}}->{{name}}));
152 {%- elif kind|is_enum_kind %} 155 {%- elif kind|is_enum_kind %}
153 {{output_field}} = static_cast<{{kind|cpp_wrapper_type}}>({{input}}->{{name} }); 156 {{output_field}} = static_cast<{{kind|cpp_wrapper_type}}>({{input}}->{{name} });
154 {%- else %} 157 {%- else %}
155 {{output_field}} = {{input}}->{{name}}; 158 {{output_field}} = {{input}}->{{name}};
156 {%- endif %} 159 {%- endif %}
157 {%- endfor %} 160 {%- endfor %}
158 } while (false); 161 } while (false);
159 {%- endmacro %} 162 {%- endmacro %}
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698