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

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

Issue 294833002: Mojo: more idiomatic C++ bindings (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: more Created 6 years, 7 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
1 class {{struct.name}} { 2 class {{struct.name}} {
2 public: 3 public:
3 typedef internal::{{struct.name}}_Data Data;
4
5 {#--- Constants #} 4 {#--- Constants #}
6 {% for constant in struct.constants %} 5 {%- for constant in struct.constants %}
7 static const {{constant.kind|cpp_pod_type}} {{constant.name}}; 6 static const {{constant.kind|cpp_pod_type}} {{constant.name}};
8 {%- endfor %} 7 {%- endfor %}
9
10 {#--- Enums #} 8 {#--- Enums #}
11 {%- for enum in struct.enums -%} 9 {%- for enum in struct.enums -%}
12 {% macro enum_def() %}{% include "enum_declaration.tmpl" %}{% endmacro %} 10 {% macro enum_def() %}{% include "enum_declaration.tmpl" %}{% endmacro %}
13 {{enum_def()|indent(2)}} 11 {{enum_def()|indent(2)}}
14 {%- endfor %} 12 {%- endfor %}
13 static {{struct.name}}Ptr New();
15 14
16 {{struct.name}}() : data_(NULL) { 15 template <typename U>
16 static {{struct.name}}Ptr From(const U& u) {
17 return mojo::TypeConverter<{{struct.name}}Ptr, U>::ConvertFrom(u);
17 } 18 }
18 19
19 template <typename U> 20 {{struct.name}}();
20 {{struct.name}}(const U& u, mojo::Buffer* buf = mojo::Buffer::current()) { 21 ~{{struct.name}}();
21 mojo::TypeConverter<{{struct.name}},U>::AssertAllowImplicitTypeConversion();
22 *this = mojo::TypeConverter<{{struct.name}},U>::ConvertFrom(u, buf);
23 }
24
25 template <typename U>
26 {{struct.name}}& operator=(const U& u) {
27 mojo::TypeConverter<{{struct.name}},U>::AssertAllowImplicitTypeConversion();
28 *this = mojo::TypeConverter<{{struct.name}},U>::ConvertFrom(u, mojo::Buffer: :current());
29 return *this;
30 }
31
32 template <typename U>
33 operator U() const {
34 mojo::TypeConverter<{{struct.name}},U>::AssertAllowImplicitTypeConversion();
35 return To<U>();
36 }
37
38 template <typename U>
39 U To() const {
40 return mojo::TypeConverter<{{struct.name}},U>::ConvertTo(*this);
41 }
42
43 template <typename U>
44 static {{struct.name}} From(const U& u, mojo::Buffer* buf = mojo::Buffer::curr ent()) {
45 return mojo::TypeConverter<{{struct.name}},U>::ConvertFrom(u, buf);
46 }
47
48 bool is_null() const { return !data_; }
49 22
50 {#--- Getters #} 23 {#--- Getters #}
51 {% for packed_field in struct.packed.packed_fields %} 24 {% for field in struct.fields %}
52 {%- set type = packed_field.field.kind|cpp_wrapper_type %} 25 {%- set type = field.kind|cpp_wrapper_type %}
53 {%- set name = packed_field.field.name %} 26 {%- set name = field.name %}
54 {%- if packed_field.field.kind|is_object_kind %} 27 {{type}} {{name}};
55 const {{type}} {{name}}() const { {#
56 #}return mojo::internal::Wrap(data_->{{name}}()); }
57 {%- elif packed_field.field.kind|is_handle_kind %}
58 {{type}} {{name}}() const { return mojo::MakePassable(data_->{{name}}()); }
59 {%- elif packed_field.field.kind|is_enum_kind %}
60 {{type}} {{name}}() const { return static_cast<{{type}}>(data_->{{name}}()); }
61 {%- else %}
62 {{type}} {{name}}() const { return data_->{{name}}(); }
63 {%- endif %}
64 {%- endfor %} 28 {%- endfor %}
65
66 class Builder {
67 public:
68 explicit Builder(mojo::Buffer* buf = mojo::Buffer::current());
69
70 {#--- Setters #}
71 {% for packed_field in struct.packed.packed_fields %}
72 {%- set type = packed_field.field.kind|cpp_const_wrapper_type %}
73 {%- set name = packed_field.field.name %}
74 {%- if packed_field.field.kind|is_object_kind %}
75 void set_{{name}}({{type}} {{name}}) { {#
76 #}data_->set_{{name}}(mojo::internal::Unwrap({{name}})); }
77 {%- elif packed_field.field.kind|is_handle_kind %}
78 void set_{{name}}({{type}} {{name}}) { {#
79 #}data_->set_{{name}}({{name}}.release()); }
80 {%- else %}
81 void set_{{name}}({{type}} {{name}}) { {#
82 #}data_->set_{{name}}({{name}}); }
83 {%- endif %}
84 {%- endfor %}
85
86 {{struct.name}} Finish();
87
88 private:
89 {{struct.name}}::Data* data_;
90 MOJO_DISALLOW_COPY_AND_ASSIGN(Builder);
91 };
92
93 private:
94 friend class mojo::internal::WrapperHelper<{{struct.name}}>;
95
96 struct Wrap {};
97 {{struct.name}}(Wrap, const Data* data) : data_(data) {}
98
99 const Data* data_;
100 }; 29 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698