| 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 `is_static` is relevant if this enum declaration is defined within a class, in | 3 `is_static` is relevant if this enum declaration is defined within a class, in |
| 4 which case associated functions need to be static. | 4 which case associated functions need to be static. |
| 5 ---#} | 5 ---#} |
| 6 {%- macro enum_decl(enum, is_static=false) %} | 6 {%- macro enum_decl(enum, is_static=false) %} |
| 7 {%- if enum.native_only %} |
| 8 using {{enum.name}} = {{enum|cpp_wrapper_type}}; |
| 9 {%- else %} |
| 7 enum class {{enum.name}} : int32_t { | 10 enum class {{enum.name}} : int32_t { |
| 8 {%- for field in enum.fields %} | 11 {%- for field in enum.fields %} |
| 9 {%- if field.value %} | 12 {%- if field.value %} |
| 10 {{field.name}} = {{field.value|expression_to_text}}, | 13 {{field.name}} = {{field.value|expression_to_text}}, |
| 11 {%- else %} | 14 {%- else %} |
| 12 {{field.name}}, | 15 {{field.name}}, |
| 13 {%- endif %} | 16 {%- endif %} |
| 14 {%- endfor %} | 17 {%- endfor %} |
| 15 }; | 18 }; |
| 16 {{is_valid_enum_decl(enum, is_static)}} | 19 {{is_valid_enum_decl(enum, is_static)}} |
| 20 {% endif %} |
| 17 {%- endmacro %} | 21 {%- endmacro %} |
| 18 | 22 |
| 19 {#--- macros for the declaration & definitions of enum-associated functions. | 23 {#--- macros for the declaration & definitions of enum-associated functions. |
| 20 Namely: | 24 Namely: |
| 21 * {enum_name}_IsValidValue: returns true if the given enum has a valid value | 25 * {enum_name}_IsValidValue: returns true if the given enum has a valid value |
| 22 for this generated version of enum. | 26 for this generated version of enum. |
| 23 ---#} | 27 ---#} |
| 24 | 28 |
| 25 {%- macro is_valid_enum_decl(enum, is_static=false) %} | 29 {%- macro is_valid_enum_decl(enum, is_static=false) %} |
| 26 {% if is_static %}static {% endif -%} | 30 {% if is_static %}static {% endif -%} |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 58 {{enum.name}}_IsValidValue({{enum.name}} value) { | 62 {{enum.name}}_IsValidValue({{enum.name}} value) { |
| 59 switch (static_cast<int32_t>(value)) { | 63 switch (static_cast<int32_t>(value)) { |
| 60 {%- for enum_field in enum.fields|groupby('numeric_value') %} | 64 {%- for enum_field in enum.fields|groupby('numeric_value') %} |
| 61 case {{enum_field[0]}}: | 65 case {{enum_field[0]}}: |
| 62 {%- endfor %} | 66 {%- endfor %} |
| 63 return true; | 67 return true; |
| 64 } | 68 } |
| 65 return false; | 69 return false; |
| 66 } | 70 } |
| 67 {%- endmacro %} | 71 {%- endmacro %} |
| OLD | NEW |