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

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

Issue 2250183003: Make the fuchsia mojo/public repo the source of truth. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 4 years, 4 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 {% from "enum_macros.tmpl" import enum_decl -%}
2 class {{struct.name}} {
3 public:
4 using Data_ = internal::{{struct.name}}_Data;
5
6 {#--- Enums #}
7 {%- for enum in struct.enums -%}
8 {{enum_decl(enum, is_static=true)|indent(2)}}
9 {%- endfor %}
10
11 {#--- Constants #}
12 {%- for constant in struct.constants %}
13 {%- if constant.kind|is_integral_kind %}
14 static const {{constant.kind|cpp_pod_type}} {{constant.name}} = {{constant|con stant_value}};
15 {%- else %}
16 static const {{constant.kind|cpp_pod_type}} {{constant.name}};
17 {%- endif %}
18 {%- endfor %}
19
20 static {{struct.name}}Ptr New();
21
22 template <typename U>
23 static {{struct.name}}Ptr From(const U& u) {
24 return mojo::TypeConverter<{{struct.name}}Ptr, U>::Convert(u);
25 }
26
27 template <typename U>
28 U To() const {
29 return mojo::TypeConverter<U, {{struct.name}}>::Convert(*this);
30 }
31
32 {{struct.name}}();
33 ~{{struct.name}}();
34
35 // Returns the number of bytes it would take to serialize this struct's data.
36 size_t GetSerializedSize() const;
37
38 // Returns true on successful serialization. On failure, part of the data may
39 // be serialized, until the point of failure. This API does not support
40 // serializing handles. If not null, |bytes_written| is set to the number of
41 // bytes written to |buf|, even if this function return false.
42 //
43 // TODO(vardhan): For now, we return true for success. Should we define a
44 // public error type for serialization? Should we open up
45 // internal::ValidationError?
46 bool Serialize(void* buf, size_t buf_size, size_t* bytes_written = nullptr);
47
48 // Deserializes the given |buf| of size |buf_size| representing a serialized
49 // version of this struct. The buffer is validated before it is deserialized.
50 // Returns true on successful deserialization.
51 // TODO(vardhan): Recover the validation error if there is one?
52 bool Deserialize(void* buf, size_t buf_size);
53
54 // Deserializes the given |buf| representing a serialized version of this
55 // struct. The buffer is NOT validated before it is deserialized, so the user
56 // must be confident of its validity and that |buf| points to enough data to
57 // finish deserializing.
58 void DeserializeWithoutValidation(void* buf);
59
60 {% if struct|is_cloneable_kind %}
61 {{struct.name}}Ptr Clone() const;
62 {%- endif %}
63 bool Equals(const {{struct.name}}& other) const;
64
65 {#--- Struct members #}
66 {% for field in struct.fields %}
67 {%- set type = field.kind|cpp_wrapper_type %}
68 {%- set name = field.name %}
69 {{type}} {{name}};
70 {%- endfor %}
71 };
72
73 {#--- Enum Operators #}
74 {% from "enum_macros.tmpl" import global_enum_operators_decl -%}
75 {%- for enum in struct.enums %}
76 {{global_enum_operators_decl(enum, class_name=struct.name)}}
77 {%- endfor %}
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698