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

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

Issue 2247083003: Mojo C++ bindings: extract code shared by different variants. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: . Created 4 years, 4 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 {%- set mojom_type = enum|get_qualified_name_for_kind %} 1 {%- set mojom_type = enum|get_qualified_name_for_kind(
2 flatten_nested_kind=True) %}
2 3
3 template <> 4 template <>
4 struct EnumTraits<{{mojom_type}}, {{mojom_type}}> { 5 struct EnumTraits<{{mojom_type}}, {{mojom_type}}> {
5 static {{mojom_type}} ToMojom({{mojom_type}} input) { return input; } 6 static {{mojom_type}} ToMojom({{mojom_type}} input) { return input; }
6 static bool FromMojom({{mojom_type}} input, {{mojom_type}}* output) { 7 static bool FromMojom({{mojom_type}} input, {{mojom_type}}* output) {
7 *output = input; 8 *output = input;
8 return true; 9 return true;
9 } 10 }
10 }; 11 };
11 12
12 namespace internal { 13 namespace internal {
13 14
14 template <typename MaybeConstUserType> 15 template <typename MaybeConstUserType>
15 struct Serializer<{{mojom_type}}, MaybeConstUserType> { 16 struct Serializer<{{mojom_type}}, MaybeConstUserType> {
16 using UserType = typename std::remove_const<MaybeConstUserType>::type; 17 using UserType = typename std::remove_const<MaybeConstUserType>::type;
17 using Traits = EnumTraits<{{mojom_type}}, UserType>; 18 using Traits = EnumTraits<{{mojom_type}}, UserType>;
18 19
19 static void Serialize(UserType input, int32_t* output) { 20 static void Serialize(UserType input, int32_t* output) {
20 *output = static_cast<int32_t>(Traits::ToMojom(input)); 21 *output = static_cast<int32_t>(Traits::ToMojom(input));
21 } 22 }
22 23
23 static bool Deserialize(int32_t input, UserType* output) { 24 static bool Deserialize(int32_t input, UserType* output) {
24 return Traits::FromMojom(static_cast<{{mojom_type}}>(input), output); 25 return Traits::FromMojom(static_cast<{{mojom_type}}>(input), output);
25 } 26 }
26 }; 27 };
27 28
28 } // namespace internal 29 } // namespace internal
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698