OLD | NEW |
1 {%- set class_name = union.name ~ "_Data" -%} | 1 {%- set class_name = union.name ~ "_Data" -%} |
2 {%- set enum_name = union.name ~ "_Tag" -%} | 2 {%- set enum_name = union.name ~ "_Tag" -%} |
3 {%- import "struct_macros.tmpl" as struct_macros %} | 3 {%- import "struct_macros.tmpl" as struct_macros %} |
4 | 4 |
5 class {{class_name}} { | 5 class {{class_name}} { |
6 public: | 6 public: |
7 // Used to identify Mojom Union Data Classes. | 7 // Used to identify Mojom Union Data Classes. |
8 typedef void MojomUnionDataType; | 8 typedef void MojomUnionDataType; |
9 static {{class_name}}* New(mojo::internal::Buffer* buf); | 9 |
| 10 static {{class_name}}* New(mojo::internal::Buffer* buf) { |
| 11 return new (buf->Allocate(sizeof({{class_name}}))) {{class_name}}(); |
| 12 } |
| 13 |
10 {{class_name}}(); | 14 {{class_name}}(); |
11 // Do nothing in the destructor since it won't be called. | 15 // Do nothing in the destructor since it won't be called. |
12 ~{{class_name}}() {} | 16 ~{{class_name}}() {} |
13 | 17 |
14 static bool Validate(const void* data, | 18 static bool Validate(const void* data, |
15 mojo::internal::ValidationContext* validation_context, | 19 mojo::internal::ValidationContext* validation_context, |
16 bool inlined); | 20 bool inlined); |
17 | 21 |
18 bool is_null() const { | 22 bool is_null() const { |
19 return size == 0; | 23 return size == 0; |
(...skipping 20 matching lines...) Expand all Loading... |
40 {%- endfor %} | 44 {%- endfor %} |
41 uint64_t unknown; | 45 uint64_t unknown; |
42 }; | 46 }; |
43 | 47 |
44 uint32_t size; | 48 uint32_t size; |
45 {{enum_name}} tag; | 49 {{enum_name}} tag; |
46 Union_ data; | 50 Union_ data; |
47 }; | 51 }; |
48 static_assert(sizeof({{class_name}}) == mojo::internal::kUnionDataSize, | 52 static_assert(sizeof({{class_name}}) == mojo::internal::kUnionDataSize, |
49 "Bad sizeof({{class_name}})"); | 53 "Bad sizeof({{class_name}})"); |
OLD | NEW |