| OLD | NEW |
| 1 // This file is generated | 1 // This file is generated |
| 2 | 2 |
| 3 // Copyright (c) 2016 The Chromium Authors. All rights reserved. | 3 // Copyright (c) 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_TYPES_H_ | 7 #ifndef HEADLESS_PUBLIC_DEVTOOLS_DOMAINS_TYPES_{{domain.domain | camelcase_to_ha
cker_style | upper}}_H_ |
| 8 #define HEADLESS_PUBLIC_DOMAINS_TYPES_H_ | 8 #define HEADLESS_PUBLIC_DEVTOOLS_DOMAINS_TYPES_{{domain.domain | camelcase_to_ha
cker_style | upper}}_H_ |
| 9 | 9 |
| 10 #include "base/optional.h" | 10 #include "base/optional.h" |
| 11 #include "base/values.h" | 11 #include "base/values.h" |
| 12 {% for domain_name in domain.dependencies %} |
| 13 #include "headless/public/devtools/internal/types_forward_declaration_{{domain_n
ame | camelcase_to_hacker_style}}.h" |
| 14 {% endfor %} |
| 12 #include "headless/public/headless_export.h" | 15 #include "headless/public/headless_export.h" |
| 13 #include "headless/public/util/error_reporter.h" | 16 #include "headless/public/util/error_reporter.h" |
| 14 | 17 |
| 15 #include "base/memory/ptr_util.h" | 18 #include "base/memory/ptr_util.h" |
| 16 | 19 |
| 17 namespace headless { | 20 namespace headless { |
| 18 | 21 |
| 19 // ------------- Forward declarations and typedefs. | 22 namespace {{domain.domain | camelcase_to_hacker_style}} { |
| 23 {% for type in domain.types %} |
| 24 {% if not (type.type == "object") or not ("properties" in type) %}{% continue
%}{% endif %} |
| 20 | 25 |
| 21 {% for domain in api.domains %} | 26 {% if type.description %} |
| 22 | |
| 23 namespace {{domain.domain | camelcase_to_hacker_style}} { | |
| 24 {% for type in domain.types %} | |
| 25 {% if type.type == "object" %} | |
| 26 {% if "properties" in type %} | |
| 27 class {{type.id}}; | |
| 28 {% else %} | |
| 29 using {{type.id}} = base::Value; | |
| 30 {% endif %} | |
| 31 {% endif %} | |
| 32 {% endfor %} | |
| 33 } // namespace {{domain.domain}} | |
| 34 {% endfor %} | |
| 35 | |
| 36 {% for domain in api.domains %} | |
| 37 namespace {{domain.domain | camelcase_to_hacker_style}} { | |
| 38 {% for type in domain.types %} | |
| 39 {% if "enum" in type %} | |
| 40 enum class {{type.id}} { | |
| 41 {% for literal in type.enum %} | |
| 42 {{ literal | sanitize_literal | dash_to_camelcase | camelcase_to_hacker_style
| upper }}{{',' if not loop.last}} | |
| 43 {% endfor %} | |
| 44 }; | |
| 45 | |
| 46 {% endif %} | |
| 47 {% endfor %} | |
| 48 } // namespace {{domain.domain | camelcase_to_hacker_style}} | |
| 49 | |
| 50 {% endfor %} | |
| 51 | |
| 52 // ------------- Type and builder declarations. | |
| 53 {% for domain in api.domains %} | |
| 54 | |
| 55 namespace {{domain.domain | camelcase_to_hacker_style}} { | |
| 56 {% for type in domain.types %} | |
| 57 {% if not (type.type == "object") or not ("properties" in type) %}{% continu
e %}{% endif %} | |
| 58 | |
| 59 {% if type.description %} | |
| 60 // {{type.description}} | 27 // {{type.description}} |
| 61 {% endif %} | 28 {% endif %} |
| 62 class HEADLESS_EXPORT {{type.id}} { | 29 class HEADLESS_EXPORT {{type.id}} { |
| 63 public: | 30 public: |
| 64 static {{resolve_type(type).pass_type}} Parse(const base::Value& value, ErrorR
eporter* errors); | 31 static {{resolve_type(type).pass_type}} Parse(const base::Value& value, ErrorR
eporter* errors); |
| 65 ~{{type.id}}() { } | 32 ~{{type.id}}() { } |
| 66 {% for property in type.properties %} | 33 {% for property in type.properties %} |
| 67 | 34 |
| 68 {% if property.description %} | 35 {% if property.description %} |
| 69 // {{property.description}} | 36 // {{property.description}} |
| 70 {% endif %} | 37 {% endif %} |
| 71 {% if property.optional %} | 38 {% if property.optional %} |
| 72 bool Has{{property.name | to_title_case}}() const { return !!{{property.name |
camelcase_to_hacker_style}}_; } | 39 bool Has{{property.name | to_title_case}}() const { return !!{{property.name |
camelcase_to_hacker_style}}_; } |
| 73 {{resolve_type(property).raw_return_type}} Get{{property.name | to_title_case}
}() const { DCHECK(Has{{property.name | to_title_case}}()); return {{resolve_typ
e(property).to_raw_return_type % ("%s_.value()" % property.name | camelcase_to_h
acker_style)}}; } | 40 {{resolve_type(property).raw_return_type}} Get{{property.name | to_title_case}
}() const { DCHECK(Has{{property.name | to_title_case}}()); return {{resolve_typ
e(property).to_raw_return_type % ("%s_.value()" % property.name | camelcase_to_h
acker_style)}}; } |
| 74 void Set{{property.name | to_title_case}}({{resolve_type(property).pass_type}}
value) { {{property.name | camelcase_to_hacker_style}}_ = {{resolve_type(proper
ty).to_pass_type % 'value'}}; } | 41 void Set{{property.name | to_title_case}}({{resolve_type(property).pass_type}}
value) { {{property.name | camelcase_to_hacker_style}}_ = {{resolve_type(proper
ty).to_pass_type % 'value'}}; } |
| 75 {% else %} | 42 {% else %} |
| 76 {{resolve_type(property).raw_return_type}} Get{{property.name | to_title_case}
}() const { return {{resolve_type(property).to_raw_return_type % ("%s_" % proper
ty.name | camelcase_to_hacker_style)}}; } | 43 {{resolve_type(property).raw_return_type}} Get{{property.name | to_title_case}
}() const { return {{resolve_type(property).to_raw_return_type % ("%s_" % proper
ty.name | camelcase_to_hacker_style)}}; } |
| 77 void Set{{property.name | to_title_case}}({{resolve_type(property).pass_type}}
value) { {{property.name | camelcase_to_hacker_style}}_ = {{resolve_type(proper
ty).to_pass_type % 'value'}}; } | 44 void Set{{property.name | to_title_case}}({{resolve_type(property).pass_type}}
value) { {{property.name | camelcase_to_hacker_style}}_ = {{resolve_type(proper
ty).to_pass_type % 'value'}}; } |
| 78 {% endif %} | 45 {% endif %} |
| 79 {% endfor %} | 46 {% endfor %} |
| 80 | 47 |
| 81 std::unique_ptr<base::Value> Serialize() const; | 48 std::unique_ptr<base::Value> Serialize() const; |
| 82 {{resolve_type(type).pass_type}} Clone() const; | 49 {{resolve_type(type).pass_type}} Clone() const; |
| 83 | 50 |
| 84 template<int STATE> | 51 template<int STATE> |
| 85 class {{type.id}}Builder { | 52 class {{type.id}}Builder { |
| 86 public: | 53 public: |
| 87 enum { | 54 enum { |
| 88 kNoFieldsSet = 0, | 55 kNoFieldsSet = 0, |
| 89 {% set count = 0 %} | 56 {% set count = 0 %} |
| 90 {% for property in type.properties %} | 57 {% for property in type.properties %} |
| 91 {% if not(property.optional) %} | 58 {% if not(property.optional) %} |
| 92 {% set count = count + 1 %} | 59 {% set count = count + 1 %} |
| 93 k{{property.name | to_title_case}}Set = 1 << {{count}}, | 60 k{{property.name | to_title_case}}Set = 1 << {{count}}, |
| 94 {% endif %} | 61 {% endif %} |
| 95 {% endfor %} | 62 {% endfor %} |
| 96 kAllRequiredFieldsSet = ( | 63 kAllRequiredFieldsSet = ( |
| 97 {%- for property in type.properties %} | 64 {%- for property in type.properties %} |
| 98 {% if not(property.optional) %}k{{property.name | to_title_case}}Set | {%e
ndif %} | 65 {% if not(property.optional) %}k{{property.name | to_title_case}}Set | {%end
if %} |
| 99 {% endfor %}0) | 66 {% endfor %}0) |
| 100 }; | 67 }; |
| 101 | 68 |
| 102 {% for property in type.properties %} | 69 {% for property in type.properties %} |
| 103 {% if property.optional %} | 70 {% if property.optional %} |
| 104 {{type.id}}Builder<STATE>& Set{{property.name | to_title_case}}({{resolve_ty
pe(property).pass_type}} value) { | 71 {{type.id}}Builder<STATE>& Set{{property.name | to_title_case}}({{resolve_ty
pe(property).pass_type}} value) { |
| 105 result_->Set{{property.name | to_title_case}}({{resolve_type(property).to_
pass_type % 'value'}}); | 72 result_->Set{{property.name | to_title_case}}({{resolve_type(property).to_
pass_type % 'value'}}); |
| 106 return *this; | 73 return *this; |
| 107 } | 74 } |
| 108 {% else %} | 75 {% else %} |
| 109 {{type.id}}Builder<STATE | k{{property.name | to_title_case}}Set>& Set{{prop
erty.name | to_title_case}}({{resolve_type(property).pass_type}} value) { | 76 {{type.id}}Builder<STATE | k{{property.name | to_title_case}}Set>& Set{{prop
erty.name | to_title_case}}({{resolve_type(property).pass_type}} value) { |
| 110 static_assert(!(STATE & k{{property.name | to_title_case}}Set), "property
{{property.name}} should not have already been set"); | 77 static_assert(!(STATE & k{{property.name | to_title_case}}Set), "property
{{property.name}} should not have already been set"); |
| 111 result_->Set{{property.name | to_title_case}}({{resolve_type(property).to_
pass_type % 'value'}}); | 78 result_->Set{{property.name | to_title_case}}({{resolve_type(property).to_
pass_type % 'value'}}); |
| 112 return CastState<k{{property.name | to_title_case}}Set>(); | 79 return CastState<k{{property.name | to_title_case}}Set>(); |
| 113 } | 80 } |
| 114 {% endif %} | 81 {% endif %} |
| 115 | 82 |
| 116 {% endfor %} | 83 {% endfor %} |
| 117 {{resolve_type(type).pass_type}} Build() { | 84 {{resolve_type(type).pass_type}} Build() { |
| 118 static_assert(STATE == kAllRequiredFieldsSet, "all required fields should
have been set"); | 85 static_assert(STATE == kAllRequiredFieldsSet, "all required fields should
have been set"); |
| 119 return std::move(result_); | 86 return std::move(result_); |
| 120 } | 87 } |
| 121 | 88 |
| 122 private: | 89 private: |
| 123 friend class {{type.id}}; | 90 friend class {{type.id}}; |
| 124 {{type.id}}Builder() : result_(new {{type.id}}()) { } | 91 {{type.id}}Builder() : result_(new {{type.id}}()) { } |
| 125 | 92 |
| 126 template<int STEP> {{type.id}}Builder<STATE | STEP>& CastState() { | 93 template<int STEP> {{type.id}}Builder<STATE | STEP>& CastState() { |
| 127 return *reinterpret_cast<{{type.id}}Builder<STATE | STEP>*>(this); | 94 return *reinterpret_cast<{{type.id}}Builder<STATE | STEP>*>(this); |
| 128 } | 95 } |
| 129 | 96 |
| 130 {{resolve_type(type).type}} result_; | 97 {{resolve_type(type).type}} result_; |
| 131 }; | 98 }; |
| 132 | 99 |
| 133 static {{type.id}}Builder<0> Builder() { | 100 static {{type.id}}Builder<0> Builder() { |
| 134 return {{type.id}}Builder<0>(); | 101 return {{type.id}}Builder<0>(); |
| 135 } | 102 } |
| 136 | 103 |
| 137 private: | 104 private: |
| 138 {{type.id}}() { } | 105 {{type.id}}() { } |
| 139 | 106 |
| 140 {% for property in type.properties %} | 107 {% for property in type.properties %} |
| 141 {% if property.optional %} | 108 {% if property.optional %} |
| 142 base::Optional<{{resolve_type(property).type}}> {{property.name | camelcase_to
_hacker_style}}_; | 109 base::Optional<{{resolve_type(property).type}}> {{property.name | camelcase_to
_hacker_style}}_; |
| 143 {% else %} | 110 {% else %} |
| 144 {{resolve_type(property).type}} {{property.name | camelcase_to_hacker_style}}_
; | 111 {{resolve_type(property).type}} {{property.name | camelcase_to_hacker_style}}_
; |
| 145 {% endif %} | 112 {% endif %} |
| 146 {% endfor %} | 113 {% endfor %} |
| 147 | 114 |
| 148 DISALLOW_COPY_AND_ASSIGN({{type.id}}); | 115 DISALLOW_COPY_AND_ASSIGN({{type.id}}); |
| 149 }; | 116 }; |
| 150 | 117 |
| 151 {% endfor %} | 118 {% endfor %} |
| 152 | 119 |
| 153 } // namespace {{domain.domain | camelcase_to_hacker_style}} | 120 } // namespace {{domain.domain | camelcase_to_hacker_style}} |
| 154 {% endfor %} | |
| 155 | 121 |
| 156 } // namespace headless | 122 } // namespace headless |
| 157 | 123 |
| 158 #endif // HEADLESS_PUBLIC_DOMAINS_TYPES_H_ | 124 #endif // HEADLESS_PUBLIC_DEVTOOLS_DOMAINS_TYPES_{{domain.domain | camelcase_to
_hacker_style | upper}}_H_ |
| OLD | NEW |