OLD | NEW |
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) -%} | 9 {%- macro set_default(field) -%} |
10 {%- if field.kind|is_string_kind -%} | 10 {%- if field.kind|is_string_kind -%} |
11 set_{{field.name}}(mojo::String({{field.default}})); | 11 set_{{field.name}}(mojo::String({{field.default}})); |
| 12 {%- elif field.kind|is_array_kind -%} |
| 13 { |
| 14 {{field.kind|cpp_wrapper_type}}::Builder tmp({{field.default|length}}); |
| 15 {%- for element in field.default %} |
| 16 tmp[{{loop.index0}}] = {{element}}; |
| 17 {%- endfor %} |
| 18 set_{{field.name}}(tmp.Finish()); |
| 19 } |
12 {%- elif field.kind|is_object_kind -%} | 20 {%- elif field.kind|is_object_kind -%} |
13 { | 21 { |
14 {{field.kind|cpp_wrapper_type}}::Builder tmp; | 22 {{field.kind|cpp_wrapper_type}}::Builder tmp; |
15 // TODO | 23 // TODO |
16 set_{{field.name}}(tmp.Finish()); | 24 set_{{field.name}}(tmp.Finish()); |
17 } | 25 } |
18 {%- else -%} | 26 {%- else -%} |
19 set_{{field.name}}({{field.default}}); | 27 set_{{field.name}}({{field.default}}); |
20 {%- endif %} | 28 {%- endif %} |
21 {%- endmacro %} | 29 {%- endmacro %} |
22 | 30 |
23 {{class_name}}::Builder::Builder(mojo::Buffer* buf) | 31 {{class_name}}::Builder::Builder(mojo::Buffer* buf) |
24 : data_(Data::New(buf, {{dtor_name[0]}})) { | 32 : data_(Data::New(buf, {{dtor_name[0]}})) { |
25 {%- for pf in struct.packed.packed_fields if pf.field.default %} | 33 {%- for pf in struct.packed.packed_fields if pf.field.default %} |
26 {{set_default(pf.field)|indent(2)}} | 34 {{set_default(pf.field)|indent(2)}} |
27 {%- endfor %} | 35 {%- endfor %} |
28 } | 36 } |
29 | 37 |
30 {{class_name}} {{class_name}}::Builder::Finish() { | 38 {{class_name}} {{class_name}}::Builder::Finish() { |
31 Data* data = NULL; | 39 Data* data = NULL; |
32 std::swap(data, data_); | 40 std::swap(data, data_); |
33 return mojo::internal::Wrap(data); | 41 return mojo::internal::Wrap(data); |
34 } | 42 } |
OLD | NEW |