OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 BASE_WIN_SCOPED_HANDLE_H_ | 5 #ifndef BASE_WIN_SCOPED_HANDLE_H_ |
6 #define BASE_WIN_SCOPED_HANDLE_H_ | 6 #define BASE_WIN_SCOPED_HANDLE_H_ |
7 | 7 |
8 #include <windows.h> | 8 #include <windows.h> |
9 | 9 |
10 #include "base/base_export.h" | 10 #include "base/base_export.h" |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
42 public: | 42 public: |
43 typedef typename Traits::Handle Handle; | 43 typedef typename Traits::Handle Handle; |
44 | 44 |
45 GenericScopedHandle() : handle_(Traits::NullHandle()) {} | 45 GenericScopedHandle() : handle_(Traits::NullHandle()) {} |
46 | 46 |
47 explicit GenericScopedHandle(Handle handle) : handle_(Traits::NullHandle()) { | 47 explicit GenericScopedHandle(Handle handle) : handle_(Traits::NullHandle()) { |
48 Set(handle); | 48 Set(handle); |
49 } | 49 } |
50 | 50 |
51 // Move constructor for C++03 move emulation of this type. | 51 // Move constructor for C++03 move emulation of this type. |
52 GenericScopedHandle(RValue& other) : handle_(Traits::NullHandle()) { | 52 GenericScopedHandle(RValue other) : handle_(Traits::NullHandle()) { |
53 Set(other.Take()); | 53 Set(other.object->Take()); |
54 } | 54 } |
55 | 55 |
56 ~GenericScopedHandle() { | 56 ~GenericScopedHandle() { |
57 Close(); | 57 Close(); |
58 } | 58 } |
59 | 59 |
60 bool IsValid() const { | 60 bool IsValid() const { |
61 return Traits::IsHandleValid(handle_); | 61 return Traits::IsHandleValid(handle_); |
62 } | 62 } |
63 | 63 |
64 // Move operator= for C++03 move emulation of this type. | 64 // Move operator= for C++03 move emulation of this type. |
65 GenericScopedHandle& operator=(RValue& other) { | 65 GenericScopedHandle& operator=(RValue other) { |
66 if (this != &other) { | 66 if (this != other.object) { |
67 Set(other.Take()); | 67 Set(other.object->Take()); |
68 } | 68 } |
69 return *this; | 69 return *this; |
70 } | 70 } |
71 | 71 |
72 void Set(Handle handle) { | 72 void Set(Handle handle) { |
73 if (handle_ != handle) { | 73 if (handle_ != handle) { |
74 Close(); | 74 Close(); |
75 | 75 |
76 if (Traits::IsHandleValid(handle)) { | 76 if (Traits::IsHandleValid(handle)) { |
77 handle_ = handle; | 77 handle_ = handle; |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
179 private: | 179 private: |
180 DISALLOW_IMPLICIT_CONSTRUCTORS(VerifierTraits); | 180 DISALLOW_IMPLICIT_CONSTRUCTORS(VerifierTraits); |
181 }; | 181 }; |
182 | 182 |
183 typedef GenericScopedHandle<HandleTraits, VerifierTraits> ScopedHandle; | 183 typedef GenericScopedHandle<HandleTraits, VerifierTraits> ScopedHandle; |
184 | 184 |
185 } // namespace win | 185 } // namespace win |
186 } // namespace base | 186 } // namespace base |
187 | 187 |
188 #endif // BASE_SCOPED_HANDLE_WIN_H_ | 188 #endif // BASE_SCOPED_HANDLE_WIN_H_ |
OLD | NEW |