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

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

Issue 828373008: Allow constructing {Interface,Struct}Ptr from nullptr (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 11 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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_HANDLE_H_ 5 #ifndef MOJO_PUBLIC_CPP_SYSTEM_HANDLE_H_
6 #define MOJO_PUBLIC_CPP_SYSTEM_HANDLE_H_ 6 #define MOJO_PUBLIC_CPP_SYSTEM_HANDLE_H_
7 7
8 #include <assert.h> 8 #include <assert.h>
9 #include <limits> 9 #include <limits>
10 10
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
77 // 77 //
78 // Other |...Raw()| functions expose similar rough edges, e.g., dealing with raw 78 // Other |...Raw()| functions expose similar rough edges, e.g., dealing with raw
79 // pointers (and lengths) instead of taking |std::vector|s or similar. 79 // pointers (and lengths) instead of taking |std::vector|s or similar.
80 80
81 // ScopedHandleBase ------------------------------------------------------------ 81 // ScopedHandleBase ------------------------------------------------------------
82 82
83 // Scoper for the actual handle types defined further below. It's move-only, 83 // Scoper for the actual handle types defined further below. It's move-only,
84 // like the C++11 |unique_ptr|. 84 // like the C++11 |unique_ptr|.
85 template <class HandleType> 85 template <class HandleType>
86 class ScopedHandleBase { 86 class ScopedHandleBase {
87 MOJO_MOVE_ONLY_TYPE_FOR_CPP_03(ScopedHandleBase, RValue) 87 MOJO_MOVE_ONLY_TYPE(ScopedHandleBase)
88 88
89 public: 89 public:
90 ScopedHandleBase() {} 90 ScopedHandleBase() {}
91 explicit ScopedHandleBase(HandleType handle) : handle_(handle) {} 91 explicit ScopedHandleBase(HandleType handle) : handle_(handle) {}
92 ~ScopedHandleBase() { CloseIfNecessary(); } 92 ~ScopedHandleBase() { CloseIfNecessary(); }
93 93
94 template <class CompatibleHandleType> 94 template <class CompatibleHandleType>
95 explicit ScopedHandleBase(ScopedHandleBase<CompatibleHandleType> other) 95 explicit ScopedHandleBase(ScopedHandleBase<CompatibleHandleType> other)
96 : handle_(other.release()) {} 96 : handle_(other.release()) {}
97 97
98 // Move-only constructor and operator=. 98 // Move-only constructor and operator=.
99 ScopedHandleBase(RValue other) : handle_(other.object->release()) {} 99 ScopedHandleBase(ScopedHandleBase&& other) : handle_(other.release()) {}
100 ScopedHandleBase& operator=(RValue other) { 100 ScopedHandleBase& operator=(ScopedHandleBase&& other) {
101 if (other.object != this) { 101 if (&other != this) {
102 CloseIfNecessary(); 102 CloseIfNecessary();
103 handle_ = other.object->release(); 103 handle_ = other.release();
104 } 104 }
105 return *this; 105 return *this;
106 } 106 }
107 107
108 const HandleType& get() const { return handle_; } 108 const HandleType& get() const { return handle_; }
109 109
110 template <typename PassedHandleType> 110 template <typename PassedHandleType>
111 static ScopedHandleBase<HandleType> From( 111 static ScopedHandleBase<HandleType> From(
112 ScopedHandleBase<PassedHandleType> other) { 112 ScopedHandleBase<PassedHandleType> other) {
113 static_assert( 113 static_assert(
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after
296 } 296 }
297 297
298 // Strict weak ordering, so that |Handle|s can be used as keys in |std::map|s, 298 // Strict weak ordering, so that |Handle|s can be used as keys in |std::map|s,
299 inline bool operator<(const Handle a, const Handle b) { 299 inline bool operator<(const Handle a, const Handle b) {
300 return a.value() < b.value(); 300 return a.value() < b.value();
301 } 301 }
302 302
303 } // namespace mojo 303 } // namespace mojo
304 304
305 #endif // MOJO_PUBLIC_CPP_SYSTEM_HANDLE_H_ 305 #endif // MOJO_PUBLIC_CPP_SYSTEM_HANDLE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698