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

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

Issue 2031823002: Mojo C++ bindings: more consistent Clone() and Equals(). (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 6 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 {% 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 16 matching lines...) Expand all
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 // Clone() is a template so it is only instantiated if it is used. Thus, the 36 // Clone() is a template so it is only instantiated if it is used. Thus, the
37 // bindings generator does not need to know whether typemapped native types 37 // bindings generator does not need to know whether Clone() or copy
38 // support operator=. 38 // constructor/assignment are available for members.
39 template <typename StructPtrType = {{struct.name}}Ptr> 39 template <typename StructPtrType = {{struct.name}}Ptr>
40 {{struct.name}}Ptr Clone() const { 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 41
55 // Equals() is a template so it is only instantiated if it is used. Thus, the 42 // Equals() is a template so it is only instantiated if it is used. Thus, the
56 // bindings generator does not need to know whether typemapped native types 43 // bindings generator does not need to know whether Equals() or == operator
57 // support operator==. 44 // are available for members.
58 template <typename T, 45 template <typename T,
59 typename std::enable_if<std::is_same< 46 typename std::enable_if<std::is_same<
60 T, {{struct.name}}>::value>::type* = nullptr> 47 T, {{struct.name}}>::value>::type* = nullptr>
61 bool Equals(const T& other) const { 48 bool Equals(const T& other) const;
62 {%- for field in struct.fields %}
63 if (!mojo::internal::ValueTraits<{{field.kind|cpp_wrapper_type}}>::Equals(th is->{{field.name}}, other.{{field.name}}))
64 return false;
65 {%- endfor %}
66 return true;
67 }
68 49
69 {#--- Struct members #} 50 {#--- Struct members #}
70 {% for field in struct.fields %} 51 {% for field in struct.fields %}
71 {%- set type = field.kind|cpp_wrapper_type %} 52 {%- set type = field.kind|cpp_wrapper_type %}
72 {%- set name = field.name %} 53 {%- set name = field.name %}
73 {{type}} {{name}}; 54 {{type}} {{name}};
74 {%- endfor %} 55 {%- endfor %}
75 }; 56 };
76 57
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698