OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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_ARRAY_H_ | 5 #ifndef MOJO_PUBLIC_CPP_BINDINGS_ARRAY_H_ |
6 #define MOJO_PUBLIC_CPP_BINDINGS_ARRAY_H_ | 6 #define MOJO_PUBLIC_CPP_BINDINGS_ARRAY_H_ |
7 | 7 |
8 #include <string.h> | 8 #include <string.h> |
9 | 9 |
10 #include <algorithm> | 10 #include <algorithm> |
11 #include <cstddef> | 11 #include <cstddef> |
| 12 #include <iosfwd> |
12 #include <set> | 13 #include <set> |
13 #include <string> | 14 #include <string> |
14 #include <vector> | 15 #include <vector> |
15 | 16 |
16 #include "mojo/public/cpp/bindings/lib/array_internal.h" | 17 #include "mojo/public/cpp/bindings/lib/array_internal.h" |
17 #include "mojo/public/cpp/bindings/lib/bindings_internal.h" | 18 #include "mojo/public/cpp/bindings/lib/bindings_internal.h" |
18 #include "mojo/public/cpp/bindings/lib/template_util.h" | 19 #include "mojo/public/cpp/bindings/lib/template_util.h" |
19 #include "mojo/public/cpp/bindings/type_converter.h" | 20 #include "mojo/public/cpp/bindings/type_converter.h" |
20 | 21 |
21 namespace mojo { | 22 namespace mojo { |
(...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
302 static std::set<E> Convert(const Array<T>& input) { | 303 static std::set<E> Convert(const Array<T>& input) { |
303 std::set<E> result; | 304 std::set<E> result; |
304 if (!input.is_null()) { | 305 if (!input.is_null()) { |
305 for (size_t i = 0; i < input.size(); ++i) | 306 for (size_t i = 0; i < input.size(); ++i) |
306 result.insert(TypeConverter<E, T>::Convert(input[i])); | 307 result.insert(TypeConverter<E, T>::Convert(input[i])); |
307 } | 308 } |
308 return result; | 309 return result; |
309 } | 310 } |
310 }; | 311 }; |
311 | 312 |
| 313 // Prints the contents of an array to an output stream for debugging purposes. |
| 314 template <typename T> |
| 315 std::ostream& operator<<(std::ostream& os, const mojo::Array<T>& array) { |
| 316 if (array) { |
| 317 os << "["; |
| 318 bool first = true; |
| 319 for (auto it = array.storage().cbegin(); it != array.storage().cend(); |
| 320 ++it) { |
| 321 if (first) |
| 322 first = false; |
| 323 else |
| 324 os << ", "; |
| 325 os << *it; |
| 326 } |
| 327 os << "]"; |
| 328 } else { |
| 329 os << "null"; |
| 330 } |
| 331 return os; |
| 332 } |
| 333 |
312 } // namespace mojo | 334 } // namespace mojo |
313 | 335 |
314 #endif // MOJO_PUBLIC_CPP_BINDINGS_ARRAY_H_ | 336 #endif // MOJO_PUBLIC_CPP_BINDINGS_ARRAY_H_ |
OLD | NEW |