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

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

Issue 1635613002: [mojo-bindings] Support reuse of native enum classes (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix more missing public_deps Created 4 years, 11 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/enum_macros.tmpl
diff --git a/mojo/public/tools/bindings/generators/cpp_templates/enum_macros.tmpl b/mojo/public/tools/bindings/generators/cpp_templates/enum_macros.tmpl
index 745ebf6bd189eef8d44de98515599f79397ba2bf..4b30ca73c811116fc5093fd4ba6bfcd2bd713140 100644
--- a/mojo/public/tools/bindings/generators/cpp_templates/enum_macros.tmpl
+++ b/mojo/public/tools/bindings/generators/cpp_templates/enum_macros.tmpl
@@ -2,15 +2,19 @@
Macro for enum definition, and the declaration of associated functions.
---#}
{%- macro enum_decl(enum) %}
+{%- if enum.native_only %}
+using {{enum.name}} = {{enum|cpp_wrapper_type}};
+{%- else %}
enum class {{enum.name}} : int32_t {
-{%- for field in enum.fields %}
-{%- if field.value %}
+{%- for field in enum.fields %}
+{%- if field.value %}
{{field.name}} = {{field.value|expression_to_text}},
-{%- else %}
+{%- else %}
{{field.name}},
-{%- endif %}
-{%- endfor %}
+{%- endif %}
+{%- endfor %}
};
+{%- endif %}
{%- endmacro %}
{%- macro enum_data_decl(enum) %}
@@ -22,13 +26,17 @@ struct {{enum.name}}_Data {
static bool const kIsExtensible = {% if enum.extensible %}true{% else %}false{% endif %};
static bool IsKnownValue(int32_t value) {
+{%- if enum.native_only %}
+ return mojo::EnumTraits<{{enum|cpp_wrapper_type}}>::IsKnownValue(value);
+{%- else %}
switch (value) {
-{%- for enum_field in enum.fields|groupby('numeric_value') %}
+{%- for enum_field in enum.fields|groupby('numeric_value') %}
case {{enum_field[0]}}:
-{%- endfor %}
+{%- endfor %}
return true;
}
return false;
+{%- endif %}
}
int32_t value;
@@ -42,24 +50,26 @@ struct {{enum.name}}_Data {
---#}
{%- macro enum_stream_operator(enum) %}
+{%- if not enum.native_only %}
inline std::ostream& operator<<(std::ostream& os, {{enum|get_name_for_kind}} value) {
switch(value) {
-{%- for _, values in enum.fields|groupby('numeric_value') %}
+{%- for _, values in enum.fields|groupby('numeric_value') %}
case {{enum|get_name_for_kind}}::{{values[0].name}}:
return os << "{{enum|get_name_for_kind}}::
-{%- if values|length > 1 -%}
+{%- if values|length > 1 -%}
{{'{'}}
-{%- endif -%}
+{%- endif -%}
{{values|map(attribute='name')|join(', ')}}
-{%- if values|length > 1 -%}
+{%- if values|length > 1 -%}
{{'}'}}
-{%- endif -%}
+{%- endif -%}
";
-{%- endfor %}
+{%- endfor %}
default:
return os << "Unknown {{enum|get_name_for_kind}} value: " << static_cast<int32_t>(value);
}
}
+{%- endif %}
{%- endmacro %}
{%- macro is_known_enum_value(enum) %}
« no previous file with comments | « mojo/public/cpp/bindings/enum_traits.h ('k') | mojo/public/tools/bindings/generators/cpp_templates/module.h.tmpl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698