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

Unified Diff: third_party/mojo/src/mojo/public/tools/bindings/generators/cpp_templates/union_definition.tmpl

Issue 910883002: Update mojo sdk to rev 8af2ccff2eee4bfca1043015abee30482a030b30 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Apply 9f87aeadbda22441b7d469e596f7bd7d0d73e2a8 (https://codereview.chromium.org/908973002/) 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 side-by-side diff with in-line comments
Download patch
Index: third_party/mojo/src/mojo/public/tools/bindings/generators/cpp_templates/union_definition.tmpl
diff --git a/third_party/mojo/src/mojo/public/tools/bindings/generators/cpp_templates/union_definition.tmpl b/third_party/mojo/src/mojo/public/tools/bindings/generators/cpp_templates/union_definition.tmpl
new file mode 100644
index 0000000000000000000000000000000000000000..9f6f02f0d8a525d480effd45bccce100619bfbfc
--- /dev/null
+++ b/third_party/mojo/src/mojo/public/tools/bindings/generators/cpp_templates/union_definition.tmpl
@@ -0,0 +1,54 @@
+{%- import "validation_macros.tmpl" as validation_macros %}
+{%- set class_name = union.name ~ "_Data" %}
+{%- set enum_name = union.name ~ "_Tag" -%}
+
+// static
+{{class_name}}* {{class_name}}::New(mojo::internal::Buffer* buf) {
+ return new (buf->Allocate(sizeof({{class_name}}))) {{class_name}}();
+}
+
+// static
+bool {{class_name}}::Validate(const void* data,
+ mojo::internal::BoundsChecker* bounds_checker) {
+ if (!data) {
+ return true;
+ }
+
+ if (!mojo::internal::IsAligned(data)) {
+ ReportValidationError(mojo::internal::VALIDATION_ERROR_MISALIGNED_OBJECT);
+ return false;
+ }
+
+ if (!bounds_checker->ClaimMemory(data, sizeof({{class_name}}))) {
+ ReportValidationError(
+ mojo::internal::VALIDATION_ERROR_ILLEGAL_MEMORY_RANGE);
+ return false;
+ }
+ const {{class_name}}* object = static_cast<const {{class_name}}*>(data);
+ MOJO_ALLOW_UNUSED_LOCAL(object);
+
+ switch (object->tag) {
+{% for field in union.fields %}
+ case {{enum_name}}::{{field.name|upper}}:
+{{ validation_macros.validate_union_field(field, union)|indent(6) }}
+{%- endfor %}
+ default:
+ ReportValidationError(
+ mojo::internal::VALIDATION_ERROR_UNKOWN_UNION_TAG,
+ "unknown tag in {{union.name}}");
+ return false;
+ }
+}
+
+{{class_name}}::{{class_name}}() {
+}
+
+void {{class_name}}::EncodePointersAndHandles(
+ std::vector<mojo::Handle>* handles) {
+ // TODO(azani): Implement pointers and handles.
+}
+
+void {{class_name}}::DecodePointersAndHandles(
+ std::vector<mojo::Handle>* handles) {
+ // TODO(azani): Implement pointers and handles.
+}

Powered by Google App Engine
This is Rietveld 408576698