1 class {{struct.name}} {
3 typedef internal::{{struct.name}}_Data Data;
6 {%- for enum in struct.enums -%}
7 {% macro enum_def() %}{% include "enum_declaration.tmpl" %}{% endmacro %}
8 {{enum_def()|indent(2)}}
11 {{struct.name}}() : data_(NULL) {
15 {{struct.name}}(const U& u, mojo::Buffer* buf = mojo::Buffer::current()) {
16 mojo::TypeConverter<{{struct.name}},U>::AssertAllowImplicitTypeConversion();
17 *this = mojo::TypeConverter<{{struct.name}},U>::ConvertFrom(u, buf);
21 {{struct.name}}& operator=(const U& u) {
22 mojo::TypeConverter<{{struct.name}},U>::AssertAllowImplicitTypeConversion();
23 *this = mojo::TypeConverter<{{struct.name}},U>::ConvertFrom(u, mojo::Buffer::current());
29 mojo::TypeConverter<{{struct.name}},U>::AssertAllowImplicitTypeConversion();
35 return mojo::TypeConverter<{{struct.name}},U>::ConvertTo(*this);
39 static {{struct.name}} From(const U& u, mojo::Buffer* buf = mojo::Buffer::current()) {
40 return mojo::TypeConverter<{{struct.name}},U>::ConvertFrom(u, buf);
43 bool is_null() const { return !data_; }
46 {% for packed_field in struct.packed.packed_fields %}
47 {%- set type = packed_field.field.kind|cpp_wrapper_type %}
48 {%- set name = packed_field.field.name %}
49 {%- if packed_field.field.kind|is_object_kind %}
50 const {{type}} {{name}}() const { {#
51 #}return mojo::internal::Wrap(data_->{{name}}()); }
52 {%- elif packed_field.field.kind|is_handle_kind %}
53 {{type}} {{name}}() const { return mojo::MakePassable(data_->{{name}}()); }
54 {%- elif packed_field.field.kind|is_enum_kind %}
55 {{type}} {{name}}() const { return static_cast<{{type}}>(data_->{{name}}()); }
57 {{type}} {{name}}() const { return data_->{{name}}(); }
63 explicit Builder(mojo::Buffer* buf = mojo::Buffer::current());
66 {% for packed_field in struct.packed.packed_fields %}
67 {%- set type = packed_field.field.kind|cpp_const_wrapper_type %}
68 {%- set name = packed_field.field.name %}
69 {%- if packed_field.field.kind|is_object_kind %}
70 void set_{{name}}({{type}} {{name}}) { {#
71 #}data_->set_{{name}}(mojo::internal::Unwrap({{name}})); }
72 {%- elif packed_field.field.kind|is_handle_kind %}
73 void set_{{name}}({{type}} {{name}}) { {#
74 #}data_->set_{{name}}({{name}}.release()); }
76 void set_{{name}}({{type}} {{name}}) { {#
77 #}data_->set_{{name}}({{name}}); }
81 {{struct.name}} Finish();
84 {{struct.name}}::Data* data_;
85 MOJO_DISALLOW_COPY_AND_ASSIGN(Builder);
89 friend class mojo::internal::WrapperHelper<{{struct.name}}>;
92 {{struct.name}}(Wrap, const Data* data) : data_(data) {}