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

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

Issue 2797793002: Remove base::underlying_type, replace uses with std::underlying_type (Closed)
Patch Set: underlyingtype: rm-tests Created 3 years, 8 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 unified diff | Download patch
« no previous file with comments | « mojo/public/cpp/bindings/lib/bindings_internal.h ('k') | net/http2/http2_structures_test.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
88 flatten_nested_kind=True, include_variant=False) %} 88 flatten_nested_kind=True, include_variant=False) %}
89 {%- set hash_fn_name = enum|wtf_hash_fn_name_for_enum %} 89 {%- set hash_fn_name = enum|wtf_hash_fn_name_for_enum %}
90 {# We need two unused enum values: #} 90 {# We need two unused enum values: #}
91 {%- set empty_value = -1000000 %} 91 {%- set empty_value = -1000000 %}
92 {%- set deleted_value = -1000001 %} 92 {%- set deleted_value = -1000001 %}
93 {%- set empty_value_unused = "false" if empty_value in enum|all_enum_values el se "true" %} 93 {%- set empty_value_unused = "false" if empty_value in enum|all_enum_values el se "true" %}
94 {%- set deleted_value_unused = "false" if empty_value in enum|all_enum_values else "true" %} 94 {%- set deleted_value_unused = "false" if empty_value in enum|all_enum_values else "true" %}
95 namespace WTF { 95 namespace WTF {
96 struct {{hash_fn_name}} { 96 struct {{hash_fn_name}} {
97 static unsigned hash(const {{enum_name}}& value) { 97 static unsigned hash(const {{enum_name}}& value) {
98 typedef base::underlying_type<{{enum_name}}>::type utype; 98 using utype = std::underlying_type<{{enum_name}}>::type;
99 return DefaultHash<utype>::Hash().hash(static_cast<utype>(value)); 99 return DefaultHash<utype>::Hash().hash(static_cast<utype>(value));
100 } 100 }
101 static bool equal(const {{enum_name}}& left, const {{enum_name}}& right) { 101 static bool equal(const {{enum_name}}& left, const {{enum_name}}& right) {
102 return left == right; 102 return left == right;
103 } 103 }
104 static const bool safeToCompareToEmptyOrDeleted = true; 104 static const bool safeToCompareToEmptyOrDeleted = true;
105 }; 105 };
106 106
107 template <> 107 template <>
108 struct DefaultHash<{{enum_name}}> { 108 struct DefaultHash<{{enum_name}}> {
(...skipping 13 matching lines...) Expand all
122 } 122 }
123 static void constructDeletedValue({{enum_name}}& slot, bool) { 123 static void constructDeletedValue({{enum_name}}& slot, bool) {
124 slot = static_cast<{{enum_name}}>({{deleted_value}}); 124 slot = static_cast<{{enum_name}}>({{deleted_value}});
125 } 125 }
126 static bool isDeletedValue(const {{enum_name}}& value) { 126 static bool isDeletedValue(const {{enum_name}}& value) {
127 return value == static_cast<{{enum_name}}>({{deleted_value}}); 127 return value == static_cast<{{enum_name}}>({{deleted_value}});
128 } 128 }
129 }; 129 };
130 } // namespace WTF 130 } // namespace WTF
131 {%- endmacro %} 131 {%- endmacro %}
OLDNEW
« no previous file with comments | « mojo/public/cpp/bindings/lib/bindings_internal.h ('k') | net/http2/http2_structures_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698