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

Unified Diff: mojo/public/cpp/bindings/interface_ptr.h

Issue 405653003: mojo: Make InterfacePtr<> testable in if() statements without .get(). (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Move to is_bound() Created 6 years, 5 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « mojo/gles2/command_buffer_client_impl.cc ('k') | mojo/public/cpp/bindings/lib/interface_ptr_internal.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: mojo/public/cpp/bindings/interface_ptr.h
diff --git a/mojo/public/cpp/bindings/interface_ptr.h b/mojo/public/cpp/bindings/interface_ptr.h
index b868a0a5c36167c1885c16f597a600bfed4ecef2..01b15ed047d579df025a435d56433612ff5c49fa 100644
--- a/mojo/public/cpp/bindings/interface_ptr.h
+++ b/mojo/public/cpp/bindings/interface_ptr.h
@@ -104,6 +104,16 @@ class InterfacePtr {
return &internal_state_;
}
+ // Allow InterfacePtr<> to be used in boolean expressions, but not
+ // implicitly convertible to a real bool (which is dangerous).
+ private:
+ typedef internal::InterfacePtrState<Interface> InterfacePtr::*Testable;
+
+ public:
+ operator Testable() const {
+ return internal_state_.is_bound() ? &InterfacePtr::internal_state_ : NULL;
+ }
+
private:
typedef internal::InterfacePtrState<Interface> State;
mutable State internal_state_;
« no previous file with comments | « mojo/gles2/command_buffer_client_impl.cc ('k') | mojo/public/cpp/bindings/lib/interface_ptr_internal.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698