| 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) %}
|
|
|