Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 PDFium Authors. All rights reserved. | 1 // Copyright 2016 PDFium 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 CORE_FXCRT_CFX_RETAIN_PTR_H_ | 5 #ifndef CORE_FXCRT_CFX_RETAIN_PTR_H_ |
| 6 #define CORE_FXCRT_CFX_RETAIN_PTR_H_ | 6 #define CORE_FXCRT_CFX_RETAIN_PTR_H_ |
| 7 | 7 |
| 8 #include <memory> | 8 #include <memory> |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 30 | 30 |
| 31 void Reset(T* obj = nullptr) { | 31 void Reset(T* obj = nullptr) { |
| 32 if (obj) | 32 if (obj) |
| 33 obj->Retain(); | 33 obj->Retain(); |
| 34 m_pObj.reset(obj); | 34 m_pObj.reset(obj); |
| 35 } | 35 } |
| 36 | 36 |
| 37 T* Get() const { return m_pObj.get(); } | 37 T* Get() const { return m_pObj.get(); } |
| 38 void Swap(CFX_RetainPtr& that) { m_pObj.swap(that.m_pObj); } | 38 void Swap(CFX_RetainPtr& that) { m_pObj.swap(that.m_pObj); } |
| 39 | 39 |
| 40 // TODO(tsepez): temporary scaffolding, to be removed. | |
| 41 T* Leak() { return m_pObj.release(); } | |
| 42 void Unleak(T* ptr) { m_pObj.reset(ptr); } | |
|
Wei Li
2016/12/28 19:35:04
I don't quite understand the needs for these funct
| |
| 43 | |
| 40 CFX_RetainPtr& operator=(const CFX_RetainPtr& that) { | 44 CFX_RetainPtr& operator=(const CFX_RetainPtr& that) { |
| 41 if (*this != that) | 45 if (*this != that) |
| 42 Reset(that.Get()); | 46 Reset(that.Get()); |
| 43 return *this; | 47 return *this; |
| 44 } | 48 } |
| 45 | 49 |
| 46 bool operator==(const CFX_RetainPtr& that) const { | 50 bool operator==(const CFX_RetainPtr& that) const { |
| 47 return Get() == that.Get(); | 51 return Get() == that.Get(); |
| 48 } | 52 } |
| 49 | 53 |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 88 // Classes managed by CFX_RetainPtr should have protected (or private) | 92 // Classes managed by CFX_RetainPtr should have protected (or private) |
| 89 // constructors, and should friend this function. | 93 // constructors, and should friend this function. |
| 90 template <typename T, typename... Args> | 94 template <typename T, typename... Args> |
| 91 CFX_RetainPtr<T> MakeRetain(Args&&... args) { | 95 CFX_RetainPtr<T> MakeRetain(Args&&... args) { |
| 92 return CFX_RetainPtr<T>(new T(std::forward<Args>(args)...)); | 96 return CFX_RetainPtr<T>(new T(std::forward<Args>(args)...)); |
| 93 } | 97 } |
| 94 | 98 |
| 95 } // namespace pdfium | 99 } // namespace pdfium |
| 96 | 100 |
| 97 #endif // CORE_FXCRT_CFX_RETAIN_PTR_H_ | 101 #endif // CORE_FXCRT_CFX_RETAIN_PTR_H_ |
| OLD | NEW |