OLD | NEW |
1 {% from "enum_macros.tmpl" import enum_decl -%} | 1 {% from "enum_macros.tmpl" import enum_decl -%} |
2 | 2 |
3 class {{struct.name}} { | 3 class {{struct.name}} { |
4 public: | 4 public: |
5 using Data_ = internal::{{struct.name}}_Data; | 5 using Data_ = internal::{{struct.name}}_Data; |
6 | 6 |
7 {#--- Enums #} | 7 {#--- Enums #} |
8 {%- for enum in struct.enums -%} | 8 {%- for enum in struct.enums -%} |
9 {{enum_decl(enum)|indent(2)}} | 9 {{enum_decl(enum)|indent(2)}} |
10 {%- endfor %} | 10 {%- endfor %} |
(...skipping 15 matching lines...) Expand all Loading... |
26 } | 26 } |
27 | 27 |
28 template <typename U> | 28 template <typename U> |
29 U To() const { | 29 U To() const { |
30 return mojo::TypeConverter<U, {{struct.name}}>::Convert(*this); | 30 return mojo::TypeConverter<U, {{struct.name}}>::Convert(*this); |
31 } | 31 } |
32 | 32 |
33 {{struct.name}}(); | 33 {{struct.name}}(); |
34 ~{{struct.name}}(); | 34 ~{{struct.name}}(); |
35 | 35 |
36 {% if struct|is_cloneable_kind %} | 36 // Clone() is a template so it is only instantiated if it is used. Thus, the |
37 {{struct.name}}Ptr Clone() const; | 37 // bindings generator does not need to know whether typemapped native types |
38 {%- endif %} | 38 // support operator=. |
| 39 template <typename StructPtrType = {{struct.name}}Ptr> |
| 40 {{struct.name}}Ptr Clone() const { |
| 41 // Use StructPtrType to prevent the compiler from trying to compile this |
| 42 // without being asked. |
| 43 StructPtrType rv(New()); |
| 44 {%- for field in struct.fields %} |
| 45 {%- if field.kind|is_object_kind and not field.kind|is_string_kind and |
| 46 not field.kind|is_typemapped_kind %} |
| 47 rv->{{field.name}} = {{field.name}}.Clone(); |
| 48 {%- else %} |
| 49 rv->{{field.name}} = {{field.name}}; |
| 50 {%- endif %} |
| 51 {%- endfor %} |
| 52 return rv; |
| 53 } |
| 54 |
39 // Equals() is a template so it is only instantiated if it is used. Thus, the | 55 // Equals() is a template so it is only instantiated if it is used. Thus, the |
40 // bindings generator does not need to know whether typemapped native types | 56 // bindings generator does not need to know whether typemapped native types |
41 // support operator==. | 57 // support operator==. |
42 template <typename T, | 58 template <typename T, |
43 typename std::enable_if<std::is_same< | 59 typename std::enable_if<std::is_same< |
44 T, {{struct.name}}>::value>::type* = nullptr> | 60 T, {{struct.name}}>::value>::type* = nullptr> |
45 bool Equals(const T& other) const { | 61 bool Equals(const T& other) const { |
46 {%- for field in struct.fields %} | 62 {%- for field in struct.fields %} |
47 if (!mojo::internal::ValueTraits<{{field.kind|cpp_wrapper_type}}>::Equals(th
is->{{field.name}}, other.{{field.name}})) | 63 if (!mojo::internal::ValueTraits<{{field.kind|cpp_wrapper_type}}>::Equals(th
is->{{field.name}}, other.{{field.name}})) |
48 return false; | 64 return false; |
49 {%- endfor %} | 65 {%- endfor %} |
50 return true; | 66 return true; |
51 } | 67 } |
52 | 68 |
53 {#--- Struct members #} | 69 {#--- Struct members #} |
54 {% for field in struct.fields %} | 70 {% for field in struct.fields %} |
55 {%- set type = field.kind|cpp_wrapper_type %} | 71 {%- set type = field.kind|cpp_wrapper_type %} |
56 {%- set name = field.name %} | 72 {%- set name = field.name %} |
57 {{type}} {{name}}; | 73 {{type}} {{name}}; |
58 {%- endfor %} | 74 {%- endfor %} |
59 }; | 75 }; |
60 | 76 |
OLD | NEW |