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

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

Issue 923033003: Implement unions as members of structs. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 5 years, 9 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 6e6fe95a74c1dc207af7f5d252494a1936fd7e14..bc77c112dd0f010dbd0d4f817d648c4e0031c4f4 100644
--- a/mojo/public/tools/bindings/generators/cpp_templates/union_declaration.tmpl
+++ b/mojo/public/tools/bindings/generators/cpp_templates/union_declaration.tmpl
@@ -4,10 +4,22 @@
class {{class_name}} {
public:
+ // Used to identify Mojom Union Data Classes.
+ typedef void MojomUnionDataType;
static {{class_name}}* New(mojo::internal::Buffer* buf);
+ {{class_name}}();
+ // Do nothing in the destructor since it won't be called.
+ ~{{class_name}}() {}
static bool Validate(const void* data,
- mojo::internal::BoundsChecker* bounds_checker);
+ mojo::internal::BoundsChecker* bounds_checker,
+ bool inlined);
+
+ bool is_null() const {
+ return size == 0;
+ }
+
+ void set_null();
enum class {{enum_name}} : uint32_t {
{% for field in union.fields %}
@@ -33,16 +45,12 @@ class {{class_name}} {
uint64_t unknown;
};
- uint32_t reserved;
+ uint32_t size;
{{enum_name}} tag;
Union_ data;
void EncodePointersAndHandles(std::vector<mojo::Handle>* handles);
void DecodePointersAndHandles(std::vector<mojo::Handle>* handles);
-
- private:
- {{class_name}}();
- ~{{class_name}}() = delete;
};
static_assert(sizeof({{class_name}}) == 16,
"Bad sizeof({{class_name}})");

Powered by Google App Engine
This is Rietveld 408576698