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 9400ca77041e65cf319e0512101d619d4b63ecb6..92073bc5d5973e07791753c57e3de40799b4e286 100644 |
--- a/mojo/public/tools/bindings/generators/cpp_templates/enum_macros.tmpl |
+++ b/mojo/public/tools/bindings/generators/cpp_templates/enum_macros.tmpl |
@@ -78,3 +78,50 @@ template <> |
struct hash<{{enum_name}}> |
: public mojo::internal::EnumHashImpl<{{enum_name}}> {}; |
{%- endmacro %} |
+ |
+{%- macro enum_hash_blink(enum) %} |
+{%- set enum_name = enum|get_qualified_name_for_kind( |
+ flatten_nested_kind=True, include_variant=False) %} |
+{%- set hash_fn_name = enum|wtf_hash_fn_name_for_enum %} |
+{# We need two unused enum values: #} |
+{%- set empty_value = -1000000 %} |
+{%- set deleted_value = -1000001 %} |
+{%- set empty_value_unused = "false" if empty_value in enum|all_enum_values else "true" %} |
+{%- set deleted_value_unused = "false" if empty_value in enum|all_enum_values else "true" %} |
+namespace WTF { |
+struct {{hash_fn_name}} { |
+ static unsigned hash(const {{enum_name}}& value) { |
+ typedef base::underlying_type<{{enum_name}}>::type utype; |
+ return DefaultHash<utype>::Hash().hash(static_cast<utype>(value)); |
+ } |
+ static bool equal(const {{enum_name}}& left, const {{enum_name}}& right) { |
+ return left == right; |
+ } |
+ static const bool safeToCompareToEmptyOrDeleted = true; |
+}; |
+ |
+template <> |
+struct DefaultHash<{{enum_name}}> { |
+ using Hash = {{hash_fn_name}}; |
+}; |
+ |
+template <> |
+struct HashTraits<{{enum_name}}> |
+ : public GenericHashTraits<{{enum_name}}> { |
+ static_assert({{empty_value_unused}}, |
+ "{{empty_value}} is a reserved enum value"); |
+ static_assert({{deleted_value_unused}}, |
+ "{{deleted_value}} is a reserved enum value"); |
+ static const bool hasIsEmptyValueFunction = true; |
+ static bool isEmptyValue(const {{enum_name}}& value) { |
+ return value == static_cast<{{enum_name}}>({{empty_value}}); |
+ } |
+ static void constructDeletedValue({{enum_name}}& slot, bool) { |
+ slot = static_cast<{{enum_name}}>({{deleted_value}}); |
+ } |
+ static bool isDeletedValue(const {{enum_name}}& value) { |
+ return value == static_cast<{{enum_name}}>({{deleted_value}}); |
+ } |
+}; |
+} // namespace WTF |
+{%- endmacro %} |