| OLD | NEW |
| 1 {#--- | 1 {#--- |
| 2 Macro for enum definition, and the declaration of associated functions. | 2 Macro for enum definition, and the declaration of associated functions. |
| 3 ---#} | 3 ---#} |
| 4 | 4 |
| 5 {%- macro enum_decl(enum) %} | 5 {%- macro enum_decl(enum) %} |
| 6 {%- set enum_name = enum|get_name_for_kind(flatten_nested_kind=True) %} | 6 {%- set enum_name = enum|get_name_for_kind(flatten_nested_kind=True) %} |
| 7 enum class {{enum_name}} : int32_t { | 7 enum class {{enum_name}} : int32_t { |
| 8 {%- for field in enum.fields %} | 8 {%- for field in enum.fields %} |
| 9 {%- if field.value %} | 9 {%- if field.value %} |
| 10 {{field.name}} = {{field.value|expression_to_text}}, | 10 {{field.name}} = {{field.value|expression_to_text}}, |
| (...skipping 27 matching lines...) Expand all Loading... |
| 38 return {{enum|get_name_for_kind(internal=True, | 38 return {{enum|get_name_for_kind(internal=True, |
| 39 flatten_nested_kind=True)}}::IsKnownValue( | 39 flatten_nested_kind=True)}}::IsKnownValue( |
| 40 static_cast<int32_t>(value)); | 40 static_cast<int32_t>(value)); |
| 41 } | 41 } |
| 42 {%- endmacro %} | 42 {%- endmacro %} |
| 43 | 43 |
| 44 {%- macro enum_data_decl(enum) %} | 44 {%- macro enum_data_decl(enum) %} |
| 45 {%- set enum_name = enum|get_name_for_kind(flatten_nested_kind=True) %} | 45 {%- set enum_name = enum|get_name_for_kind(flatten_nested_kind=True) %} |
| 46 struct {{enum_name}}_Data { | 46 struct {{enum_name}}_Data { |
| 47 public: | 47 public: |
| 48 static bool const kIsExtensible = {% if enum.extensible %}true{% else %}false{
% endif %}; | 48 static bool constexpr kIsExtensible = {% if enum.extensible %}true{% else %}fa
lse{% endif %}; |
| 49 | 49 |
| 50 static bool IsKnownValue(int32_t value) { | 50 static bool IsKnownValue(int32_t value) { |
| 51 {%- if enum.fields %} | 51 {%- if enum.fields %} |
| 52 switch (value) { | 52 switch (value) { |
| 53 {%- for enum_field in enum.fields|groupby('numeric_value') %} | 53 {%- for enum_field in enum.fields|groupby('numeric_value') %} |
| 54 case {{enum_field[0]}}: | 54 case {{enum_field[0]}}: |
| 55 {%- endfor %} | 55 {%- endfor %} |
| 56 return true; | 56 return true; |
| 57 } | 57 } |
| 58 {%- endif %} | 58 {%- endif %} |
| (...skipping 12 matching lines...) Expand all Loading... |
| 71 }; | 71 }; |
| 72 {%- endmacro %} | 72 {%- endmacro %} |
| 73 | 73 |
| 74 {%- macro enum_hash(enum) %} | 74 {%- macro enum_hash(enum) %} |
| 75 {%- set enum_name = enum|get_qualified_name_for_kind( | 75 {%- set enum_name = enum|get_qualified_name_for_kind( |
| 76 flatten_nested_kind=True) %} | 76 flatten_nested_kind=True) %} |
| 77 template <> | 77 template <> |
| 78 struct hash<{{enum_name}}> | 78 struct hash<{{enum_name}}> |
| 79 : public mojo::internal::EnumHashImpl<{{enum_name}}> {}; | 79 : public mojo::internal::EnumHashImpl<{{enum_name}}> {}; |
| 80 {%- endmacro %} | 80 {%- endmacro %} |
| OLD | NEW |