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

Side by Side Diff: third_party/WebKit/Source/platform/inspector_protocol/TypeBuilder_h.template

Issue 1738073002: DevTools: introduce protocol::Value, baseline for hierarchical data in remote debugging protocol. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 9 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 // 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 {{class_name}}_h 7 #ifndef {{class_name}}_h
8 #define {{class_name}}_h 8 #define {{class_name}}_h
9 9
10 #include "platform/JSONValues.h"
11 #include "platform/PlatformExport.h" 10 #include "platform/PlatformExport.h"
11 #include "platform/inspector_protocol/Values.h"
12 #include "wtf/Assertions.h" 12 #include "wtf/Assertions.h"
13 #include "wtf/PassOwnPtr.h" 13 #include "wtf/PassOwnPtr.h"
14 #include "wtf/PassRefPtr.h" 14 #include "wtf/PassRefPtr.h"
15 #include "wtf/text/StringBuilder.h" 15 #include "wtf/text/StringBuilder.h"
16 #include "wtf/text/WTFString.h" 16 #include "wtf/text/WTFString.h"
17 17
18 namespace blink { 18 namespace blink {
19 namespace protocol { 19 namespace protocol {
20 20
21 template<typename T> 21 template<typename T>
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
92 PassRefPtr<T> fromMaybe(const PassRefPtr<T> defaultValue) const { return m_v alue || defaultValue; } 92 PassRefPtr<T> fromMaybe(const PassRefPtr<T> defaultValue) const { return m_v alue || defaultValue; }
93 bool isJust() const { return !!m_value; } 93 bool isJust() const { return !!m_value; }
94 PassRefPtr<T> takeJust() { return m_value; } 94 PassRefPtr<T> takeJust() { return m_value; }
95 95
96 protected: 96 protected:
97 RefPtr<T> m_value; 97 RefPtr<T> m_value;
98 }; 98 };
99 99
100 template<typename T> class Array; 100 template<typename T> class Array;
101 101
102 PLATFORM_EXPORT PassRefPtr<JSONValue> toValue(int value); 102 PLATFORM_EXPORT PassRefPtr<protocol::Value> toValue(int value);
103 PLATFORM_EXPORT PassRefPtr<JSONValue> toValue(double value); 103 PLATFORM_EXPORT PassRefPtr<protocol::Value> toValue(double value);
104 PLATFORM_EXPORT PassRefPtr<JSONValue> toValue(bool value); 104 PLATFORM_EXPORT PassRefPtr<protocol::Value> toValue(bool value);
105 PLATFORM_EXPORT PassRefPtr<JSONValue> toValue(const String& param); 105 PLATFORM_EXPORT PassRefPtr<protocol::Value> toValue(const String& param);
106 template<typename T> PassRefPtr<JSONValue> toValue(PassRefPtr<T> param) { return param; } 106 template<typename T> PassRefPtr<protocol::Value> toValue(PassRefPtr<T> param) { return param; }
107 template<typename T> PassRefPtr<JSONValue> toValue(const RefPtr<T>& param) { ret urn param; } 107 template<typename T> PassRefPtr<protocol::Value> toValue(const RefPtr<T>& param) { return param; }
108 template<typename T> PassRefPtr<JSONValue> toValue(T* param) { return param->ser ialize(); } 108 template<typename T> PassRefPtr<protocol::Value> toValue(T* param) { return para m->serialize(); }
109 template<typename T> PassRefPtr<JSONValue> toValue(PassOwnPtr<T> param) { return param->serialize(); } 109 template<typename T> PassRefPtr<protocol::Value> toValue(PassOwnPtr<T> param) { return param->serialize(); }
110 template<typename T> PassRefPtr<JSONValue> toValue(const OwnPtr<T>& param) { ret urn param->serialize(); } 110 template<typename T> PassRefPtr<protocol::Value> toValue(const OwnPtr<T>& param) { return param->serialize(); }
111 111
112 class PLATFORM_EXPORT ErrorSupport { 112 class PLATFORM_EXPORT ErrorSupport {
113 public: 113 public:
114 ErrorSupport(); 114 ErrorSupport();
115 ErrorSupport(String* errorString); 115 ErrorSupport(String* errorString);
116 ~ErrorSupport(); 116 ~ErrorSupport();
117 117
118 void push(); 118 void push();
119 void setName(const String& name); 119 void setName(const String& name);
120 void pop(); 120 void pop();
121 void addError(const String& error); 121 void addError(const String& error);
122 bool hasErrors(); 122 bool hasErrors();
123 String errors(); 123 String errors();
124 124
125 private: 125 private:
126 Vector<String> m_path; 126 Vector<String> m_path;
127 Vector<String> m_errors; 127 Vector<String> m_errors;
128 String* m_errorString; 128 String* m_errorString;
129 }; 129 };
130 130
131 template<typename T> 131 template<typename T>
132 struct FromValue 132 struct FromValue
133 { 133 {
134 static PassOwnPtr<T> parse(PassRefPtr<JSONValue> value, ErrorSupport* errors ) 134 static PassOwnPtr<T> parse(PassRefPtr<protocol::Value> value, ErrorSupport* errors)
135 { 135 {
136 return T::parse(value, errors); 136 return T::parse(value, errors);
137 } 137 }
138 }; 138 };
139 139
140 template<> 140 template<>
141 struct FromValue<bool> 141 struct FromValue<bool>
142 { 142 {
143 static bool parse(PassRefPtr<JSONValue> value, ErrorSupport* errors) 143 static bool parse(PassRefPtr<protocol::Value> value, ErrorSupport* errors)
144 { 144 {
145 bool result = false; 145 bool result = false;
146 bool success = value ? value->asBoolean(&result) : false; 146 bool success = value ? value->asBoolean(&result) : false;
147 if (!success) 147 if (!success)
148 errors->addError("boolean value expected"); 148 errors->addError("boolean value expected");
149 return result; 149 return result;
150 } 150 }
151 }; 151 };
152 152
153 template<> 153 template<>
154 struct FromValue<int> 154 struct FromValue<int>
155 { 155 {
156 static int parse(PassRefPtr<JSONValue> value, ErrorSupport* errors) 156 static int parse(PassRefPtr<protocol::Value> value, ErrorSupport* errors)
157 { 157 {
158 int result = 0; 158 int result = 0;
159 bool success = value ? value->asNumber(&result) : false; 159 bool success = value ? value->asNumber(&result) : false;
160 if (!success) 160 if (!success)
161 errors->addError("integer value expected"); 161 errors->addError("integer value expected");
162 return result; 162 return result;
163 } 163 }
164 }; 164 };
165 165
166 template<> 166 template<>
167 struct FromValue<double> 167 struct FromValue<double>
168 { 168 {
169 static double parse(PassRefPtr<JSONValue> value, ErrorSupport* errors) 169 static double parse(PassRefPtr<protocol::Value> value, ErrorSupport* errors)
170 { 170 {
171 double result = 0; 171 double result = 0;
172 bool success = value ? value->asNumber(&result) : false; 172 bool success = value ? value->asNumber(&result) : false;
173 if (!success) 173 if (!success)
174 errors->addError("double value expected"); 174 errors->addError("double value expected");
175 return result; 175 return result;
176 } 176 }
177 }; 177 };
178 178
179 template<> 179 template<>
180 struct FromValue<String> 180 struct FromValue<String>
181 { 181 {
182 static String parse(PassRefPtr<JSONValue> value, ErrorSupport* errors) 182 static String parse(PassRefPtr<protocol::Value> value, ErrorSupport* errors)
183 { 183 {
184 String result; 184 String result;
185 bool success = value ? value->asString(&result) : false; 185 bool success = value ? value->asString(&result) : false;
186 if (!success) 186 if (!success)
187 errors->addError("string value expected"); 187 errors->addError("string value expected");
188 return result; 188 return result;
189 } 189 }
190 }; 190 };
191 191
192 template<typename T> 192 template<typename T>
193 struct FromValue<RefPtr<T>> 193 struct FromValue<RefPtr<T>>
194 { 194 {
195 static PassRefPtr<T> parse(PassRefPtr<JSONValue> value, ErrorSupport* errors ) 195 static PassRefPtr<T> parse(PassRefPtr<protocol::Value> value, ErrorSupport* errors)
196 { 196 {
197 if (!value) 197 if (!value)
198 errors->addError("value expected"); 198 errors->addError("value expected");
199 return value; 199 return value;
200 } 200 }
201 }; 201 };
202 202
203 template<> 203 template<>
204 struct FromValue<RefPtr<JSONObject>> 204 struct FromValue<RefPtr<protocol::DictionaryValue>>
205 { 205 {
206 static PassRefPtr<JSONObject> parse(PassRefPtr<JSONValue> value, ErrorSuppor t* errors) 206 static PassRefPtr<protocol::DictionaryValue> parse(PassRefPtr<protocol::Valu e> value, ErrorSupport* errors)
207 { 207 {
208 if (value && value->type() == JSONValue::TypeObject) 208 if (value && value->type() == protocol::Value::TypeObject)
209 return JSONObject::cast(value); 209 return DictionaryValue::cast(value);
210 errors->addError("object expected"); 210 errors->addError("object expected");
211 return nullptr; 211 return nullptr;
212 } 212 }
213 }; 213 };
214 214
215 template<typename T> 215 template<typename T>
216 struct FromValue<protocol::Array<T>> 216 struct FromValue<protocol::Array<T>>
217 { 217 {
218 static PassOwnPtr<protocol::Array<T>> parse(PassRefPtr<JSONValue> value, Err orSupport* errors) 218 static PassOwnPtr<protocol::Array<T>> parse(PassRefPtr<protocol::Value> valu e, ErrorSupport* errors)
219 { 219 {
220 return protocol::Array<T>::parse(value, errors); 220 return protocol::Array<T>::parse(value, errors);
221 } 221 }
222 }; 222 };
223 223
224 template<typename T> 224 template<typename T>
225 class ArrayBase { 225 class ArrayBase {
226 public: 226 public:
227 static PassOwnPtr<Array<T>> create() 227 static PassOwnPtr<Array<T>> create()
228 { 228 {
229 return adoptPtr(new Array<T>()); 229 return adoptPtr(new Array<T>());
230 } 230 }
231 231
232 static PassOwnPtr<Array<T>> parse(PassRefPtr<JSONValue> value, ErrorSupport* errors) 232 static PassOwnPtr<Array<T>> parse(PassRefPtr<protocol::Value> value, ErrorSu pport* errors)
233 { 233 {
234 RefPtr<JSONArray> array = JSONArray::cast(value); 234 RefPtr<protocol::ListValue> array = ListValue::cast(value);
235 if (!array) { 235 if (!array) {
236 errors->addError("array expected"); 236 errors->addError("array expected");
237 return nullptr; 237 return nullptr;
238 } 238 }
239 errors->push(); 239 errors->push();
240 OwnPtr<Array<T>> result = adoptPtr(new Array<T>()); 240 OwnPtr<Array<T>> result = adoptPtr(new Array<T>());
241 for (size_t i = 0; i < array->length(); ++i) { 241 for (size_t i = 0; i < array->length(); ++i) {
242 errors->setName("[" + String::number(i) + "]"); 242 errors->setName("[" + String::number(i) + "]");
243 T item = FromValue<T>::parse(array->get(i), errors); 243 T item = FromValue<T>::parse(array->get(i), errors);
244 result->m_vector.append(item); 244 result->m_vector.append(item);
(...skipping 12 matching lines...) Expand all
257 size_t length() 257 size_t length()
258 { 258 {
259 return m_vector.size(); 259 return m_vector.size();
260 } 260 }
261 261
262 T get(size_t index) 262 T get(size_t index)
263 { 263 {
264 return m_vector[index]; 264 return m_vector[index];
265 } 265 }
266 266
267 PassRefPtr<JSONArray> serialize() 267 PassRefPtr<protocol::ListValue> serialize()
268 { 268 {
269 RefPtr<JSONArray> result = JSONArray::create(); 269 RefPtr<protocol::ListValue> result = ListValue::create();
270 for (auto& item : m_vector) 270 for (auto& item : m_vector)
271 result->pushValue(toValue(item)); 271 result->pushValue(toValue(item));
272 return result.release(); 272 return result.release();
273 } 273 }
274 274
275 private: 275 private:
276 Vector<T> m_vector; 276 Vector<T> m_vector;
277 }; 277 };
278 278
279 template<> class Array<String> : public ArrayBase<String> {}; 279 template<> class Array<String> : public ArrayBase<String> {};
280 template<> class Array<int> : public ArrayBase<int> {}; 280 template<> class Array<int> : public ArrayBase<int> {};
281 template<> class Array<double> : public ArrayBase<double> {}; 281 template<> class Array<double> : public ArrayBase<double> {};
282 template<> class Array<bool> : public ArrayBase<bool> {}; 282 template<> class Array<bool> : public ArrayBase<bool> {};
283 template<typename T> class Array<RefPtr<T>> : public ArrayBase<RefPtr<T>> {}; 283 template<typename T> class Array<RefPtr<T>> : public ArrayBase<RefPtr<T>> {};
284 284
285 template<typename T> 285 template<typename T>
286 class Array { 286 class Array {
287 public: 287 public:
288 static PassOwnPtr<Array<T>> create() 288 static PassOwnPtr<Array<T>> create()
289 { 289 {
290 return adoptPtr(new Array<T>()); 290 return adoptPtr(new Array<T>());
291 } 291 }
292 292
293 static PassOwnPtr<Array<T>> parse(PassRefPtr<JSONValue> value, ErrorSupport* errors) 293 static PassOwnPtr<Array<T>> parse(PassRefPtr<protocol::Value> value, ErrorSu pport* errors)
294 { 294 {
295 RefPtr<JSONArray> array = JSONArray::cast(value); 295 RefPtr<protocol::ListValue> array = ListValue::cast(value);
296 if (!array) { 296 if (!array) {
297 errors->addError("array expected"); 297 errors->addError("array expected");
298 return nullptr; 298 return nullptr;
299 } 299 }
300 OwnPtr<Array<T>> result = adoptPtr(new Array<T>()); 300 OwnPtr<Array<T>> result = adoptPtr(new Array<T>());
301 errors->push(); 301 errors->push();
302 for (size_t i = 0; i < array->length(); ++i) { 302 for (size_t i = 0; i < array->length(); ++i) {
303 errors->setName("[" + String::number(i) + "]"); 303 errors->setName("[" + String::number(i) + "]");
304 OwnPtr<T> item = FromValue<T>::parse(array->get(i), errors); 304 OwnPtr<T> item = FromValue<T>::parse(array->get(i), errors);
305 result->m_vector.append(item.release()); 305 result->m_vector.append(item.release());
(...skipping 10 matching lines...) Expand all
316 size_t length() 316 size_t length()
317 { 317 {
318 return m_vector.size(); 318 return m_vector.size();
319 } 319 }
320 320
321 T* get(size_t index) 321 T* get(size_t index)
322 { 322 {
323 return m_vector[index].get(); 323 return m_vector[index].get();
324 } 324 }
325 325
326 PassRefPtr<JSONArray> serialize() 326 PassRefPtr<protocol::ListValue> serialize()
327 { 327 {
328 RefPtr<JSONArray> result = JSONArray::create(); 328 RefPtr<protocol::ListValue> result = ListValue::create();
329 for (auto& item : m_vector) 329 for (auto& item : m_vector)
330 result->pushValue(toValue(item)); 330 result->pushValue(toValue(item));
331 return result.release(); 331 return result.release();
332 } 332 }
333 333
334 private: 334 private:
335 Vector<OwnPtr<T>> m_vector; 335 Vector<OwnPtr<T>> m_vector;
336 }; 336 };
337 337
338 class PLATFORM_EXPORT Object { 338 class PLATFORM_EXPORT Object {
339 public: 339 public:
340 static PassOwnPtr<Object> parse(PassRefPtr<JSONValue> value, ErrorSupport* e rrors); 340 static PassOwnPtr<Object> parse(PassRefPtr<protocol::Value> value, ErrorSupp ort* errors);
341 ~Object(); 341 ~Object();
342 342
343 PassRefPtr<JSONObject> serialize() const; 343 PassRefPtr<protocol::DictionaryValue> serialize() const;
344 PassOwnPtr<Object> clone() const; 344 PassOwnPtr<Object> clone() const;
345 private: 345 private:
346 Object(PassRefPtr<JSONObject> object); 346 Object(PassRefPtr<protocol::DictionaryValue> object);
347 RefPtr<JSONObject> m_object; 347 RefPtr<protocol::DictionaryValue> m_object;
348 }; 348 };
349 349
350 {% for domain in api.domains %} 350 {% for domain in api.domains %}
351 351
352 // ------------- Forward declarations and typedefs. 352 // ------------- Forward declarations and typedefs.
353 353
354 namespace {{domain.domain}} { 354 namespace {{domain.domain}} {
355 {% for type in domain.types %} 355 {% for type in domain.types %}
356 {% if type.type == "object" %} 356 {% if type.type == "object" %}
357 {% if "properties" in type %} 357 {% if "properties" in type %}
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
409 {% for domain in api.domains %} 409 {% for domain in api.domains %}
410 410
411 namespace {{domain.domain}} { 411 namespace {{domain.domain}} {
412 {% for type in domain.types %} 412 {% for type in domain.types %}
413 {% if not (type.type == "object") or not ("properties" in type) %}{% continu e %}{% endif %} 413 {% if not (type.type == "object") or not ("properties" in type) %}{% continu e %}{% endif %}
414 {% set type_def = type_definition(domain.domain + "." + type.id)%} 414 {% set type_def = type_definition(domain.domain + "." + type.id)%}
415 415
416 // {{type.description}} 416 // {{type.description}}
417 class PLATFORM_EXPORT {{type.id}} { 417 class PLATFORM_EXPORT {{type.id}} {
418 public: 418 public:
419 static PassOwnPtr<{{type.id}}> parse(PassRefPtr<JSONValue> value, ErrorSuppo rt* errors); 419 static PassOwnPtr<{{type.id}}> parse(PassRefPtr<protocol::Value> value, Erro rSupport* errors);
420 420
421 ~{{type.id}}() { } 421 ~{{type.id}}() { }
422 {% for property in type.properties %} 422 {% for property in type.properties %}
423 {% if "enum" in property %} 423 {% if "enum" in property %}
424 424
425 struct PLATFORM_EXPORT {{property.name | to_title_case}}Enum { 425 struct PLATFORM_EXPORT {{property.name | to_title_case}}Enum {
426 {% for literal in property.enum %} 426 {% for literal in property.enum %}
427 static const char* {{ literal | dash_to_camelcase}}; 427 static const char* {{ literal | dash_to_camelcase}};
428 {% endfor %} 428 {% endfor %}
429 }; // {{property.name | to_title_case}}Enum 429 }; // {{property.name | to_title_case}}Enum
430 {% endif %} 430 {% endif %}
431 431
432 {% if property.optional %} 432 {% if property.optional %}
433 bool has{{property.name | to_title_case}}() { return m_{{property.name}}.isJ ust(); } 433 bool has{{property.name | to_title_case}}() { return m_{{property.name}}.isJ ust(); }
434 {{resolve_type(property).raw_return_type}} get{{property.name | to_title_cas e}}({{resolve_type(property).raw_pass_type}} defaultValue) { return m_{{property .name}}.isJust() ? m_{{property.name}}.fromJust() : defaultValue; } 434 {{resolve_type(property).raw_return_type}} get{{property.name | to_title_cas e}}({{resolve_type(property).raw_pass_type}} defaultValue) { return m_{{property .name}}.isJust() ? m_{{property.name}}.fromJust() : defaultValue; }
435 {% else %} 435 {% else %}
436 {{resolve_type(property).raw_return_type}} get{{property.name | to_title_cas e}}() { return {{resolve_type(property).to_raw_type % ("m_" + property.name)}}; } 436 {{resolve_type(property).raw_return_type}} get{{property.name | to_title_cas e}}() { return {{resolve_type(property).to_raw_type % ("m_" + property.name)}}; }
437 {% endif %} 437 {% endif %}
438 void set{{property.name | to_title_case}}({{resolve_type(property).pass_type }} value) { m_{{property.name}} = value; } 438 void set{{property.name | to_title_case}}({{resolve_type(property).pass_type }} value) { m_{{property.name}} = value; }
439 {% endfor %} 439 {% endfor %}
440 440
441 PassRefPtr<JSONObject> serialize() const; 441 PassRefPtr<protocol::DictionaryValue> serialize() const;
442 PassOwnPtr<{{type.id}}> clone() const; 442 PassOwnPtr<{{type.id}}> clone() const;
443 443
444 template<int STATE> 444 template<int STATE>
445 class {{type.id}}Builder { 445 class {{type.id}}Builder {
446 public: 446 public:
447 enum { 447 enum {
448 NoFieldsSet = 0, 448 NoFieldsSet = 0,
449 {% set count = 0 %} 449 {% set count = 0 %}
450 {% for property in type.properties %} 450 {% for property in type.properties %}
451 {% if not(property.optional) %} 451 {% if not(property.optional) %}
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
513 513
514 {% endfor %} 514 {% endfor %}
515 515
516 } // {{domain.domain}} 516 } // {{domain.domain}}
517 {% endfor %} 517 {% endfor %}
518 518
519 } // namespace protocol 519 } // namespace protocol
520 } // namespace blink 520 } // namespace blink
521 521
522 #endif // !defined({{class_name}}_h) 522 #endif // !defined({{class_name}}_h)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698