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

Unified Diff: mojo/public/cpp/bindings/struct_ptr.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/string.h ('k') | mojo/public/cpp/bindings/tests/array_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: mojo/public/cpp/bindings/struct_ptr.h
diff --git a/mojo/public/cpp/bindings/struct_ptr.h b/mojo/public/cpp/bindings/struct_ptr.h
index 1b34a9ec036149c229d63d1f4a139ceb8de96093..1bfc0ed85b5484dddccf7bb5528bc9e704407a0b 100644
--- a/mojo/public/cpp/bindings/struct_ptr.h
+++ b/mojo/public/cpp/bindings/struct_ptr.h
@@ -6,6 +6,7 @@
#define MOJO_PUBLIC_CPP_BINDINGS_STRUCT_PTR_H_
#include <cstddef>
+#include <iosfwd>
#include <memory>
#include <new>
@@ -127,7 +128,7 @@ class InlinedStructPtr {
void reset() {
is_null_ = true;
- value_. ~Struct();
+ value_.~Struct();
new (&value_) Struct();
}
@@ -175,6 +176,22 @@ class InlinedStructPtr {
MOJO_MOVE_ONLY_TYPE(InlinedStructPtr);
};
+// Prints the pointee of a Mojo structure pointer to an output stream
+// for debugging purposes, assuming there exists an operator<< overload
+// that accepts a const reference to the object.
+template <typename T, typename = typename T::Data_>
+auto operator<<(std::ostream& os, const T* value) -> decltype(os << *value) {
+ return value ? os << *value : os << "null";
+}
+template <typename T>
+std::ostream& operator<<(std::ostream& os, const StructPtr<T>& value) {
+ return os << value.get();
+}
+template <typename T>
+std::ostream& operator<<(std::ostream& os, const InlinedStructPtr<T>& value) {
+ return os << value.get();
+}
+
} // namespace mojo
#endif // MOJO_PUBLIC_CPP_BINDINGS_STRUCT_PTR_H_
« no previous file with comments | « mojo/public/cpp/bindings/string.h ('k') | mojo/public/cpp/bindings/tests/array_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698