OLD | NEW |
1 // This file is generated | 1 // This file is generated |
2 | 2 |
3 // Copyright 2016 The Chromium Authors. All rights reserved. | 3 // Copyright 2016 The Chromium Authors. All rights reserved. |
4 // Use of this source code is governed by a BSD-style license that can be | 4 // Use of this source code is governed by a BSD-style license that can be |
5 // found in the LICENSE file. | 5 // found in the LICENSE file. |
6 | 6 |
7 #ifndef HEADLESS_PUBLIC_DOMAINS_TYPE_CONVERSIONS_H_ | 7 #ifndef HEADLESS_PUBLIC_DOMAINS_TYPE_CONVERSIONS_H_ |
8 #define HEADLESS_PUBLIC_DOMAINS_TYPE_CONVERSIONS_H_ | 8 #define HEADLESS_PUBLIC_DOMAINS_TYPE_CONVERSIONS_H_ |
9 | 9 |
10 #include "headless/public/domains/types.h" | 10 #include "headless/public/domains/types.h" |
11 #include "headless/public/internal/value_conversions.h" | 11 #include "headless/public/internal/value_conversions.h" |
12 | 12 |
13 namespace headless { | 13 namespace headless { |
14 namespace internal { | 14 namespace internal { |
15 | 15 |
16 {% for domain in api.domains %} | 16 {% for domain in api.domains %} |
17 {% for type in domain.types %} | 17 {% for type in domain.types %} |
18 {% set namespace = domain.domain | camelcase_to_hacker_style %} | 18 {% set namespace = domain.domain | camelcase_to_hacker_style %} |
19 {% if "enum" in type %} | 19 {% if "enum" in type %} |
20 template <> | 20 template <> |
21 struct FromValue<{{namespace}}::{{type.id}}> { | 21 struct FromValue<{{namespace}}::{{type.id}}> { |
22 static {{namespace}}::{{type.id}} Parse(const base::Value& value, ErrorReporte
r* errors) { | 22 static {{namespace}}::{{type.id}} Parse(const base::Value& value, ErrorReporte
r* errors) { |
23 {% set default = namespace + '::' + type.id + '::' + type.enum[0] | dash_t
o_camelcase | camelcase_to_hacker_style | upper | mangle_enum %} | 23 {% set default = namespace + '::' + type.id + '::' + type.enum[0] | saniti
ze_literal | dash_to_camelcase | camelcase_to_hacker_style | upper %} |
24 std::string string_value; | 24 std::string string_value; |
25 if (!value.GetAsString(&string_value)) { | 25 if (!value.GetAsString(&string_value)) { |
26 errors->AddError("string enum value expected"); | 26 errors->AddError("string enum value expected"); |
27 {# Return an arbitrary enum member -- the caller will just ignore it. #} | 27 {# Return an arbitrary enum member -- the caller will just ignore it. #} |
28 return {{default}}; | 28 return {{default}}; |
29 } | 29 } |
30 {% for literal in type.enum %} | 30 {% for literal in type.enum %} |
31 if (string_value == "{{literal}}") | 31 if (string_value == "{{literal}}") |
32 return {{namespace}}::{{type.id}}::{{literal | dash_to_camelcase | camelca
se_to_hacker_style | upper | mangle_enum}}; | 32 return {{namespace}}::{{type.id}}::{{literal | sanitize_literal | dash_to_
camelcase | camelcase_to_hacker_style | upper }}; |
33 {% endfor %} | 33 {% endfor %} |
34 errors->AddError("invalid enum value"); | 34 errors->AddError("invalid enum value"); |
35 return {{default}}; | 35 return {{default}}; |
36 } | 36 } |
37 }; | 37 }; |
38 | 38 |
39 template <typename T> | 39 template <typename T> |
40 std::unique_ptr<base::Value> ToValueImpl(const {{namespace}}::{{type.id}}& value
, T*) { | 40 std::unique_ptr<base::Value> ToValueImpl(const {{namespace}}::{{type.id}}& value
, T*) { |
41 switch (value) { | 41 switch (value) { |
42 {% for literal in type.enum %} | 42 {% for literal in type.enum %} |
43 case {{namespace}}::{{type.id}}::{{literal | dash_to_camelcase | camelcase_t
o_hacker_style | upper | mangle_enum}}: | 43 case {{namespace}}::{{type.id}}::{{literal | sanitize_literal | dash_to_came
lcase | camelcase_to_hacker_style | upper }}: |
44 return base::WrapUnique(new base::StringValue("{{literal}}")); | 44 return base::WrapUnique(new base::StringValue("{{literal}}")); |
45 {% endfor %} | 45 {% endfor %} |
46 }; | 46 }; |
47 NOTREACHED(); | 47 NOTREACHED(); |
48 return nullptr; | 48 return nullptr; |
49 } | 49 } |
50 {% continue %} | 50 {% continue %} |
51 {% endif %} | 51 {% endif %} |
52 | 52 |
53 {% if not (type.type == "object") or not ("properties" in type) %}{% continu
e %}{% endif %} | 53 {% if not (type.type == "object") or not ("properties" in type) %}{% continu
e %}{% endif %} |
(...skipping 14 matching lines...) Expand all Loading... |
68 | 68 |
69 template <typename T> | 69 template <typename T> |
70 std::unique_ptr<base::Value> ToValue(const T& value) { | 70 std::unique_ptr<base::Value> ToValue(const T& value) { |
71 return ToValueImpl(value, static_cast<T*>(nullptr)); | 71 return ToValueImpl(value, static_cast<T*>(nullptr)); |
72 } | 72 } |
73 | 73 |
74 } // namespace internal | 74 } // namespace internal |
75 } // namespace headless | 75 } // namespace headless |
76 | 76 |
77 #endif // HEADLESS_PUBLIC_DOMAINS_TYPE_CONVERSIONS_H_ | 77 #endif // HEADLESS_PUBLIC_DOMAINS_TYPE_CONVERSIONS_H_ |
OLD | NEW |