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

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

Issue 226263002: Mojo: Move mojo/public/bindings to mojo/public/tools/bindings. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebased Created 6 years, 8 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
(Empty)
1 {%- import "struct_macros.tmpl" as struct_macros %}
2 {%- set class_name = struct.name ~ "_Data" %}
3 // static
4 {{class_name}}* {{class_name}}::New(mojo::Buffer* buf, mojo::Buffer::Destructor dtor) {
5 return new (buf->Allocate(sizeof({{class_name}}), dtor)) {{class_name}}();
6 }
7
8 {{class_name}}::{{class_name}}() {
9 _header_.num_bytes = sizeof(*this);
10 _header_.num_fields = {{struct.packed.packed_fields|length}};
11 }
12
13 size_t {{class_name}}::ComputeSize() const {
14 size_t result = sizeof(*this);
15 {%- for pf in struct.packed.packed_fields if pf.field.kind|is_object_kind %}
16 if ({{pf.field.name}}_.ptr)
17 result += {{pf.field.name}}_.ptr->ComputeSize();
18 {%- endfor %}
19 return result;
20 }
21
22 {{class_name}}* {{class_name}}::Clone(mojo::Buffer* buf) const {
23 {{class_name}}* clone = New(buf);
24 memcpy(clone, this, sizeof(*this));
25 {%- for pf in struct.packed.packed_fields if pf.field.kind|is_object_kind %}
26 if ({{pf.field.name}}_.ptr)
27 clone->set_{{pf.field.name}}({{pf.field.name}}_.ptr->Clone(buf));
28 {%- endfor %}
29 {%- for pf in struct.packed.packed_fields if pf.field.kind|is_handle_kind %}
30 mojo::internal::ResetIfNonNull({{pf.field.name}}());
31 {%- endfor %}
32 return clone;
33 }
34
35 void {{class_name}}::CloseHandles() {
36 {%- for pf in struct.packed.packed_fields if pf.field.kind|is_object_kind %}
37 if ({{pf.field.name}}_.ptr)
38 {{pf.field.name}}_.ptr->CloseHandles();
39 {%- endfor %}
40 {%- if struct|is_struct_with_handles %}
41 {{struct.name}}_Data_Destructor(this);
42 {%- endif %}
43 }
44
45 void {{class_name}}::EncodePointersAndHandles(
46 std::vector<mojo::Handle>* handles) {
47 {{ struct_macros.encodes(struct)|indent(2) }}
48 }
49
50 bool {{class_name}}::DecodePointersAndHandles(mojo::Message* message) {
51 {{ struct_macros.decodes(struct)|indent(2) }}
52 return true;
53 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698