• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1class {{export_attribute}} {{struct.name}} {
2 public:
3  using DataView = {{struct.name}}DataView;
4  using Data_ = internal::{{struct.name}}_Data;
5
6{#--- Enums #}
7{%- for enum in struct.enums -%}
8  using {{enum.name}} = {{enum|get_name_for_kind(flatten_nested_kind=True)}};
9{%- endfor %}
10
11{#--- Constants #}
12{%- for constant in struct.constants %}
13  static {{constant|format_constant_declaration(nested=True)}};
14{%- endfor %}
15
16  template <typename... Args>
17  static {{struct.name}}Ptr New(Args&&... args) {
18    return {{struct.name}}Ptr(
19        base::in_place,
20        std::forward<Args>(args)...);
21  }
22
23  template <typename U>
24  static {{struct.name}}Ptr From(const U& u) {
25    return mojo::TypeConverter<{{struct.name}}Ptr, U>::Convert(u);
26  }
27
28  template <typename U>
29  U To() const {
30    return mojo::TypeConverter<U, {{struct.name}}>::Convert(*this);
31  }
32
33{% for constructor in struct|struct_constructors %}
34  {% if constructor.params|length == 1 %}explicit {% endif %}{{struct.name}}(
35{%-   for field in constructor.params %}
36{%-     set type = field.kind|cpp_wrapper_param_type %}
37{%-     set name = field.name %}
38      {{type}} {{name}}
39{%-     if not loop.last -%},{%- endif %}
40{%-   endfor %});
41{% endfor %}
42  ~{{struct.name}}();
43
44  // Clone() is a template so it is only instantiated if it is used. Thus, the
45  // bindings generator does not need to know whether Clone() or copy
46  // constructor/assignment are available for members.
47  template <typename StructPtrType = {{struct.name}}Ptr>
48  {{struct.name}}Ptr Clone() const;
49
50  // Equals() is a template so it is only instantiated if it is used. Thus, the
51  // bindings generator does not need to know whether Equals() or == operator
52  // are available for members.
53  template <typename T,
54            typename std::enable_if<std::is_same<
55                T, {{struct.name}}>::value>::type* = nullptr>
56  bool Equals(const T& other) const;
57
58{%- if struct|is_hashable %}
59  size_t Hash(size_t seed) const;
60{%- endif %}
61
62{%- set serialization_result_type = "WTF::Vector<uint8_t>"
63        if for_blink else "std::vector<uint8_t>" %}
64
65  template <typename UserType>
66  static {{serialization_result_type}} Serialize(UserType* input) {
67    return mojo::internal::StructSerializeImpl<
68        {{struct.name}}::DataView, {{serialization_result_type}}>(input);
69  }
70
71  template <typename UserType>
72  static bool Deserialize(const {{serialization_result_type}}& input,
73                          UserType* output) {
74    return mojo::internal::StructDeserializeImpl<
75        {{struct.name}}::DataView, {{serialization_result_type}}>(
76            input, output);
77  }
78
79{#--- Struct members #}
80{%  for field in struct.fields %}
81{%-   set type = field.kind|cpp_wrapper_type %}
82{%-   set name = field.name %}
83  {{type}} {{name}};
84{%- endfor %}
85
86{%- if struct|contains_move_only_members %}
87 private:
88  DISALLOW_COPY_AND_ASSIGN({{struct.name}});
89{%- endif %}
90};
91
92