| // This file is generated |
| |
| // Copyright (c) 2016 The Chromium Authors. All rights reserved. |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| |
| #include "platform/inspector_protocol/{{class_name}}.h" |
| |
| namespace blink { |
| namespace protocol { |
| |
| // ------------- Enum values from types. |
| {% for domain in api.domains %} |
| |
| namespace {{domain.domain}} { |
| {% for type in domain.types %} |
| {% if "enum" in type %} |
| |
| namespace {{type.id}}Enum { |
| {% for literal in type.enum %} |
| const char* {{ literal | dash_to_camelcase}} = "{{literal}}"; |
| {% endfor %} |
| } // {{type.id}}Enum |
| {% endif %} |
| {% for property in type.properties %} |
| {% if "enum" in property %} |
| |
| {% for literal in property.enum %} |
| const char* {{type.id}}::{{property.name | to_title_case}}Enum::{{ literal | dash_to_camelcase}} = "{{literal}}"; |
| {% endfor %} |
| {% endif %} |
| {% endfor %} |
| {% if not (type.type == "object") or not ("properties" in type) %}{% continue %}{% endif %} |
| |
| std::unique_ptr<{{type.id}}> {{type.id}}::parse(protocol::Value* value, ErrorSupport* errors) |
| { |
| if (!value || value->type() != protocol::Value::TypeObject) { |
| errors->addError("object expected"); |
| return nullptr; |
| } |
| |
| std::unique_ptr<{{type.id}}> result(new {{type.id}}()); |
| protocol::DictionaryValue* object = DictionaryValue::cast(value); |
| errors->push(); |
| {% for property in type.properties %} |
| protocol::Value* {{property.name}}Value = object->get("{{property.name}}"); |
| {% if property.optional %} |
| if ({{property.name}}Value) { |
| errors->setName("{{property.name}}"); |
| result->m_{{property.name}} = FromValue<{{resolve_type(property).raw_type}}>::parse({{property.name}}Value, errors); |
| } |
| {% else %} |
| errors->setName("{{property.name}}"); |
| result->m_{{property.name}} = FromValue<{{resolve_type(property).raw_type}}>::parse({{property.name}}Value, errors); |
| {% endif %} |
| {% endfor %} |
| errors->pop(); |
| if (errors->hasErrors()) |
| return nullptr; |
| return result; |
| } |
| |
| std::unique_ptr<protocol::DictionaryValue> {{type.id}}::serialize() const |
| { |
| std::unique_ptr<protocol::DictionaryValue> result = DictionaryValue::create(); |
| {% for property in type.properties %} |
| {% if property.optional %} |
| if (m_{{property.name}}.isJust()) |
| result->setValue("{{property.name}}", toValue(m_{{property.name}}.fromJust())); |
| {% else %} |
| result->setValue("{{property.name}}", toValue({{resolve_type(property).to_raw_type % ("m_" + property.name)}})); |
| {% endif %} |
| {% endfor %} |
| return result; |
| } |
| |
| std::unique_ptr<{{type.id}}> {{type.id}}::clone() const |
| { |
| ErrorSupport errors; |
| return parse(serialize().get(), &errors); |
| } |
| {% endfor %} |
| } // {{domain.domain}} |
| {% endfor %} |
| |
| // ------------- Enum values from params. |
| {% for domain in api.domains %} |
| {% for command in join_arrays(domain, ["commands", "events"]) %} |
| {% for param in join_arrays(command, ["parameters", "returns"]) %} |
| {% if "enum" in param %} |
| |
| namespace {{domain.domain}} { |
| namespace {{command.name | to_title_case}} { |
| namespace {{param.name | to_title_case}}Enum { |
| {% for literal in param.enum %} |
| const char* {{ literal | to_title_case}} = "{{literal}}"; |
| {% endfor %} |
| } // {{param.name | to_title_case}}Enum |
| } // {{command.name | to_title_case }} |
| } // {{domain.domain}} |
| {% endif %} |
| {% endfor %} |
| {% endfor %} |
| {% endfor %} |
| |
| } // namespace protocol |
| } // namespace blink |