OLD | NEW |
---|---|
(Empty) | |
1 // This file is generated | |
2 | |
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 | |
5 // found in the LICENSE file. | |
6 | |
7 #ifndef HEADLESS_PUBLIC_DOMAINS_TYPES_H_ | |
8 #define HEADLESS_PUBLIC_DOMAINS_TYPES_H_ | |
9 | |
10 #include "base/values.h" | |
11 #include "headless/public/headless_export.h" | |
12 #include "headless/public/util/error_reporter.h" | |
13 #include "headless/public/util/maybe.h" | |
14 | |
15 #include "base/memory/ptr_util.h" | |
16 | |
17 namespace headless { | |
18 | |
19 // ------------- Forward declarations and typedefs. | |
dgozman
2016/04/14 18:01:54
In generated files I see a forward declaration for
Sami
2016/04/15 14:43:45
Do you mean here?
https://drive.google.com/corp/d
dgozman
2016/04/15 20:51:13
Wow. A serious usability decision here :-)
| |
20 | |
21 {% for domain in api.domains %} | |
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 | dash_to_camelcase | camelcase_to_hacker_style | upper | mangle_en um}}{{',' 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 {% set type_def = type_definition(domain.domain + "." + type.id)%} | |
59 | |
60 {% if type.description %} | |
61 // {{type.description}} | |
62 {% endif %} | |
63 class HEADLESS_EXPORT {{type.id}} { | |
64 public: | |
65 static {{resolve_type(type).pass_type}} Parse(const base::Value& value, ErrorR eporter* errors); | |
66 ~{{type.id}}() { } | |
67 {% for property in type.properties %} | |
68 | |
69 {% if property.description %} | |
70 // {{property.description}} | |
71 {% endif %} | |
72 {% if property.optional %} | |
73 bool Has{{property.name | to_title_case}}() { return {{property.name | camelca se_to_hacker_style}}_.IsJust(); } | |
74 {{resolve_type(property).raw_return_type}} Get{{property.name | to_title_case} }() { return {{resolve_type(property).to_raw_return_type % ("%s_.FromJust()" % p roperty.name | camelcase_to_hacker_style)}}; } | |
75 void Set{{property.name | to_title_case}}({{resolve_type(property).pass_type}} value) { {{property.name | camelcase_to_hacker_style}}_ = Just({{resolve_type(p roperty).to_pass_type % 'value'}}); } | |
76 {% else %} | |
77 {{resolve_type(property).raw_return_type}} Get{{property.name | to_title_case} }() { return {{resolve_type(property).to_raw_return_type % ("%s_" % property.nam e | camelcase_to_hacker_style)}}; } | |
78 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'}}; } | |
79 {% endif %} | |
80 {% endfor %} | |
81 | |
82 std::unique_ptr<base::Value> Serialize() const; | |
83 {{resolve_type(type).pass_type}} Clone() const; | |
84 | |
85 template<int STATE> | |
86 class {{type.id}}Builder { | |
87 public: | |
88 enum { | |
89 kNoFieldsSet = 0, | |
90 {% set count = 0 %} | |
91 {% for property in type.properties %} | |
92 {% if not(property.optional) %} | |
93 {% set count = count + 1 %} | |
94 k{{property.name | to_title_case}}Set = 1 << {{count}}, | |
95 {% endif %} | |
96 {% endfor %} | |
97 kAllRequiredFieldsSet = ( | |
98 {%- for property in type.properties %} | |
99 {% if not(property.optional) %}k{{property.name | to_title_case}}Set | {%e ndif %} | |
100 {% endfor %}0) | |
101 }; | |
102 | |
103 {% for property in type.properties %} | |
104 {% if property.optional %} | |
105 {{type.id}}Builder<STATE>& Set{{property.name | to_title_case}}({{resolve_ty pe(property).pass_type}} value) { | |
106 result_->Set{{property.name | to_title_case}}({{resolve_type(property).to_ pass_type % 'value'}}); | |
107 return *this; | |
108 } | |
109 {% else %} | |
110 {{type.id}}Builder<STATE | k{{property.name | to_title_case}}Set>& Set{{prop erty.name | to_title_case}}({{resolve_type(property).pass_type}} value) { | |
111 static_assert(!(STATE & k{{property.name | to_title_case}}Set), "property {{property.name}} should not have already been set"); | |
112 result_->Set{{property.name | to_title_case}}({{resolve_type(property).to_ pass_type % 'value'}}); | |
113 return CastState<k{{property.name | to_title_case}}Set>(); | |
114 } | |
115 {% endif %} | |
116 | |
117 {% endfor %} | |
118 {{resolve_type(type).pass_type}} Build() { | |
119 static_assert(STATE == kAllRequiredFieldsSet, "all required fields should have been set"); | |
120 return std::move(result_); | |
121 } | |
122 | |
123 private: | |
124 friend class {{type.id}}; | |
125 {{type.id}}Builder() : result_(new {{type.id}}()) { } | |
126 | |
127 template<int STEP> {{type.id}}Builder<STATE | STEP>& CastState() { | |
128 return *reinterpret_cast<{{type.id}}Builder<STATE | STEP>*>(this); | |
129 } | |
130 | |
131 {{resolve_type(type).type}} result_; | |
132 }; | |
133 | |
134 static {{type.id}}Builder<0> Builder() { | |
135 return {{type.id}}Builder<0>(); | |
136 } | |
137 | |
138 private: | |
139 {{type.id}}() { } | |
140 | |
141 {% for property in type.properties %} | |
142 {% if property.optional %} | |
143 Maybe<{{resolve_type(property).type}}> {{property.name | camelcase_to_hacker_s tyle}}_; | |
144 {% else %} | |
145 {{resolve_type(property).type}} {{property.name | camelcase_to_hacker_style}}_ ; | |
146 {% endif %} | |
147 {% endfor %} | |
148 | |
149 DISALLOW_COPY_AND_ASSIGN({{type.id}}); | |
150 }; | |
151 | |
152 {% endfor %} | |
153 | |
154 } // namespace {{domain.domain | camelcase_to_hacker_style}} | |
155 {% endfor %} | |
156 | |
157 } // namespace headless | |
158 | |
159 #endif // HEADLESS_PUBLIC_DOMAINS_TYPES_H_ | |
OLD | NEW |