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

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

Issue 2038273002: Remove base/move.h (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: . Created 4 years, 6 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 <stdint.h> 8 #include <stdint.h>
9 #include <limits> 9 #include <limits>
10 10
11 #include "base/compiler_specific.h" 11 #include "base/compiler_specific.h"
12 #include "base/logging.h" 12 #include "base/logging.h"
13 #include "base/macros.h" 13 #include "base/macros.h"
14 #include "base/move.h"
15 #include "mojo/public/c/system/functions.h" 14 #include "mojo/public/c/system/functions.h"
16 #include "mojo/public/c/system/types.h" 15 #include "mojo/public/c/system/types.h"
17 16
18 namespace mojo { 17 namespace mojo {
19 18
20 // OVERVIEW 19 // OVERVIEW
21 // 20 //
22 // |Handle| and |...Handle|: 21 // |Handle| and |...Handle|:
23 // 22 //
24 // |Handle| is a simple, copyable wrapper for the C type |MojoHandle| (which is 23 // |Handle| is a simple, copyable wrapper for the C type |MojoHandle| (which is
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
65 // 64 //
66 // An exception are some of the |...Raw()| functions. E.g., |CloseRaw()| takes a 65 // An exception are some of the |...Raw()| functions. E.g., |CloseRaw()| takes a
67 // |Handle|, leaving the user to discard the wrapper. 66 // |Handle|, leaving the user to discard the wrapper.
68 // 67 //
69 // ScopedHandleBase ------------------------------------------------------------ 68 // ScopedHandleBase ------------------------------------------------------------
70 69
71 // Scoper for the actual handle types defined further below. It's move-only, 70 // Scoper for the actual handle types defined further below. It's move-only,
72 // like the C++11 |unique_ptr|. 71 // like the C++11 |unique_ptr|.
73 template <class HandleType> 72 template <class HandleType>
74 class ScopedHandleBase { 73 class ScopedHandleBase {
75 MOVE_ONLY_TYPE_FOR_CPP_03(ScopedHandleBase);
76
77 public: 74 public:
78 using RawHandleType = HandleType; 75 using RawHandleType = HandleType;
79 76
80 ScopedHandleBase() {} 77 ScopedHandleBase() {}
81 explicit ScopedHandleBase(HandleType handle) : handle_(handle) {} 78 explicit ScopedHandleBase(HandleType handle) : handle_(handle) {}
82 ~ScopedHandleBase() { CloseIfNecessary(); } 79 ~ScopedHandleBase() { CloseIfNecessary(); }
83 80
84 template <class CompatibleHandleType> 81 template <class CompatibleHandleType>
85 explicit ScopedHandleBase(ScopedHandleBase<CompatibleHandleType> other) 82 explicit ScopedHandleBase(ScopedHandleBase<CompatibleHandleType> other)
86 : handle_(other.release()) {} 83 : handle_(other.release()) {}
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
126 return handle_.value() == other.get().value(); 123 return handle_.value() == other.get().value();
127 } 124 }
128 125
129 private: 126 private:
130 void CloseIfNecessary() { 127 void CloseIfNecessary() {
131 if (handle_.is_valid()) 128 if (handle_.is_valid())
132 handle_.Close(); 129 handle_.Close();
133 } 130 }
134 131
135 HandleType handle_; 132 HandleType handle_;
133
134 DISALLOW_COPY_AND_ASSIGN(ScopedHandleBase);
136 }; 135 };
137 136
138 template <typename HandleType> 137 template <typename HandleType>
139 inline ScopedHandleBase<HandleType> MakeScopedHandle(HandleType handle) { 138 inline ScopedHandleBase<HandleType> MakeScopedHandle(HandleType handle) {
140 return ScopedHandleBase<HandleType>(handle); 139 return ScopedHandleBase<HandleType>(handle);
141 } 140 }
142 141
143 // Handle ---------------------------------------------------------------------- 142 // Handle ----------------------------------------------------------------------
144 143
145 const MojoHandle kInvalidHandleValue = MOJO_HANDLE_INVALID; 144 const MojoHandle kInvalidHandleValue = MOJO_HANDLE_INVALID;
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
299 } 298 }
300 299
301 // Comparison, so that |Handle|s can be used as keys in hash maps. 300 // Comparison, so that |Handle|s can be used as keys in hash maps.
302 inline bool operator==(const Handle a, const Handle b) { 301 inline bool operator==(const Handle a, const Handle b) {
303 return a.value() == b.value(); 302 return a.value() == b.value();
304 } 303 }
305 304
306 } // namespace mojo 305 } // namespace mojo
307 306
308 #endif // MOJO_PUBLIC_CPP_SYSTEM_HANDLE_H_ 307 #endif // MOJO_PUBLIC_CPP_SYSTEM_HANDLE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698