| 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 ValueConversions_h |
| 6 #define ValueConversions_h | 6 #define ValueConversions_h |
| 7 | 7 |
| 8 #include "platform/PlatformExport.h" | 8 #include "platform/PlatformExport.h" |
| 9 #include "platform/inspector_protocol/ErrorSupport.h" | 9 #include "platform/inspector_protocol/ErrorSupport.h" |
| 10 #include "platform/inspector_protocol/String16.h" | 10 #include "platform/inspector_protocol/String16.h" |
| 11 #include "platform/inspector_protocol/Values.h" | 11 #include "platform/inspector_protocol/Values.h" |
| 12 | 12 |
| 13 namespace blink { | 13 namespace blink { |
| 14 namespace protocol { | 14 namespace protocol { |
| 15 | 15 |
| 16 PLATFORM_EXPORT PassOwnPtr<protocol::Value> toValue(int value); | 16 PLATFORM_EXPORT std::unique_ptr<protocol::Value> toValue(int value); |
| 17 | 17 |
| 18 PLATFORM_EXPORT PassOwnPtr<protocol::Value> toValue(double value); | 18 PLATFORM_EXPORT std::unique_ptr<protocol::Value> toValue(double value); |
| 19 | 19 |
| 20 PLATFORM_EXPORT PassOwnPtr<protocol::Value> toValue(bool value); | 20 PLATFORM_EXPORT std::unique_ptr<protocol::Value> toValue(bool value); |
| 21 | 21 |
| 22 PLATFORM_EXPORT PassOwnPtr<protocol::Value> toValue(const String16& param); | 22 PLATFORM_EXPORT std::unique_ptr<protocol::Value> toValue(const String16& param); |
| 23 | 23 |
| 24 PLATFORM_EXPORT PassOwnPtr<protocol::Value> toValue(const String& param); | 24 PLATFORM_EXPORT std::unique_ptr<protocol::Value> toValue(const String& param); |
| 25 | 25 |
| 26 PLATFORM_EXPORT PassOwnPtr<protocol::Value> toValue(protocol::Value* param); | 26 PLATFORM_EXPORT std::unique_ptr<protocol::Value> toValue(protocol::Value* param)
; |
| 27 | 27 |
| 28 PLATFORM_EXPORT PassOwnPtr<protocol::Value> toValue(protocol::DictionaryValue* p
aram); | 28 PLATFORM_EXPORT std::unique_ptr<protocol::Value> toValue(protocol::DictionaryVal
ue* param); |
| 29 | 29 |
| 30 PLATFORM_EXPORT PassOwnPtr<protocol::Value> toValue(protocol::ListValue* param); | 30 PLATFORM_EXPORT std::unique_ptr<protocol::Value> toValue(protocol::ListValue* pa
ram); |
| 31 | 31 |
| 32 template<typename T> PassOwnPtr<protocol::Value> toValue(T* param) | 32 template<typename T> std::unique_ptr<protocol::Value> toValue(T* param) |
| 33 { | 33 { |
| 34 return param->serialize(); | 34 return param->serialize(); |
| 35 } | 35 } |
| 36 | 36 |
| 37 template<typename T> PassOwnPtr<protocol::Value> toValue(const OwnPtr<T>& param) | 37 template<typename T> std::unique_ptr<protocol::Value> toValue(const std::unique_
ptr<T>& param) |
| 38 { | 38 { |
| 39 static_assert(sizeof(T) == 0, "use raw pointer version."); | 39 static_assert(sizeof(T) == 0, "use raw pointer version."); |
| 40 return nullptr; | 40 return nullptr; |
| 41 } | 41 } |
| 42 | 42 |
| 43 template<typename T> PassOwnPtr<protocol::Value> toValue(PassOwnPtr<T> param) | 43 template<typename T> std::unique_ptr<protocol::Value> toValue(std::unique_ptr<T>
param) |
| 44 { | 44 { |
| 45 static_assert(sizeof(T) == 0, "use raw pointer version."); | 45 static_assert(sizeof(T) == 0, "use raw pointer version."); |
| 46 return nullptr; | 46 return nullptr; |
| 47 } | 47 } |
| 48 | 48 |
| 49 template<typename T> | 49 template<typename T> |
| 50 struct FromValue { | 50 struct FromValue { |
| 51 static PassOwnPtr<T> parse(protocol::Value* value, ErrorSupport* errors) | 51 static std::unique_ptr<T> parse(protocol::Value* value, ErrorSupport* errors
) |
| 52 { | 52 { |
| 53 return T::parse(value, errors); | 53 return T::parse(value, errors); |
| 54 } | 54 } |
| 55 }; | 55 }; |
| 56 | 56 |
| 57 template<> | 57 template<> |
| 58 struct FromValue<bool> { | 58 struct FromValue<bool> { |
| 59 static bool parse(protocol::Value* value, ErrorSupport* errors) | 59 static bool parse(protocol::Value* value, ErrorSupport* errors) |
| 60 { | 60 { |
| 61 bool result = false; | 61 bool result = false; |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 109 String16 result; | 109 String16 result; |
| 110 bool success = value ? value->asString(&result) : false; | 110 bool success = value ? value->asString(&result) : false; |
| 111 if (!success) | 111 if (!success) |
| 112 errors->addError("string value expected"); | 112 errors->addError("string value expected"); |
| 113 return result; | 113 return result; |
| 114 } | 114 } |
| 115 }; | 115 }; |
| 116 | 116 |
| 117 template<> | 117 template<> |
| 118 struct FromValue<Value> { | 118 struct FromValue<Value> { |
| 119 static PassOwnPtr<Value> parse(protocol::Value* value, ErrorSupport* errors) | 119 static std::unique_ptr<Value> parse(protocol::Value* value, ErrorSupport* er
rors) |
| 120 { | 120 { |
| 121 bool success = !!value; | 121 bool success = !!value; |
| 122 if (!success) | 122 if (!success) |
| 123 errors->addError("value expected"); | 123 errors->addError("value expected"); |
| 124 return value->clone(); | 124 return value->clone(); |
| 125 } | 125 } |
| 126 }; | 126 }; |
| 127 | 127 |
| 128 template<> | 128 template<> |
| 129 struct FromValue<DictionaryValue> { | 129 struct FromValue<DictionaryValue> { |
| 130 static PassOwnPtr<DictionaryValue> parse(protocol::Value* value, ErrorSuppor
t* errors) | 130 static std::unique_ptr<DictionaryValue> parse(protocol::Value* value, ErrorS
upport* errors) |
| 131 { | 131 { |
| 132 bool success = value && value->type() == protocol::Value::TypeObject; | 132 bool success = value && value->type() == protocol::Value::TypeObject; |
| 133 if (!success) | 133 if (!success) |
| 134 errors->addError("object expected"); | 134 errors->addError("object expected"); |
| 135 return DictionaryValue::cast(value->clone()); | 135 return DictionaryValue::cast(value->clone()); |
| 136 } | 136 } |
| 137 }; | 137 }; |
| 138 | 138 |
| 139 template<> | 139 template<> |
| 140 struct FromValue<ListValue> { | 140 struct FromValue<ListValue> { |
| 141 static PassOwnPtr<ListValue> parse(protocol::Value* value, ErrorSupport* err
ors) | 141 static std::unique_ptr<ListValue> parse(protocol::Value* value, ErrorSupport
* errors) |
| 142 { | 142 { |
| 143 bool success = value && value->type() == protocol::Value::TypeArray; | 143 bool success = value && value->type() == protocol::Value::TypeArray; |
| 144 if (!success) | 144 if (!success) |
| 145 errors->addError("list expected"); | 145 errors->addError("list expected"); |
| 146 return ListValue::cast(value->clone()); | 146 return ListValue::cast(value->clone()); |
| 147 } | 147 } |
| 148 }; | 148 }; |
| 149 | 149 |
| 150 template<typename T> class Array; | 150 template<typename T> class Array; |
| 151 | 151 |
| 152 template<typename T> | 152 template<typename T> |
| 153 struct FromValue<protocol::Array<T>> { | 153 struct FromValue<protocol::Array<T>> { |
| 154 static PassOwnPtr<protocol::Array<T>> parse(protocol::Value* value, ErrorSup
port* errors) | 154 static std::unique_ptr<protocol::Array<T>> parse(protocol::Value* value, Err
orSupport* errors) |
| 155 { | 155 { |
| 156 return protocol::Array<T>::parse(value, errors); | 156 return protocol::Array<T>::parse(value, errors); |
| 157 } | 157 } |
| 158 }; | 158 }; |
| 159 | 159 |
| 160 } // namespace platform | 160 } // namespace platform |
| 161 } // namespace blink | 161 } // namespace blink |
| 162 | 162 |
| 163 #endif // !defined(ValueConversions_h) | 163 #endif // !defined(ValueConversions_h) |
| OLD | NEW |