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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: mojo/public/tools/bindings/generators/cpp_templates/wrapper_class_declaration.tmpl
diff --git a/mojo/public/tools/bindings/generators/cpp_templates/wrapper_class_declaration.tmpl b/mojo/public/tools/bindings/generators/cpp_templates/wrapper_class_declaration.tmpl
index 9c56d25b63da4f44de881aed8c9cfb790b286ba5..10dae9703a3db2ef45eb9ca4fe7cd90cd8765e4f 100644
--- a/mojo/public/tools/bindings/generators/cpp_templates/wrapper_class_declaration.tmpl
+++ b/mojo/public/tools/bindings/generators/cpp_templates/wrapper_class_declaration.tmpl
@@ -1,100 +1,29 @@
+
class {{struct.name}} {
public:
- typedef internal::{{struct.name}}_Data Data;
-
{#--- Constants #}
-{% for constant in struct.constants %}
+{%- for constant in struct.constants %}
static const {{constant.kind|cpp_pod_type}} {{constant.name}};
{%- endfor %}
-
{#--- Enums #}
{%- for enum in struct.enums -%}
{% macro enum_def() %}{% include "enum_declaration.tmpl" %}{% endmacro %}
{{enum_def()|indent(2)}}
{%- endfor %}
-
- {{struct.name}}() : data_(NULL) {
- }
+ static {{struct.name}}Ptr New();
template <typename U>
- {{struct.name}}(const U& u, mojo::Buffer* buf = mojo::Buffer::current()) {
- mojo::TypeConverter<{{struct.name}},U>::AssertAllowImplicitTypeConversion();
- *this = mojo::TypeConverter<{{struct.name}},U>::ConvertFrom(u, buf);
+ static {{struct.name}}Ptr From(const U& u) {
+ return mojo::TypeConverter<{{struct.name}}Ptr, U>::ConvertFrom(u);
}
- template <typename U>
- {{struct.name}}& operator=(const U& u) {
- mojo::TypeConverter<{{struct.name}},U>::AssertAllowImplicitTypeConversion();
- *this = mojo::TypeConverter<{{struct.name}},U>::ConvertFrom(u, mojo::Buffer::current());
- return *this;
- }
-
- template <typename U>
- operator U() const {
- mojo::TypeConverter<{{struct.name}},U>::AssertAllowImplicitTypeConversion();
- return To<U>();
- }
-
- template <typename U>
- U To() const {
- return mojo::TypeConverter<{{struct.name}},U>::ConvertTo(*this);
- }
-
- template <typename U>
- static {{struct.name}} From(const U& u, mojo::Buffer* buf = mojo::Buffer::current()) {
- return mojo::TypeConverter<{{struct.name}},U>::ConvertFrom(u, buf);
- }
-
- bool is_null() const { return !data_; }
+ {{struct.name}}();
+ ~{{struct.name}}();
{#--- Getters #}
-{% for packed_field in struct.packed.packed_fields %}
-{%- set type = packed_field.field.kind|cpp_wrapper_type %}
-{%- set name = packed_field.field.name %}
-{%- if packed_field.field.kind|is_object_kind %}
- const {{type}} {{name}}() const { {#
- #}return mojo::internal::Wrap(data_->{{name}}()); }
-{%- elif packed_field.field.kind|is_handle_kind %}
- {{type}} {{name}}() const { return mojo::MakePassable(data_->{{name}}()); }
-{%- elif packed_field.field.kind|is_enum_kind %}
- {{type}} {{name}}() const { return static_cast<{{type}}>(data_->{{name}}()); }
-{%- else %}
- {{type}} {{name}}() const { return data_->{{name}}(); }
-{%- endif %}
-{%- endfor %}
-
- class Builder {
- public:
- explicit Builder(mojo::Buffer* buf = mojo::Buffer::current());
-
-{#--- Setters #}
-{% for packed_field in struct.packed.packed_fields %}
-{%- set type = packed_field.field.kind|cpp_const_wrapper_type %}
-{%- set name = packed_field.field.name %}
-{%- if packed_field.field.kind|is_object_kind %}
- void set_{{name}}({{type}} {{name}}) { {#
- #}data_->set_{{name}}(mojo::internal::Unwrap({{name}})); }
-{%- elif packed_field.field.kind|is_handle_kind %}
- void set_{{name}}({{type}} {{name}}) { {#
- #}data_->set_{{name}}({{name}}.release()); }
-{%- else %}
- void set_{{name}}({{type}} {{name}}) { {#
- #}data_->set_{{name}}({{name}}); }
-{%- endif %}
+{% for field in struct.fields %}
+{%- set type = field.kind|cpp_wrapper_type %}
+{%- set name = field.name %}
+ {{type}} {{name}};
{%- endfor %}
-
- {{struct.name}} Finish();
-
- private:
- {{struct.name}}::Data* data_;
- MOJO_DISALLOW_COPY_AND_ASSIGN(Builder);
- };
-
- private:
- friend class mojo::internal::WrapperHelper<{{struct.name}}>;
-
- struct Wrap {};
- {{struct.name}}(Wrap, const Data* data) : data_(data) {}
-
- const Data* data_;
};

Powered by Google App Engine
This is Rietveld 408576698