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

Unified Diff: mojo/public/cpp/bindings/map.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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « mojo/public/cpp/bindings/array.h ('k') | mojo/public/cpp/bindings/string.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: mojo/public/cpp/bindings/map.h
diff --git a/mojo/public/cpp/bindings/map.h b/mojo/public/cpp/bindings/map.h
index 0a0f8051a80dcbab88c9655f28b9aa0687c22e4c..80655b5ece5ddfe651e4d758eafd69337c318aec 100644
--- a/mojo/public/cpp/bindings/map.h
+++ b/mojo/public/cpp/bindings/map.h
@@ -5,6 +5,7 @@
#ifndef MOJO_PUBLIC_CPP_BINDINGS_MAP_H_
#define MOJO_PUBLIC_CPP_BINDINGS_MAP_H_
+#include <iosfwd>
#include <map>
#include <type_traits>
@@ -293,6 +294,26 @@ struct TypeConverter<std::map<STLKey, STLValue>, Map<MojoKey, MojoValue>> {
}
};
+// Prints the contents of a map to an output stream for debugging purposes.
+template <typename Key, typename Value>
+std::ostream& operator<<(std::ostream& os, const mojo::Map<Key, Value>& map) {
+ if (map) {
+ os << "[";
+ bool first = true;
+ for (auto it = map.cbegin(); it != map.cend(); ++it) {
+ if (first)
+ first = false;
+ else
+ os << ", ";
+ os << "{" << it.GetKey() << ": " << it.GetValue() << "}";
+ }
+ os << "]";
+ } else {
+ os << "null";
+ }
+ return os;
+}
+
} // namespace mojo
#endif // MOJO_PUBLIC_CPP_BINDINGS_MAP_H_
« no previous file with comments | « mojo/public/cpp/bindings/array.h ('k') | mojo/public/cpp/bindings/string.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698