| 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 Array_h | 5 #ifndef Array_h |
| 6 #define Array_h | 6 #define Array_h |
| 7 | 7 |
| 8 #include "platform/inspector_protocol/ErrorSupport.h" | 8 #include "platform/inspector_protocol/ErrorSupport.h" |
| 9 #include "platform/inspector_protocol/Platform.h" | 9 #include "platform/inspector_protocol/Platform.h" |
| 10 #include "platform/inspector_protocol/String16.h" | 10 #include "platform/inspector_protocol/String16.h" |
| (...skipping 16 matching lines...) Expand all Loading... |
| 27 static std::unique_ptr<Array<T>> parse(protocol::Value* value, ErrorSupport*
errors) | 27 static std::unique_ptr<Array<T>> parse(protocol::Value* value, ErrorSupport*
errors) |
| 28 { | 28 { |
| 29 protocol::ListValue* array = ListValue::cast(value); | 29 protocol::ListValue* array = ListValue::cast(value); |
| 30 if (!array) { | 30 if (!array) { |
| 31 errors->addError("array expected"); | 31 errors->addError("array expected"); |
| 32 return nullptr; | 32 return nullptr; |
| 33 } | 33 } |
| 34 std::unique_ptr<Array<T>> result(new Array<T>()); | 34 std::unique_ptr<Array<T>> result(new Array<T>()); |
| 35 errors->push(); | 35 errors->push(); |
| 36 for (size_t i = 0; i < array->size(); ++i) { | 36 for (size_t i = 0; i < array->size(); ++i) { |
| 37 errors->setName(String16::fromInteger(i)); | 37 errors->setName(string16FromInteger(i)); |
| 38 std::unique_ptr<T> item = ValueConversions<T>::parse(array->at(i), e
rrors); | 38 std::unique_ptr<T> item = ValueConversions<T>::parse(array->at(i), e
rrors); |
| 39 result->m_vector.push_back(std::move(item)); | 39 result->m_vector.push_back(std::move(item)); |
| 40 } | 40 } |
| 41 errors->pop(); | 41 errors->pop(); |
| 42 if (errors->hasErrors()) | 42 if (errors->hasErrors()) |
| 43 return nullptr; | 43 return nullptr; |
| 44 return result; | 44 return result; |
| 45 } | 45 } |
| 46 | 46 |
| 47 void addItem(std::unique_ptr<T> value) | 47 void addItem(std::unique_ptr<T> value) |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 82 static std::unique_ptr<Array<T>> parse(protocol::Value* value, ErrorSupport*
errors) | 82 static std::unique_ptr<Array<T>> parse(protocol::Value* value, ErrorSupport*
errors) |
| 83 { | 83 { |
| 84 protocol::ListValue* array = ListValue::cast(value); | 84 protocol::ListValue* array = ListValue::cast(value); |
| 85 if (!array) { | 85 if (!array) { |
| 86 errors->addError("array expected"); | 86 errors->addError("array expected"); |
| 87 return nullptr; | 87 return nullptr; |
| 88 } | 88 } |
| 89 errors->push(); | 89 errors->push(); |
| 90 std::unique_ptr<Array<T>> result(new Array<T>()); | 90 std::unique_ptr<Array<T>> result(new Array<T>()); |
| 91 for (size_t i = 0; i < array->size(); ++i) { | 91 for (size_t i = 0; i < array->size(); ++i) { |
| 92 errors->setName(String16::fromInteger(i)); | 92 errors->setName(string16FromInteger(i)); |
| 93 T item = ValueConversions<T>::parse(array->at(i), errors); | 93 T item = ValueConversions<T>::parse(array->at(i), errors); |
| 94 result->m_vector.push_back(item); | 94 result->m_vector.push_back(item); |
| 95 } | 95 } |
| 96 errors->pop(); | 96 errors->pop(); |
| 97 if (errors->hasErrors()) | 97 if (errors->hasErrors()) |
| 98 return nullptr; | 98 return nullptr; |
| 99 return result; | 99 return result; |
| 100 } | 100 } |
| 101 | 101 |
| 102 void addItem(const T& value) | 102 void addItem(const T& value) |
| (...skipping 16 matching lines...) Expand all Loading... |
| 119 std::unique_ptr<protocol::ListValue> result = ListValue::create(); | 119 std::unique_ptr<protocol::ListValue> result = ListValue::create(); |
| 120 for (auto& item : m_vector) | 120 for (auto& item : m_vector) |
| 121 result->pushValue(ValueConversions<T>::serialize(item)); | 121 result->pushValue(ValueConversions<T>::serialize(item)); |
| 122 return result; | 122 return result; |
| 123 } | 123 } |
| 124 | 124 |
| 125 private: | 125 private: |
| 126 std::vector<T> m_vector; | 126 std::vector<T> m_vector; |
| 127 }; | 127 }; |
| 128 | 128 |
| 129 template<> class Array<String> : public ArrayBase<String> {}; | 129 template<> class Array<InspectorProtocolConvenienceStringType> : public ArrayBas
e<InspectorProtocolConvenienceStringType> {}; |
| 130 template<> class Array<String16> : public ArrayBase<String16> {}; | 130 template<> class Array<String16> : public ArrayBase<String16> {}; |
| 131 template<> class Array<int> : public ArrayBase<int> {}; | 131 template<> class Array<int> : public ArrayBase<int> {}; |
| 132 template<> class Array<double> : public ArrayBase<double> {}; | 132 template<> class Array<double> : public ArrayBase<double> {}; |
| 133 template<> class Array<bool> : public ArrayBase<bool> {}; | 133 template<> class Array<bool> : public ArrayBase<bool> {}; |
| 134 | 134 |
| 135 } // namespace platform | 135 } // namespace platform |
| 136 } // namespace blink | 136 } // namespace blink |
| 137 | 137 |
| 138 #endif // !defined(Array_h) | 138 #endif // !defined(Array_h) |
| OLD | NEW |