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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | mojo/public/bindings/generators/mojom_cpp_generator.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 {%- set class_name = struct.name -%} 1 {%- set class_name = struct.name -%}
2 {%- set dtor_name = [] %} 2 {%- set dtor_name = [] %}
3 {%- if struct|is_struct_with_handles %} 3 {%- if struct|is_struct_with_handles %}
4 {%- set _ = dtor_name.append("&internal::%s_Data_Destructor"|format(struct.nam e)) %} 4 {%- set _ = dtor_name.append("&internal::%s_Data_Destructor"|format(struct.nam e)) %}
5 {%- else %} 5 {%- else %}
6 {%- set _ = dtor_name.append("NULL") %} 6 {%- set _ = dtor_name.append("NULL") %}
7 {%- endif %} 7 {%- endif %}
8 8
9 {%- macro set_default(field) -%}
10 {%- if field.kind|is_string_kind -%}
11 set_{{field.name}}(mojo::String({{field.default}}));
12 {%- elif field.kind|is_object_kind -%}
13 {
14 {{field.kind|cpp_wrapper_type}}::Builder tmp;
15 // TODO
16 set_{{field.name}}(tmp.Finish());
17 }
18 {%- else -%}
19 set_{{field.name}}({{field.default}});
20 {%- endif %}
21 {%- endmacro %}
22
9 {{class_name}}::Builder::Builder(mojo::Buffer* buf) 23 {{class_name}}::Builder::Builder(mojo::Buffer* buf)
10 : data_(Data::New(buf, {{dtor_name[0]}})) { 24 : data_(Data::New(buf, {{dtor_name[0]}})) {
25 {%- for pf in struct.packed.packed_fields if pf.field.default %}
26 {{set_default(pf.field)|indent(2)}}
darin (slow to review) 2014/01/21 23:47:20 Perhaps we should defer setting default values unt
27 {%- endfor %}
11 } 28 }
12 29
13 {{class_name}} {{class_name}}::Builder::Finish() { 30 {{class_name}} {{class_name}}::Builder::Finish() {
14 Data* data = NULL; 31 Data* data = NULL;
15 std::swap(data, data_); 32 std::swap(data, data_);
16 return mojo::internal::Wrap(data); 33 return mojo::internal::Wrap(data);
17 } 34 }
OLDNEW
« 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