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

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

Issue 917333003: Mojo C++ bindings templates: use the same templates for user-defined structs and method params. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 5 years, 10 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
OLDNEW
(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::internal::Buffer* buf) {
6 return new (buf->Allocate(sizeof({{class_name}})))
7 {{class_name}}();
8 }
9
10 static bool Validate(const void* data,
11 mojo::internal::BoundsChecker* bounds_checker) {
12 {{struct_macros.validate(struct)|indent(2)}}
13 }
14
15 mojo::internal::StructHeader header_;
16 {{struct_macros.fields(struct)}}
17
18 void EncodePointersAndHandles(std::vector<mojo::Handle>* handles) {
19 {{struct_macros.encodes(struct)|indent(2)}}
20 }
21
22 void DecodePointersAndHandles(std::vector<mojo::Handle>* handles) {
23 {{struct_macros.decodes(struct)|indent(2)}}
24 }
25
26 private:
27 {{class_name}}() {
28 header_.num_bytes = sizeof(*this);
29 header_.version = {{struct.versions[-1].version}};
30 }
31 };
32 static_assert(sizeof({{class_name}}) == {{struct.versions[-1].num_bytes}},
33 "Bad sizeof({{class_name}})");
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698