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 {{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" | 10 #include "platform/JSONValues.h" |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
105 template<typename T> PassRefPtr<JSONValue> toValue(PassRefPtr<T> param) { return
param; } | 105 template<typename T> PassRefPtr<JSONValue> toValue(PassRefPtr<T> param) { return
param; } |
106 template<typename T> PassRefPtr<JSONValue> toValue(T* param) { return param->asV
alue(); } | 106 template<typename T> PassRefPtr<JSONValue> toValue(T* param) { return param->asV
alue(); } |
107 template<typename T> PassRefPtr<JSONValue> toValue(PassOwnPtr<T> param) { return
param->asValue(); } | 107 template<typename T> PassRefPtr<JSONValue> toValue(PassOwnPtr<T> param) { return
param->asValue(); } |
108 template<typename T> PassRefPtr<JSONValue> toValue(const Maybe<T>& param) { retu
rn toValue(param.fromJust()); } | 108 template<typename T> PassRefPtr<JSONValue> toValue(const Maybe<T>& param) { retu
rn toValue(param.fromJust()); } |
109 | 109 |
110 template<typename T> | 110 template<typename T> |
111 struct FromValue | 111 struct FromValue |
112 { | 112 { |
113 static PassOwnPtr<T> convert(RefPtr<JSONValue> value) | 113 static PassOwnPtr<T> convert(RefPtr<JSONValue> value) |
114 { | 114 { |
115 if (!value) | 115 return T::runtimeCast(JSONObject::cast(value.release())); |
116 return nullptr; | |
117 RefPtr<JSONObject> object; | |
118 bool success = value->asObject(&object); | |
119 ASSERT_UNUSED(success, success); | |
120 return T::runtimeCast(object.release()); | |
121 } | 116 } |
122 }; | 117 }; |
123 | 118 |
124 template<> | 119 template<> |
125 struct FromValue<bool> | 120 struct FromValue<bool> |
126 { | 121 { |
127 static bool convert(RefPtr<JSONValue> value) | 122 static bool convert(RefPtr<JSONValue> value) |
128 { | 123 { |
129 bool result; | 124 bool result; |
130 bool success = value->asBoolean(&result); | 125 bool success = value->asBoolean(&result); |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
176 { | 171 { |
177 return value.release(); | 172 return value.release(); |
178 } | 173 } |
179 }; | 174 }; |
180 | 175 |
181 template<typename T> | 176 template<typename T> |
182 struct FromValue<protocol::Array<T>> | 177 struct FromValue<protocol::Array<T>> |
183 { | 178 { |
184 static PassOwnPtr<protocol::Array<T>> convert(RefPtr<JSONValue> value) | 179 static PassOwnPtr<protocol::Array<T>> convert(RefPtr<JSONValue> value) |
185 { | 180 { |
186 RefPtr<JSONArray> array = value->asArray(); | 181 return protocol::Array<T>::runtimeCast(JSONArray::cast(value)); |
187 ASSERT_UNUSED(array, array); | |
188 return protocol::Array<T>::runtimeCast(array); | |
189 } | 182 } |
190 }; | 183 }; |
191 | 184 |
192 template<typename T> | 185 template<typename T> |
193 class ArrayBase { | 186 class ArrayBase { |
194 public: | 187 public: |
195 static PassOwnPtr<Array<T>> create() | 188 static PassOwnPtr<Array<T>> create() |
196 { | 189 { |
197 OwnPtr<Array<T>> result = adoptPtr(new Array<T>()); | 190 OwnPtr<Array<T>> result = adoptPtr(new Array<T>()); |
198 result->m_array = JSONArray::create(); | 191 result->m_array = JSONArray::create(); |
199 return result.release(); | 192 return result.release(); |
200 } | 193 } |
201 | 194 |
202 static PassOwnPtr<Array<T>> runtimeCast(PassRefPtr<JSONArray> array) | 195 static PassOwnPtr<Array<T>> runtimeCast(PassRefPtr<JSONValue> array) |
203 { | 196 { |
204 if (!array) | 197 if (!array || array->type() != JSONValue::TypeArray) |
205 return nullptr; | 198 return nullptr; |
206 OwnPtr<Array<T>> result = adoptPtr(new Array<T>()); | 199 OwnPtr<Array<T>> result = adoptPtr(new Array<T>()); |
207 result->m_array = array; | 200 result->m_array = JSONArray::cast(array); |
208 return result.release(); | 201 return result.release(); |
209 } | 202 } |
210 | 203 |
211 void addItem(const T& value) | 204 void addItem(const T& value) |
212 { | 205 { |
213 m_array->pushValue(toValue(value)); | 206 m_array->pushValue(toValue(value)); |
214 } | 207 } |
215 | 208 |
216 size_t length() { return m_array->length(); } | 209 size_t length() { return m_array->length(); } |
217 | 210 |
(...skipping 13 matching lines...) Expand all Loading... |
231 template<typename T> | 224 template<typename T> |
232 class Array { | 225 class Array { |
233 public: | 226 public: |
234 static PassOwnPtr<Array<T>> create() | 227 static PassOwnPtr<Array<T>> create() |
235 { | 228 { |
236 OwnPtr<Array<T>> result = adoptPtr(new Array<T>()); | 229 OwnPtr<Array<T>> result = adoptPtr(new Array<T>()); |
237 result->m_array = JSONArray::create(); | 230 result->m_array = JSONArray::create(); |
238 return result.release(); | 231 return result.release(); |
239 } | 232 } |
240 | 233 |
241 static PassOwnPtr<Array<T>> runtimeCast(PassRefPtr<JSONArray> array) | 234 static PassOwnPtr<Array<T>> runtimeCast(PassRefPtr<JSONValue> array) |
242 { | 235 { |
243 if (!array) | 236 if (!array || array->type() != JSONValue::TypeArray) |
244 return nullptr; | 237 return nullptr; |
245 OwnPtr<Array<T>> result = adoptPtr(new Array<T>()); | 238 OwnPtr<Array<T>> result = adoptPtr(new Array<T>()); |
246 result->m_array = array; | 239 result->m_array = JSONArray::cast(array); |
247 return result.release(); | 240 return result.release(); |
248 } | 241 } |
249 | 242 |
250 void addItem(PassOwnPtr<T> value) | 243 void addItem(PassOwnPtr<T> value) |
251 { | 244 { |
252 m_array->pushValue(toValue(value)); | 245 m_array->pushValue(toValue(value)); |
253 } | 246 } |
254 | 247 |
255 size_t length() { return m_array->length(); } | 248 size_t length() { return m_array->length(); } |
256 | 249 |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
318 {% for domain in api.domains %} | 311 {% for domain in api.domains %} |
319 | 312 |
320 namespace {{domain.domain}} { | 313 namespace {{domain.domain}} { |
321 {% for type in domain.types %} | 314 {% for type in domain.types %} |
322 {% if type.type == "object" %} | 315 {% if type.type == "object" %} |
323 {% set type_def = type_definition(domain.domain + "." + type.id)%} | 316 {% set type_def = type_definition(domain.domain + "." + type.id)%} |
324 | 317 |
325 // {{type.description}} | 318 // {{type.description}} |
326 class PLATFORM_EXPORT {{type.id}} { | 319 class PLATFORM_EXPORT {{type.id}} { |
327 public: | 320 public: |
328 static PassOwnPtr<{{type.id}}> runtimeCast(PassRefPtr<JSONObject> object) | 321 static PassOwnPtr<{{type.id}}> runtimeCast(PassRefPtr<JSONValue> value) |
329 { | 322 { |
330 return adoptPtr(new {{type.id}}(object)); | 323 if (!value || value->type() != JSONValue::TypeObject) |
| 324 return nullptr; |
| 325 return adoptPtr(new {{type.id}}(JSONObject::cast(value))); |
331 } | 326 } |
332 | 327 |
333 {{type.id}}() : m_object(JSONObject::create()) { } | 328 {{type.id}}() : m_object(JSONObject::create()) { } |
334 | 329 |
335 ~{{type.id}}() { } | 330 ~{{type.id}}() { } |
336 {% for property in type.properties %} | 331 {% for property in type.properties %} |
337 | 332 |
338 {% if "enum" in property %} | 333 {% if "enum" in property %} |
339 struct PLATFORM_EXPORT {{property.name | to_title_case}}Enum { | 334 struct PLATFORM_EXPORT {{property.name | to_title_case}}Enum { |
340 {% for literal in property.enum %} | 335 {% for literal in property.enum %} |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
450 {% endif %} | 445 {% endif %} |
451 {% endfor %} | 446 {% endfor %} |
452 | 447 |
453 } // {{domain.domain}} | 448 } // {{domain.domain}} |
454 {% endfor %} | 449 {% endfor %} |
455 | 450 |
456 } // namespace protocol | 451 } // namespace protocol |
457 } // namespace blink | 452 } // namespace blink |
458 | 453 |
459 #endif // !defined({{class_name}}_h) | 454 #endif // !defined({{class_name}}_h) |
OLD | NEW |