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

Unified Diff: mojo/public/bindings/generators/cpp_templates/struct_builder_definition.tmpl

Issue 138143003: Support default values for POD struct fields in mojom IDL. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 6 years, 11 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
« no previous file with comments | « no previous file | mojo/public/bindings/generators/mojom_cpp_generator.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: mojo/public/bindings/generators/cpp_templates/struct_builder_definition.tmpl
diff --git a/mojo/public/bindings/generators/cpp_templates/struct_builder_definition.tmpl b/mojo/public/bindings/generators/cpp_templates/struct_builder_definition.tmpl
index d4e742786a57a1ba57f52cddc159701cc3b2a538..3841f4d912e4457261263ec275b142fcd9264933 100644
--- a/mojo/public/bindings/generators/cpp_templates/struct_builder_definition.tmpl
+++ b/mojo/public/bindings/generators/cpp_templates/struct_builder_definition.tmpl
@@ -6,8 +6,25 @@
{%- set _ = dtor_name.append("NULL") %}
{%- endif %}
+{%- macro set_default(field) -%}
+{%- if field.kind|is_string_kind -%}
+set_{{field.name}}(mojo::String({{field.default}}));
+{%- elif field.kind|is_object_kind -%}
+{
+ {{field.kind|cpp_wrapper_type}}::Builder tmp;
+ // TODO
+ set_{{field.name}}(tmp.Finish());
+}
+{%- else -%}
+set_{{field.name}}({{field.default}});
+{%- endif %}
+{%- endmacro %}
+
{{class_name}}::Builder::Builder(mojo::Buffer* buf)
: data_(Data::New(buf, {{dtor_name[0]}})) {
+{%- for pf in struct.packed.packed_fields if pf.field.default %}
+ {{set_default(pf.field)|indent(2)}}
darin (slow to review) 2014/01/21 23:47:20 Perhaps we should defer setting default values unt
+{%- endfor %}
}
{{class_name}} {{class_name}}::Builder::Finish() {
« no previous file with comments | « no previous file | mojo/public/bindings/generators/mojom_cpp_generator.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698