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

Unified Diff: mojo/public/tools/bindings/generators/cpp_templates/union_declaration.tmpl

Issue 2226853002: Mojo C++ bindings: add support for UnionTraits. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@85_10_inline_more
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 side-by-side diff with in-line comments
Download patch
Index: mojo/public/tools/bindings/generators/cpp_templates/union_declaration.tmpl
diff --git a/mojo/public/tools/bindings/generators/cpp_templates/union_declaration.tmpl b/mojo/public/tools/bindings/generators/cpp_templates/union_declaration.tmpl
index d65854073187bfc6aed181e11d6a8d55407820b5..005ba76b611fa0f1bc7cae6af20fa5cbc1413b82 100644
--- a/mojo/public/tools/bindings/generators/cpp_templates/union_declaration.tmpl
+++ b/mojo/public/tools/bindings/generators/cpp_templates/union_declaration.tmpl
@@ -7,23 +7,26 @@ class {{class_name}} {
// Used to identify Mojom Union Data Classes.
typedef void MojomUnionDataType;
+ {{class_name}}() {}
+ // Do nothing in the destructor since it won't be called when it is a
+ // non-inlined union.
+ ~{{class_name}}() {}
+
static {{class_name}}* New(mojo::internal::Buffer* buf) {
return new (buf->Allocate(sizeof({{class_name}}))) {{class_name}}();
}
- {{class_name}}();
- // Do nothing in the destructor since it won't be called.
- ~{{class_name}}() {}
-
static bool Validate(const void* data,
mojo::internal::ValidationContext* validation_context,
bool inlined);
- bool is_null() const {
- return size == 0;
- }
+ bool is_null() const { return size == 0; }
- void set_null();
+ void set_null() {
+ size = 0U;
+ tag = static_cast<{{enum_name}}>(0);
+ data.unknown = 0U;
+ }
enum class {{enum_name}} : uint32_t {
{% for field in union.fields %}

Powered by Google App Engine
This is Rietveld 408576698