OLD | NEW |
---|---|
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 Loading... | |
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 Loading... | |
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_ |
OLD | NEW |