Chromium Code Reviews| 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 d11b198bc658d7623e77a8611659a98d8a118e92..19dcfd63db5ac3d1e77a67a6123892ac4c726c24 100644 |
| --- a/mojo/public/tools/bindings/generators/cpp_templates/enum_macros.tmpl |
| +++ b/mojo/public/tools/bindings/generators/cpp_templates/enum_macros.tmpl |
| @@ -4,16 +4,20 @@ |
| which case associated functions need to be static. |
| ---#} |
| {%- macro enum_decl(enum, is_static=false) %} |
| +{%- 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 %} |
| }; |
| {{is_valid_enum_decl(enum, is_static)}} |
| +{% endif %} |
|
yzshen1
2016/01/26 04:36:29
nit: "{%-" (and also line 54)
|
| {%- endmacro %} |
| {#--- macros for the declaration & definitions of enum-associated functions. |
| @@ -28,40 +32,44 @@ bool {{enum.name}}_IsValidValue({{enum.name}} value); |
| {%- endmacro %} |
| {%- 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_valid_enum_def(enum, class_name = '') %} |
| -{% if class_name != '' -%} |
| +{%- if not enum.native_only %} |
| +{% if class_name != '' -%} |
| // static |
| bool {{class_name}}:: |
| -{%- else -%} |
| +{%- else -%} |
| {{"bool "}} |
| -{%- endif -%} |
| +{%- endif -%} |
| {{enum.name}}_IsValidValue({{enum.name}} value) { |
| switch (static_cast<int32_t>(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 %} |
| {%- endmacro %} |