| 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 {{"_".join(config.protocol.namespace)}}_Array_h | 5 #ifndef {{"_".join(config.protocol.namespace)}}_Array_h |
| 6 #define {{"_".join(config.protocol.namespace)}}_Array_h | 6 #define {{"_".join(config.protocol.namespace)}}_Array_h |
| 7 | 7 |
| 8 //#include "ErrorSupport.h" | 8 //#include "ErrorSupport.h" |
| 9 //#include "Forward.h" | 9 //#include "Forward.h" |
| 10 //#include "ValueConversions.h" | 10 //#include "ValueConversions.h" |
| 11 //#include "Values.h" | 11 //#include "Values.h" |
| 12 | 12 |
| 13 {% for namespace in config.protocol.namespace %} | 13 {% for namespace in config.protocol.namespace %} |
| 14 namespace {{namespace}} { | 14 namespace {{namespace}} { |
| 15 {% endfor %} | 15 {% endfor %} |
| 16 | 16 |
| 17 template<typename T> | 17 template<typename T> |
| 18 class Array { | 18 class Array { |
| 19 public: | 19 public: |
| 20 static std::unique_ptr<Array<T>> create() | 20 static std::unique_ptr<Array<T>> create() |
| 21 { | 21 { |
| 22 return wrapUnique(new Array<T>()); | 22 return std::unique_ptr<Array<T>>(new Array<T>()); |
| 23 } | 23 } |
| 24 | 24 |
| 25 static std::unique_ptr<Array<T>> parse(protocol::Value* value, ErrorSupport*
errors) | 25 static std::unique_ptr<Array<T>> parse(protocol::Value* value, ErrorSupport*
errors) |
| 26 { | 26 { |
| 27 protocol::ListValue* array = ListValue::cast(value); | 27 protocol::ListValue* array = ListValue::cast(value); |
| 28 if (!array) { | 28 if (!array) { |
| 29 errors->addError("array expected"); | 29 errors->addError("array expected"); |
| 30 return nullptr; | 30 return nullptr; |
| 31 } | 31 } |
| 32 std::unique_ptr<Array<T>> result(new Array<T>()); | 32 std::unique_ptr<Array<T>> result(new Array<T>()); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 67 | 67 |
| 68 private: | 68 private: |
| 69 std::vector<std::unique_ptr<T>> m_vector; | 69 std::vector<std::unique_ptr<T>> m_vector; |
| 70 }; | 70 }; |
| 71 | 71 |
| 72 template<typename T> | 72 template<typename T> |
| 73 class ArrayBase { | 73 class ArrayBase { |
| 74 public: | 74 public: |
| 75 static std::unique_ptr<Array<T>> create() | 75 static std::unique_ptr<Array<T>> create() |
| 76 { | 76 { |
| 77 return wrapUnique(new Array<T>()); | 77 return std::unique_ptr<Array<T>>(new Array<T>()); |
| 78 } | 78 } |
| 79 | 79 |
| 80 static std::unique_ptr<Array<T>> parse(protocol::Value* value, ErrorSupport*
errors) | 80 static std::unique_ptr<Array<T>> parse(protocol::Value* value, ErrorSupport*
errors) |
| 81 { | 81 { |
| 82 protocol::ListValue* array = ListValue::cast(value); | 82 protocol::ListValue* array = ListValue::cast(value); |
| 83 if (!array) { | 83 if (!array) { |
| 84 errors->addError("array expected"); | 84 errors->addError("array expected"); |
| 85 return nullptr; | 85 return nullptr; |
| 86 } | 86 } |
| 87 errors->push(); | 87 errors->push(); |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 127 template<> class Array<String> : public ArrayBase<String> {}; | 127 template<> class Array<String> : public ArrayBase<String> {}; |
| 128 template<> class Array<int> : public ArrayBase<int> {}; | 128 template<> class Array<int> : public ArrayBase<int> {}; |
| 129 template<> class Array<double> : public ArrayBase<double> {}; | 129 template<> class Array<double> : public ArrayBase<double> {}; |
| 130 template<> class Array<bool> : public ArrayBase<bool> {}; | 130 template<> class Array<bool> : public ArrayBase<bool> {}; |
| 131 | 131 |
| 132 {% for namespace in config.protocol.namespace %} | 132 {% for namespace in config.protocol.namespace %} |
| 133 } // namespace {{namespace}} | 133 } // namespace {{namespace}} |
| 134 {% endfor %} | 134 {% endfor %} |
| 135 | 135 |
| 136 #endif // !defined({{"_".join(config.protocol.namespace)}}_Array_h) | 136 #endif // !defined({{"_".join(config.protocol.namespace)}}_Array_h) |
| OLD | NEW |