| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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_COMPTR_H_ | 5 #ifndef BASE_WIN_SCOPED_COMPTR_H_ |
| 6 #define BASE_WIN_SCOPED_COMPTR_H_ | 6 #define BASE_WIN_SCOPED_COMPTR_H_ |
| 7 | 7 |
| 8 #include <objbase.h> | 8 #include <objbase.h> |
| 9 #include <unknwn.h> | 9 #include <unknwn.h> |
| 10 | 10 |
| (...skipping 28 matching lines...) Expand all Loading... |
| 39 if (ptr_) | 39 if (ptr_) |
| 40 ptr_->AddRef(); | 40 ptr_->AddRef(); |
| 41 } | 41 } |
| 42 | 42 |
| 43 ~ScopedComPtr() { | 43 ~ScopedComPtr() { |
| 44 // We don't want the smart pointer class to be bigger than the pointer | 44 // We don't want the smart pointer class to be bigger than the pointer |
| 45 // it wraps. | 45 // it wraps. |
| 46 static_assert( | 46 static_assert( |
| 47 sizeof(ScopedComPtr<Interface, interface_id>) == sizeof(Interface*), | 47 sizeof(ScopedComPtr<Interface, interface_id>) == sizeof(Interface*), |
| 48 "ScopedComPtrSize"); | 48 "ScopedComPtrSize"); |
| 49 Release(); | 49 Reset(); |
| 50 } | 50 } |
| 51 | 51 |
| 52 Interface* get() const { return ptr_; } | 52 Interface* get() const { return ptr_; } |
| 53 | 53 |
| 54 explicit operator bool() const { return ptr_ != nullptr; } | 54 explicit operator bool() const { return ptr_ != nullptr; } |
| 55 | 55 |
| 56 // Explicit Release() of the held object. Useful for reuse of the | 56 // Explicit Release() of the held object. Useful for reuse of the |
| 57 // ScopedComPtr instance. | 57 // ScopedComPtr instance. |
| 58 // Note that this function equates to IUnknown::Release and should not | 58 // Note that this function equates to IUnknown::Release and should not |
| 59 // be confused with e.g. unique_ptr::release(). | 59 // be confused with e.g. unique_ptr::release(). |
| 60 void Release() { | 60 unsigned long Reset() { |
| 61 unsigned long ref = 0; |
| 61 Interface* temp = ptr_; | 62 Interface* temp = ptr_; |
| 62 if (temp) { | 63 if (temp) { |
| 63 ptr_ = nullptr; | 64 ptr_ = nullptr; |
| 64 temp->Release(); | 65 ref = temp->Release(); |
| 65 } | 66 } |
| 67 return ref; |
| 66 } | 68 } |
| 67 | 69 |
| 68 // Sets the internal pointer to NULL and returns the held object without | 70 // Sets the internal pointer to NULL and returns the held object without |
| 69 // releasing the reference. | 71 // releasing the reference. |
| 70 Interface* Detach() { | 72 Interface* Detach() { |
| 71 Interface* p = ptr_; | 73 Interface* p = ptr_; |
| 72 ptr_ = nullptr; | 74 ptr_ = nullptr; |
| 73 return p; | 75 return p; |
| 74 } | 76 } |
| 75 | 77 |
| (...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 256 // Helper to make IID_PPV_ARGS work with ScopedComPtr. | 258 // Helper to make IID_PPV_ARGS work with ScopedComPtr. |
| 257 template <typename T> | 259 template <typename T> |
| 258 void** IID_PPV_ARGS_Helper(base::win::ScopedComPtr<T>* pp) throw() { | 260 void** IID_PPV_ARGS_Helper(base::win::ScopedComPtr<T>* pp) throw() { |
| 259 return pp->ReceiveVoid(); | 261 return pp->ReceiveVoid(); |
| 260 } | 262 } |
| 261 | 263 |
| 262 } // namespace win | 264 } // namespace win |
| 263 } // namespace base | 265 } // namespace base |
| 264 | 266 |
| 265 #endif // BASE_WIN_SCOPED_COMPTR_H_ | 267 #endif // BASE_WIN_SCOPED_COMPTR_H_ |
| OLD | NEW |