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_DEVTOOLS_INTERNAL_TYPE_CONVERSIONS_{{domain.domain | cam
elcase_to_hacker_style | upper}}_H_ |
8 #define HEADLESS_PUBLIC_DOMAINS_TYPE_CONVERSIONS_H_ | 8 #define HEADLESS_PUBLIC_DEVTOOLS_INTERNAL_TYPE_CONVERSIONS_{{domain.domain | cam
elcase_to_hacker_style | upper}}_H_ |
9 | 9 |
10 #include "headless/public/domains/types.h" | 10 #include "headless/public/devtools/domains/types_{{domain.domain | camelcase_to_
hacker_style}}.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 type in domain.types %} |
17 {% for type in domain.types %} | 17 {% set namespace = domain.domain | camelcase_to_hacker_style %} |
18 {% set namespace = domain.domain | camelcase_to_hacker_style %} | 18 {% if "enum" in type %} |
19 {% if "enum" in type %} | |
20 template <> | 19 template <> |
21 struct FromValue<{{namespace}}::{{type.id}}> { | 20 struct FromValue<{{namespace}}::{{type.id}}> { |
22 static {{namespace}}::{{type.id}} Parse(const base::Value& value, ErrorReporte
r* errors) { | 21 static {{namespace}}::{{type.id}} Parse(const base::Value& value, ErrorReporte
r* errors) { |
23 {% set default = namespace + '::' + type.id + '::' + type.enum[0] | saniti
ze_literal | dash_to_camelcase | camelcase_to_hacker_style | upper %} | 22 {% set default = namespace + '::' + type.id + '::' + type.enum[0] | sanitize
_literal | dash_to_camelcase | camelcase_to_hacker_style | upper %} |
24 std::string string_value; | 23 std::string string_value; |
25 if (!value.GetAsString(&string_value)) { | 24 if (!value.GetAsString(&string_value)) { |
26 errors->AddError("string enum value expected"); | 25 errors->AddError("string enum value expected"); |
27 {# Return an arbitrary enum member -- the caller will just ignore it. #} | 26 {# Return an arbitrary enum member -- the caller will just ignore it. #} |
28 return {{default}}; | 27 return {{default}}; |
29 } | 28 } |
30 {% for literal in type.enum %} | 29 {% for literal in type.enum %} |
31 if (string_value == "{{literal}}") | 30 if (string_value == "{{literal}}") |
32 return {{namespace}}::{{type.id}}::{{literal | sanitize_literal | dash_to_
camelcase | camelcase_to_hacker_style | upper }}; | 31 return {{namespace}}::{{type.id}}::{{literal | sanitize_literal | dash_to_
camelcase | camelcase_to_hacker_style | upper }}; |
33 {% endfor %} | 32 {% endfor %} |
34 errors->AddError("invalid enum value"); | 33 errors->AddError("invalid enum value"); |
35 return {{default}}; | 34 return {{default}}; |
36 } | 35 } |
37 }; | 36 }; |
38 | 37 |
39 template <typename T> | 38 template <typename T> |
40 std::unique_ptr<base::Value> ToValueImpl(const {{namespace}}::{{type.id}}& value
, T*) { | 39 std::unique_ptr<base::Value> ToValueImpl(const {{namespace}}::{{type.id}}& value
, T*) { |
41 switch (value) { | 40 switch (value) { |
42 {% for literal in type.enum %} | 41 {% for literal in type.enum %} |
43 case {{namespace}}::{{type.id}}::{{literal | sanitize_literal | dash_to_came
lcase | camelcase_to_hacker_style | upper }}: | 42 case {{namespace}}::{{type.id}}::{{literal | sanitize_literal | dash_to_came
lcase | camelcase_to_hacker_style | upper }}: |
44 return base::WrapUnique(new base::StringValue("{{literal}}")); | 43 return base::WrapUnique(new base::StringValue("{{literal}}")); |
45 {% endfor %} | 44 {% endfor %} |
46 }; | 45 }; |
47 NOTREACHED(); | 46 NOTREACHED(); |
48 return nullptr; | 47 return nullptr; |
49 } | 48 } |
50 {% continue %} | 49 {% continue %} |
51 {% endif %} | 50 {% endif %} |
52 | 51 |
53 {% if not (type.type == "object") or not ("properties" in type) %}{% continu
e %}{% endif %} | 52 {% if not (type.type == "object") or not ("properties" in type) %}{% continue
%}{% endif %} |
54 template <> | 53 template <> |
55 struct FromValue<{{namespace}}::{{type.id}}> { | 54 struct FromValue<{{namespace}}::{{type.id}}> { |
56 static std::unique_ptr<{{namespace}}::{{type.id}}> Parse(const base::Value& va
lue, ErrorReporter* errors) { | 55 static std::unique_ptr<{{namespace}}::{{type.id}}> Parse(const base::Value& va
lue, ErrorReporter* errors) { |
57 return {{namespace}}::{{type.id}}::Parse(value, errors); | 56 return {{namespace}}::{{type.id}}::Parse(value, errors); |
58 } | 57 } |
59 }; | 58 }; |
60 | 59 |
61 template <typename T> | 60 template <typename T> |
62 std::unique_ptr<base::Value> ToValueImpl(const {{namespace}}::{{type.id}}& value
, T*) { | 61 std::unique_ptr<base::Value> ToValueImpl(const {{namespace}}::{{type.id}}& value
, T*) { |
63 return value.Serialize(); | 62 return value.Serialize(); |
64 } | 63 } |
65 | 64 |
66 {% endfor %} | |
67 {% endfor %} | 65 {% endfor %} |
68 | 66 |
69 template <typename T> | |
70 std::unique_ptr<base::Value> ToValue(const T& value) { | |
71 return ToValueImpl(value, static_cast<T*>(nullptr)); | |
72 } | |
73 | |
74 } // namespace internal | 67 } // namespace internal |
75 } // namespace headless | 68 } // namespace headless |
76 | 69 |
77 #endif // HEADLESS_PUBLIC_DOMAINS_TYPE_CONVERSIONS_H_ | 70 #endif // HEADLESS_PUBLIC_DEVTOOLS_INTERNAL_TYPE_CONVERSIONS_{{domain.domain |
camelcase_to_hacker_style | upper}}_H_ |
OLD | NEW |