OLD | NEW |
1 {%- import "struct_macros.tmpl" as struct_macros %} | 1 {%- import "struct_macros.tmpl" as struct_macros %} |
2 {%- set class_name = struct.name ~ "_Data" %} | 2 {%- set class_name = struct.name ~ "_Data" %} |
3 class {{class_name}} { | 3 class {{class_name}} { |
4 public: | 4 public: |
5 static {{class_name}}* New(mojo::Buffer* buf) { | 5 static {{class_name}}* New(mojo::Buffer* buf) { |
6 return new (buf->Allocate(sizeof({{class_name}}))) | 6 return new (buf->Allocate(sizeof({{class_name}}))) |
7 {{class_name}}(); | 7 {{class_name}}(); |
8 } | 8 } |
9 | 9 |
| 10 static bool Validate(const void* data, |
| 11 mojo::internal::BoundsChecker* bounds_checker) { |
| 12 {{ struct_macros.validate(struct, class_name)|indent(4) }} |
| 13 } |
| 14 |
10 {#--- Setters -#} | 15 {#--- Setters -#} |
11 {{ struct_macros.setters(struct) }} | 16 {{ struct_macros.setters(struct) }} |
12 | 17 |
13 {#--- Getters -#} | 18 {#--- Getters -#} |
14 {{ struct_macros.getters(struct) }} | 19 {{ struct_macros.getters(struct) }} |
15 | 20 |
16 void CloseHandles() { | 21 void CloseHandles() { |
17 {%- for pf in struct.packed.packed_fields if pf.field.kind|is_object_kind %} | 22 {%- for pf in struct.packed.packed_fields if pf.field.kind|is_object_kind %} |
18 if ({{pf.field.name}}_.ptr) | 23 if ({{pf.field.name}}_.ptr) |
19 {{pf.field.name}}_.ptr->CloseHandles(); | 24 {{pf.field.name}}_.ptr->CloseHandles(); |
(...skipping 13 matching lines...) Expand all Loading... |
33 {{class_name}}() { | 38 {{class_name}}() { |
34 _header_.num_bytes = sizeof(*this); | 39 _header_.num_bytes = sizeof(*this); |
35 _header_.num_fields = {{struct.packed.packed_fields|length}}; | 40 _header_.num_fields = {{struct.packed.packed_fields|length}}; |
36 } | 41 } |
37 | 42 |
38 mojo::internal::StructHeader _header_; | 43 mojo::internal::StructHeader _header_; |
39 {{ struct_macros.fields(struct) }} | 44 {{ struct_macros.fields(struct) }} |
40 }; | 45 }; |
41 MOJO_COMPILE_ASSERT(sizeof({{class_name}}) == {{struct.packed|struct_size}}, | 46 MOJO_COMPILE_ASSERT(sizeof({{class_name}}) == {{struct.packed|struct_size}}, |
42 bad_sizeof_{{class_name}}); | 47 bad_sizeof_{{class_name}}); |
OLD | NEW |