| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef ValueConversions_h | 5 #ifndef {{"_".join(config.protocol.namespace)}}_ValueConversions_h |
| 6 #define ValueConversions_h | 6 #define {{"_".join(config.protocol.namespace)}}_ValueConversions_h |
| 7 | 7 |
| 8 //#include "ErrorSupport.h" | 8 //#include "ErrorSupport.h" |
| 9 //#include "Platform.h" | 9 //#include "Platform.h" |
| 10 //#include "String16.h" | 10 //#include "String.h" |
| 11 //#include "Values.h" | 11 //#include "Values.h" |
| 12 | 12 |
| 13 namespace blink { | 13 {% for namespace in config.protocol.namespace %} |
| 14 namespace protocol { | 14 namespace {{namespace}} { |
| 15 {% endfor %} |
| 15 | 16 |
| 16 template<typename T> | 17 template<typename T> |
| 17 struct ValueConversions { | 18 struct ValueConversions { |
| 18 static std::unique_ptr<T> parse(protocol::Value* value, ErrorSupport* errors
) | 19 static std::unique_ptr<T> parse(protocol::Value* value, ErrorSupport* errors
) |
| 19 { | 20 { |
| 20 return T::parse(value, errors); | 21 return T::parse(value, errors); |
| 21 } | 22 } |
| 22 | 23 |
| 23 static std::unique_ptr<protocol::Value> serialize(T* value) | 24 static std::unique_ptr<protocol::Value> serialize(T* value) |
| 24 { | 25 { |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 76 return result; | 77 return result; |
| 77 } | 78 } |
| 78 | 79 |
| 79 static std::unique_ptr<protocol::Value> serialize(double value) | 80 static std::unique_ptr<protocol::Value> serialize(double value) |
| 80 { | 81 { |
| 81 return FundamentalValue::create(value); | 82 return FundamentalValue::create(value); |
| 82 } | 83 } |
| 83 }; | 84 }; |
| 84 | 85 |
| 85 template<> | 86 template<> |
| 86 struct ValueConversions<InspectorProtocolConvenienceStringType> { | 87 struct ValueConversions<String> { |
| 87 static InspectorProtocolConvenienceStringType parse(protocol::Value* value,
ErrorSupport* errors) | 88 static String parse(protocol::Value* value, ErrorSupport* errors) |
| 88 { | 89 { |
| 89 String16 result; | 90 String result; |
| 90 bool success = value ? value->asString(&result) : false; | 91 bool success = value ? value->asString(&result) : false; |
| 91 if (!success) | 92 if (!success) |
| 92 errors->addError("string value expected"); | 93 errors->addError("string value expected"); |
| 93 return result; | 94 return result; |
| 94 } | 95 } |
| 95 | 96 |
| 96 static std::unique_ptr<protocol::Value> serialize(const InspectorProtocolCon
venienceStringType& value) | 97 static std::unique_ptr<protocol::Value> serialize(const String& value) |
| 97 { | 98 { |
| 98 return StringValue::create(value); | 99 return StringValue::create(value); |
| 99 } | 100 } |
| 100 }; | |
| 101 | |
| 102 template<> | |
| 103 struct ValueConversions<String16> { | |
| 104 static String16 parse(protocol::Value* value, ErrorSupport* errors) | |
| 105 { | |
| 106 String16 result; | |
| 107 bool success = value ? value->asString(&result) : false; | |
| 108 if (!success) | |
| 109 errors->addError("string value expected"); | |
| 110 return result; | |
| 111 } | |
| 112 | |
| 113 static std::unique_ptr<protocol::Value> serialize(const String16& value) | |
| 114 { | |
| 115 return StringValue::create(value); | |
| 116 } | |
| 117 }; | 101 }; |
| 118 | 102 |
| 119 template<> | 103 template<> |
| 120 struct ValueConversions<Value> { | 104 struct ValueConversions<Value> { |
| 121 static std::unique_ptr<Value> parse(protocol::Value* value, ErrorSupport* er
rors) | 105 static std::unique_ptr<Value> parse(protocol::Value* value, ErrorSupport* er
rors) |
| 122 { | 106 { |
| 123 bool success = !!value; | 107 bool success = !!value; |
| 124 if (!success) { | 108 if (!success) { |
| 125 errors->addError("value expected"); | 109 errors->addError("value expected"); |
| 126 return nullptr; | 110 return nullptr; |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 174 { | 158 { |
| 175 return value->clone(); | 159 return value->clone(); |
| 176 } | 160 } |
| 177 | 161 |
| 178 static std::unique_ptr<protocol::Value> serialize(const std::unique_ptr<List
Value>& value) | 162 static std::unique_ptr<protocol::Value> serialize(const std::unique_ptr<List
Value>& value) |
| 179 { | 163 { |
| 180 return value->clone(); | 164 return value->clone(); |
| 181 } | 165 } |
| 182 }; | 166 }; |
| 183 | 167 |
| 184 } // namespace platform | 168 {% for namespace in config.protocol.namespace %} |
| 185 } // namespace blink | 169 } // namespace {{namespace}} |
| 170 {% endfor %} |
| 186 | 171 |
| 187 #endif // !defined(ValueConversions_h) | 172 #endif // !defined({{"_".join(config.protocol.namespace)}}_ValueConversions_h) |
| OLD | NEW |