Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(667)

Side by Side Diff: mojo/public/cpp/bindings/array.h

Issue 1519673002: Add helpers for logging mojom objects. (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: rebase Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | mojo/public/cpp/bindings/map.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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_
OLDNEW
« no previous file with comments | « no previous file | mojo/public/cpp/bindings/map.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698