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

Side by Side Diff: mojo/public/cpp/system/core.h

Issue 220063005: Adds ScopedHandleBase::From (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: wrong comment Created 6 years, 8 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef MOJO_PUBLIC_CPP_SYSTEM_CORE_H_ 5 #ifndef MOJO_PUBLIC_CPP_SYSTEM_CORE_H_
6 #define MOJO_PUBLIC_CPP_SYSTEM_CORE_H_ 6 #define MOJO_PUBLIC_CPP_SYSTEM_CORE_H_
7 7
8 #include <assert.h> 8 #include <assert.h>
9 #include <stddef.h> 9 #include <stddef.h>
10 10
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 42
43 // Move-only constructor and operator=. 43 // Move-only constructor and operator=.
44 ScopedHandleBase(RValue other) : handle_(other.object->release()) {} 44 ScopedHandleBase(RValue other) : handle_(other.object->release()) {}
45 ScopedHandleBase& operator=(RValue other) { 45 ScopedHandleBase& operator=(RValue other) {
46 handle_ = other.object->release(); 46 handle_ = other.object->release();
47 return *this; 47 return *this;
48 } 48 }
49 49
50 const HandleType& get() const { return handle_; } 50 const HandleType& get() const { return handle_; }
51 51
52 template <typename PassedHandleType>
53 static ScopedHandleBase<HandleType> From(
54 ScopedHandleBase<PassedHandleType> other) {
55 MOJO_COMPILE_ASSERT(
56 sizeof(static_cast<PassedHandleType*>(static_cast<HandleType*>(0))),
57 HandleType_is_not_a_subtype_of_PassedHandleType);
58 return ScopedHandleBase<HandleType>(
59 static_cast<HandleType>(other.release().value()));
darin (slow to review) 2014/04/04 22:40:49 Are you sure about the .value() call here? Doesn't
darin (slow to review) 2014/04/04 22:56:14 Nevermind. I somehow missed the compile assert :-P
60 }
61
52 void swap(ScopedHandleBase& other) { 62 void swap(ScopedHandleBase& other) {
53 handle_.swap(other.handle_); 63 handle_.swap(other.handle_);
54 } 64 }
55 65
56 HandleType release() MOJO_WARN_UNUSED_RESULT { 66 HandleType release() MOJO_WARN_UNUSED_RESULT {
57 HandleType rv; 67 HandleType rv;
58 rv.swap(handle_); 68 rv.swap(handle_);
59 return rv; 69 return rv;
60 } 70 }
61 71
(...skipping 396 matching lines...) Expand 10 before | Expand all | Expand 10 after
458 CreateSharedBuffer(&options, num_bytes, &handle); 468 CreateSharedBuffer(&options, num_bytes, &handle);
459 assert(result == MOJO_RESULT_OK); 469 assert(result == MOJO_RESULT_OK);
460 } 470 }
461 471
462 inline SharedBuffer::~SharedBuffer() { 472 inline SharedBuffer::~SharedBuffer() {
463 } 473 }
464 474
465 } // namespace mojo 475 } // namespace mojo
466 476
467 #endif // MOJO_PUBLIC_CPP_SYSTEM_CORE_H_ 477 #endif // MOJO_PUBLIC_CPP_SYSTEM_CORE_H_
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698