OLD | NEW |
| (Empty) |
1 {%- import "struct_macros.tmpl" as struct_macros %} | |
2 {%- set class_name = struct.name ~ "_Data" %} | |
3 class {{class_name}} { | |
4 public: | |
5 static {{class_name}}* New(mojo::Buffer* buf) { | |
6 return new (buf->Allocate(sizeof({{class_name}}))) | |
7 {{class_name}}(); | |
8 } | |
9 | |
10 {#--- Setters -#} | |
11 {{ struct_macros.setters(struct) }} | |
12 | |
13 {#--- Getters -#} | |
14 {{ struct_macros.getters(struct) }} | |
15 | |
16 void CloseHandles() { | |
17 {%- for pf in struct.packed.packed_fields if pf.field.kind|is_object_kind %} | |
18 if ({{pf.field.name}}_.ptr) | |
19 {{pf.field.name}}_.ptr->CloseHandles(); | |
20 {%- endfor %} | |
21 } | |
22 | |
23 void EncodePointersAndHandles(std::vector<mojo::Handle>* handles) { | |
24 {{ struct_macros.encodes(struct)|indent(4) }} | |
25 } | |
26 | |
27 bool DecodePointersAndHandles(mojo::Message* message) { | |
28 {{ struct_macros.decodes(struct)|indent(4) }} | |
29 return true; | |
30 } | |
31 | |
32 private: | |
33 {{class_name}}() { | |
34 _header_.num_bytes = sizeof(*this); | |
35 _header_.num_fields = 3; | |
36 } | |
37 | |
38 mojo::internal::StructHeader _header_; | |
39 {{ struct_macros.fields(struct) }} | |
40 }; | |
41 MOJO_COMPILE_ASSERT(sizeof({{class_name}}) == {{struct.packed|struct_size}}, | |
42 bad_sizeof_{{class_name}}); | |
OLD | NEW |