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

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

Issue 209453003: Add support for mojo::TypeConverter to control how convenient conversion should be. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 8 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
OLDNEW
1 class {{struct.name}} { 1 class {{struct.name}} {
2 public: 2 public:
3 typedef internal::{{struct.name}}_Data Data; 3 typedef internal::{{struct.name}}_Data Data;
4 4
5 {#--- Enums #} 5 {#--- Enums #}
6 {%- for enum in struct.enums -%} 6 {%- for enum in struct.enums -%}
7 {% macro enum_def() %}{% include "enum_declaration.tmpl" %}{% endmacro %} 7 {% macro enum_def() %}{% include "enum_declaration.tmpl" %}{% endmacro %}
8 {{enum_def()|indent(2)}} 8 {{enum_def()|indent(2)}}
9 {%- endfor %} 9 {%- endfor %}
10 10
11 {{struct.name}}() : data_(NULL) { 11 {{struct.name}}() : data_(NULL) {
12 } 12 }
13 13
14 template <typename U> 14 template <typename U>
15 {{struct.name}}(const U& u, mojo::Buffer* buf = mojo::Buffer::current()) { 15 {{struct.name}}(const U& u, mojo::Buffer* buf = mojo::Buffer::current()) {
16 MOJO_INTERNAL_CHECK_ALLOW_IMPLICIT_TYPE_CONVERSION({{struct.name}}, U);
16 *this = mojo::TypeConverter<{{struct.name}},U>::ConvertFrom(u, buf); 17 *this = mojo::TypeConverter<{{struct.name}},U>::ConvertFrom(u, buf);
17 } 18 }
18 19
19 template <typename U> 20 template <typename U>
20 {{struct.name}}& operator=(const U& u) { 21 {{struct.name}}& operator=(const U& u) {
22 MOJO_INTERNAL_CHECK_ALLOW_IMPLICIT_TYPE_CONVERSION({{struct.name}}, U);
21 *this = mojo::TypeConverter<{{struct.name}},U>::ConvertFrom(u, mojo::Buffer: :current()); 23 *this = mojo::TypeConverter<{{struct.name}},U>::ConvertFrom(u, mojo::Buffer: :current());
22 return *this; 24 return *this;
23 } 25 }
24 26
25 template <typename U> 27 template <typename U>
26 operator U() const { 28 operator U() const {
29 MOJO_INTERNAL_CHECK_ALLOW_IMPLICIT_TYPE_CONVERSION({{struct.name}}, U);
27 return To<U>(); 30 return To<U>();
28 } 31 }
29 32
30 template <typename U> 33 template <typename U>
31 U To() const { 34 U To() const {
32 return mojo::TypeConverter<{{struct.name}},U>::ConvertTo(*this); 35 return mojo::TypeConverter<{{struct.name}},U>::ConvertTo(*this);
33 } 36 }
34 37
38 template <typename U>
39 static {{struct.name}} From(const U& u, mojo::Buffer* buf = mojo::Buffer::curr ent()) {
40 return mojo::TypeConverter<{{struct.name}},U>::ConvertFrom(u, buf);
41 }
42
35 bool is_null() const { return !data_; } 43 bool is_null() const { return !data_; }
36 44
37 {#--- Getters #} 45 {#--- Getters #}
38 {% for packed_field in struct.packed.packed_fields %} 46 {% for packed_field in struct.packed.packed_fields %}
39 {%- set type = packed_field.field.kind|cpp_wrapper_type %} 47 {%- set type = packed_field.field.kind|cpp_wrapper_type %}
40 {%- set name = packed_field.field.name %} 48 {%- set name = packed_field.field.name %}
41 {%- if packed_field.field.kind|is_object_kind %} 49 {%- if packed_field.field.kind|is_object_kind %}
42 const {{type}} {{name}}() const { {# 50 const {{type}} {{name}}() const { {#
43 #}return mojo::internal::Wrap(data_->{{name}}()); } 51 #}return mojo::internal::Wrap(data_->{{name}}()); }
44 {%- elif packed_field.field.kind|is_handle_kind %} 52 {%- elif packed_field.field.kind|is_handle_kind %}
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 }; 86 };
79 87
80 private: 88 private:
81 friend class mojo::internal::WrapperHelper<{{struct.name}}>; 89 friend class mojo::internal::WrapperHelper<{{struct.name}}>;
82 90
83 struct Wrap {}; 91 struct Wrap {};
84 {{struct.name}}(Wrap, const Data* data) : data_(data) {} 92 {{struct.name}}(Wrap, const Data* data) : data_(data) {}
85 93
86 const Data* data_; 94 const Data* data_;
87 }; 95 };
OLDNEW
« no previous file with comments | « mojo/public/cpp/bindings/type_converter.h ('k') | mojo/services/gles2/command_buffer_type_conversions.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698