Upstream version 7.35.144.0
[platform/framework/web/crosswalk.git] / src / mojo / public / bindings / generators / cpp_templates / wrapper_class_declaration.tmpl
1 class {{struct.name}} {
2  public:
3   typedef internal::{{struct.name}}_Data Data;
4
5 {#--- Enums #}
6 {%- for enum in struct.enums -%}
7 {%    macro enum_def() %}{% include "enum_declaration.tmpl" %}{% endmacro %}
8   {{enum_def()|indent(2)}}
9 {%- endfor %}
10
11   {{struct.name}}() : data_(NULL) {
12   }
13
14   template <typename U>
15   {{struct.name}}(const U& u, mojo::Buffer* buf = mojo::Buffer::current()) {
16     *this = mojo::TypeConverter<{{struct.name}},U>::ConvertFrom(u, buf);
17   }
18
19   template <typename U>
20   {{struct.name}}& operator=(const U& u) {
21     *this = mojo::TypeConverter<{{struct.name}},U>::ConvertFrom(u, mojo::Buffer::current());
22     return *this;
23   }
24
25   template <typename U>
26   operator U() const {
27     return To<U>();
28   }
29
30   template <typename U>
31   U To() const {
32     return mojo::TypeConverter<{{struct.name}},U>::ConvertTo(*this);
33   }
34
35   bool is_null() const { return !data_; }
36
37 {#--- Getters #}
38 {%  for packed_field in struct.packed.packed_fields %}
39 {%-   set type = packed_field.field.kind|cpp_wrapper_type %}
40 {%-   set name = packed_field.field.name %}
41 {%-   if packed_field.field.kind|is_object_kind %}
42   const {{type}} {{name}}() const { {#
43     #}return mojo::internal::Wrap(data_->{{name}}()); }
44 {%-   elif packed_field.field.kind|is_handle_kind %}
45   {{type}} {{name}}() const { return mojo::MakePassable(data_->{{name}}()); }
46 {%-   elif packed_field.field.kind|is_enum_kind %}
47   {{type}} {{name}}() const { return static_cast<{{type}}>(data_->{{name}}()); }
48 {%-   else %}
49   {{type}} {{name}}() const { return data_->{{name}}(); }
50 {%-   endif %}
51 {%- endfor %}
52
53   class Builder {
54    public:
55     explicit Builder(mojo::Buffer* buf = mojo::Buffer::current());
56
57 {#--- Setters #}
58 {%  for packed_field in struct.packed.packed_fields %}
59 {%-   set type = packed_field.field.kind|cpp_const_wrapper_type %}
60 {%-   set name = packed_field.field.name %}
61 {%-   if packed_field.field.kind|is_object_kind %}
62     void set_{{name}}({{type}} {{name}}) { {#
63     #}data_->set_{{name}}(mojo::internal::Unwrap({{name}})); }
64 {%-   elif packed_field.field.kind|is_handle_kind %}
65     void set_{{name}}({{type}} {{name}}) { {#
66     #}data_->set_{{name}}({{name}}.release()); }
67 {%-   else %}
68     void set_{{name}}({{type}} {{name}}) { {#
69     #}data_->set_{{name}}({{name}}); }
70 {%-   endif %}
71 {%- endfor %}
72
73     {{struct.name}} Finish();
74
75    private:
76     {{struct.name}}::Data* data_;
77     MOJO_DISALLOW_COPY_AND_ASSIGN(Builder);
78   };
79
80  private:
81   friend class mojo::internal::WrapperHelper<{{struct.name}}>;
82
83   struct Wrap {};
84   {{struct.name}}(Wrap, const Data* data) : data_(data) {}
85
86   const Data* data_;
87 };