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 MOJO_PUBLIC_CPP_BINDINGS_WTF_ARRAY_H_ | 5 #ifndef MOJO_PUBLIC_CPP_BINDINGS_WTF_ARRAY_H_ |
6 #define MOJO_PUBLIC_CPP_BINDINGS_WTF_ARRAY_H_ | 6 #define MOJO_PUBLIC_CPP_BINDINGS_WTF_ARRAY_H_ |
7 | 7 |
8 #include <stddef.h> | 8 #include <stddef.h> |
9 #include <utility> | 9 #include <utility> |
10 | 10 |
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
223 | 223 |
224 void Take(WTFArray* other) { | 224 void Take(WTFArray* other) { |
225 operator=(nullptr); | 225 operator=(nullptr); |
226 Swap(other); | 226 Swap(other); |
227 } | 227 } |
228 | 228 |
229 WTF::Vector<T> vec_; | 229 WTF::Vector<T> vec_; |
230 bool is_null_; | 230 bool is_null_; |
231 }; | 231 }; |
232 | 232 |
| 233 // A |TypeConverter| that will create a |WTFArray<T>| containing a copy of the |
| 234 // contents of a |WTF::Vector<E, c, A>|, using |TypeConverter<T, E>| to copy |
| 235 // each element. The returned array will always be non-null. |
| 236 template <typename T, typename E, size_t c, typename A> |
| 237 struct TypeConverter<WTFArray<T>, WTF::Vector<E, c, A>> { |
| 238 static WTFArray<T> Convert(const WTF::Vector<E, c, A>& input) { |
| 239 WTFArray<T> result(input.size()); |
| 240 for (size_t i = 0; i < input.size(); ++i) |
| 241 result[i] = TypeConverter<T, E>::Convert(input[i]); |
| 242 return std::move(result); |
| 243 } |
| 244 }; |
| 245 |
233 } // namespace mojo | 246 } // namespace mojo |
234 | 247 |
235 #endif // MOJO_PUBLIC_CPP_BINDINGS_WTF_ARRAY_H_ | 248 #endif // MOJO_PUBLIC_CPP_BINDINGS_WTF_ARRAY_H_ |
OLD | NEW |