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

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

Issue 1375313006: For c++, Generate enum classes instead of enum from mojom. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 5 years, 3 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 0e44acd57e65ce0bc4b131b73b8d5924eb3dd8a3..269fafc4942976b7dcbf7134328e7514134fb73f 100644
--- a/mojo/public/tools/bindings/generators/cpp_templates/enum_macros.tmpl
+++ b/mojo/public/tools/bindings/generators/cpp_templates/enum_macros.tmpl
@@ -4,12 +4,12 @@
which case associated functions need to be static.
---#}
{%- macro enum_decl(enum, is_static=false) %}
-enum {{enum.name}} : int32_t {
+enum class {{enum.name}} : int32_t {
{%- for field in enum.fields %}
{%- if field.value %}
- {{enum.name|to_all_caps}}_{{field.name}} = {{field.value|expression_to_text}},
+ {{field.name}} = {{field.value|expression_to_text}},
{%- else %}
- {{enum.name|to_all_caps}}_{{field.name}},
+ {{field.name}},
{%- endif %}
{%- endfor %}
};
@@ -44,3 +44,19 @@ bool {{class_name}}::
return false;
}
{%- endmacro %}
+
+{%- macro global_enum_operators_decl(enum, class_name = '') %}
+{% if class_name != '' -%}
+static inline std::ostream& operator<<(
viettrungluu 2015/10/01 17:49:55 You need to include appropriate headers for std::o
johngro 2015/10/02 00:49:04 Done.
+ std::ostream& stream,
+ const {{class_name}}::{{enum.name}}& val) {
+ return (stream << static_cast<typename std::underlying_type<{{class_name}}::{{enum.name}}>::type>(val));
viettrungluu 2015/10/01 17:49:55 The underlying type for our enums is always int32_
johngro 2015/10/02 00:49:04 Done.
+}
+{%- else -%}
+static inline std::ostream& operator<<(
+ std::ostream& stream,
+ const {{enum.name}}& val) {
+ return (stream << static_cast<typename std::underlying_type<{{enum.name}}>::type>(val));
+}
+{%- endif -%}
+{%- endmacro %}

Powered by Google App Engine
This is Rietveld 408576698