summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-04-05 02:40:31 +0000
committersky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-04-05 02:40:31 +0000
commitaafb94168f43048379600e44a3cf6b9f7f1cb86d (patch)
tree92b4e6e8c096cc5bbb5cd9640d58ad45bd7a36c0
parent97d3fe8b02e4b4e8f1bca053c79835778765e53f (diff)
downloadchromium_src-aafb94168f43048379600e44a3cf6b9f7f1cb86d.zip
chromium_src-aafb94168f43048379600e44a3cf6b9f7f1cb86d.tar.gz
chromium_src-aafb94168f43048379600e44a3cf6b9f7f1cb86d.tar.bz2
Adds ScopedHandleBase::From
Intended for use when converting from a ScopedMessagePipeHandle to some Interface, eg: ScopedXHandle::From(scoped_message_pipe_handle.Pass()); BUG=none TEST=none R=darin@chromium.org Review URL: https://codereview.chromium.org/220063005 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@261958 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--mojo/public/cpp/system/core.h10
1 files changed, 10 insertions, 0 deletions
diff --git a/mojo/public/cpp/system/core.h b/mojo/public/cpp/system/core.h
index 14fc900..4154ba8 100644
--- a/mojo/public/cpp/system/core.h
+++ b/mojo/public/cpp/system/core.h
@@ -113,6 +113,16 @@ class ScopedHandleBase {
const HandleType& get() const { return handle_; }
+ template <typename PassedHandleType>
+ static ScopedHandleBase<HandleType> From(
+ ScopedHandleBase<PassedHandleType> other) {
+ MOJO_COMPILE_ASSERT(
+ sizeof(static_cast<PassedHandleType*>(static_cast<HandleType*>(0))),
+ HandleType_is_not_a_subtype_of_PassedHandleType);
+ return ScopedHandleBase<HandleType>(
+ static_cast<HandleType>(other.release().value()));
+ }
+
void swap(ScopedHandleBase& other) {
handle_.swap(other.handle_);
}