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

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

Issue 2250183003: Make the fuchsia mojo/public repo the source of truth. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 4 years, 4 months 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 | « mojo/public/cpp/bindings/callback.h ('k') | mojo/public/cpp/bindings/interface_handle.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #ifndef MOJO_PUBLIC_CPP_BINDINGS_FORMATTING_H_
6 #define MOJO_PUBLIC_CPP_BINDINGS_FORMATTING_H_
7
8 #include <iosfwd>
9
10 #include "mojo/public/cpp/bindings/array.h"
11 #include "mojo/public/cpp/bindings/map.h"
12 #include "mojo/public/cpp/bindings/struct_ptr.h"
13
14 namespace mojo {
15
16 // Prints the contents of an array to an output stream in a human-readable
17 // format.
18 template <typename T>
19 std::ostream& operator<<(std::ostream& os, const mojo::Array<T>& array) {
20 if (array) {
21 os << "[";
22 bool first = true;
23 for (auto it = array.storage().cbegin(); it != array.storage().cend();
24 ++it) {
25 if (first)
26 first = false;
27 else
28 os << ", ";
29 os << *it;
30 }
31 os << "]";
32 } else {
33 os << "null";
34 }
35 return os;
36 }
37
38 // Prints the contents of a map to an output stream in a human-readable
39 // format.
40 template <typename Key, typename Value>
41 std::ostream& operator<<(std::ostream& os, const mojo::Map<Key, Value>& map) {
42 if (map) {
43 os << "{";
44 bool first = true;
45 for (auto it = map.cbegin(); it != map.cend(); ++it) {
46 if (first)
47 first = false;
48 else
49 os << ", ";
50 os << it.GetKey() << ": " << it.GetValue();
51 }
52 os << "}";
53 } else {
54 os << "null";
55 }
56 return os;
57 }
58
59 // Prints the pointee of a Mojo structure pointer to an output stream
60 // assuming there exists an operator<< overload that accepts a const
61 // reference to the object.
62 template <typename T, typename = typename T::Data_>
63 std::ostream& operator<<(std::ostream& os, const T* value) {
64 return value ? os << *value : os << "null";
65 }
66 template <typename T>
67 std::ostream& operator<<(std::ostream& os, const StructPtr<T>& value) {
68 return os << value.get();
69 }
70 template <typename T>
71 std::ostream& operator<<(std::ostream& os, const InlinedStructPtr<T>& value) {
72 return os << value.get();
73 }
74
75 } // namespace mojo
76
77 #endif // MOJO_PUBLIC_CPP_BINDINGS_FORMATTING_H_
OLDNEW
« no previous file with comments | « mojo/public/cpp/bindings/callback.h ('k') | mojo/public/cpp/bindings/interface_handle.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698