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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | mojo/public/cpp/bindings/map.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: mojo/public/cpp/bindings/array.h
diff --git a/mojo/public/cpp/bindings/array.h b/mojo/public/cpp/bindings/array.h
index c03da87a7fab388e9e54fc454af1a98e009c5033..bbf8e5c93cfa74ac10d3bc2ef25b68374ea13665 100644
--- a/mojo/public/cpp/bindings/array.h
+++ b/mojo/public/cpp/bindings/array.h
@@ -9,6 +9,7 @@
#include <algorithm>
#include <cstddef>
+#include <iosfwd>
#include <set>
#include <string>
#include <vector>
@@ -309,6 +310,27 @@ struct TypeConverter<std::set<E>, Array<T>> {
}
};
+// Prints the contents of an array to an output stream for debugging purposes.
+template <typename T>
+std::ostream& operator<<(std::ostream& os, const mojo::Array<T>& array) {
+ if (array) {
+ os << "[";
+ bool first = true;
+ for (auto it = array.storage().cbegin(); it != array.storage().cend();
+ ++it) {
+ if (first)
+ first = false;
+ else
+ os << ", ";
+ os << *it;
+ }
+ os << "]";
+ } else {
+ os << "null";
+ }
+ return os;
+}
+
} // namespace mojo
#endif // MOJO_PUBLIC_CPP_BINDINGS_ARRAY_H_
« 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