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

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

Issue 2635153002: Pref service: expose all read-only PrefStores through Mojo (Closed)
Patch Set: Remove debug print Created 3 years, 9 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
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 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 %}
81
82 {%- macro enum_hash_blink(enum) %}
83 {%- set enum_name = enum|get_qualified_name_for_kind(
84 flatten_nested_kind=True, include_variant=False) %}
85 {%- set hash_fn_name = enum|get_name_for_kind ~ "HashFn" %}
86 {%- set empty_value = -1000 %}
87 {%- set deleted_value = -1001 %}
88 namespace WTF {
89 struct {{hash_fn_name}} {
90 static unsigned hash(const {{enum_name}}& value) {
91 return 0; // TODO(tibell): Implement.
92 }
93 static bool equal(const {{enum_name}}& left, const {{enum_name}}& right) {
94 return left == right;
95 }
96 static const bool safeToCompareToEmptyOrDeleted = true;
97 };
98
99 template <>
100 struct DefaultHash<{{enum_name}}> {
101 using Hash = {{hash_fn_name}};
102 };
103
104 template <>
105 struct HashTraits<{{enum_name}}>
106 : public GenericHashTraits<{{enum_name}}> {
107 static const bool hasIsEmptyValueFunction = true;
108 static bool isEmptyValue(const {{enum_name}}& value) {
109 return value == static_cast<{{enum_name}}>({{empty_value}});
110 }
111 static void constructDeletedValue({{enum_name}}& slot, bool) {
112 slot = static_cast<{{enum_name}}>({{deleted_value}});
113 }
114 static bool isDeletedValue(const {{enum_name}}& value) {
115 return value == static_cast<{{enum_name}}>({{deleted_value}});
116 }
117 };
118 } // namespace WTF
119 {%- endmacro %}
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698