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

Side by Side Diff: core/fxcrt/cfx_retain_ptr.h

Issue 2382723003: Move core/fxcrt/include to core/fxcrt (Closed)
Patch Set: Rebase to master Created 4 years, 2 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
« no previous file with comments | « core/fxcrt/cfx_observable_unittest.cpp ('k') | core/fxcrt/cfx_retain_ptr_unittest.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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_INCLUDE_CFX_RETAIN_PTR_H_ 5 #ifndef CORE_FXCRT_CFX_RETAIN_PTR_H_
6 #define CORE_FXCRT_INCLUDE_CFX_RETAIN_PTR_H_ 6 #define CORE_FXCRT_CFX_RETAIN_PTR_H_
7 7
8 #include <memory> 8 #include <memory>
9 9
10 #include "core/fxcrt/include/fx_memory.h" 10 #include "core/fxcrt/fx_memory.h"
11 11
12 template <class T> 12 template <class T>
13 class CFX_RetainPtr { 13 class CFX_RetainPtr {
14 public: 14 public:
15 explicit CFX_RetainPtr(T* pObj) : m_pObj(pObj) { 15 explicit CFX_RetainPtr(T* pObj) : m_pObj(pObj) {
16 if (m_pObj) 16 if (m_pObj)
17 m_pObj->Retain(); 17 m_pObj->Retain();
18 } 18 }
19 19
20 CFX_RetainPtr() : CFX_RetainPtr(nullptr) {} 20 CFX_RetainPtr() : CFX_RetainPtr(nullptr) {}
21 CFX_RetainPtr(const CFX_RetainPtr& that) : CFX_RetainPtr(that.Get()) {} 21 CFX_RetainPtr(const CFX_RetainPtr& that) : CFX_RetainPtr(that.Get()) {}
22 CFX_RetainPtr(CFX_RetainPtr&& that) { Swap(that); } 22 CFX_RetainPtr(CFX_RetainPtr&& that) { Swap(that); }
23 23
24 template <class U> 24 template <class U>
25 CFX_RetainPtr(const CFX_RetainPtr<U>& that) 25 CFX_RetainPtr(const CFX_RetainPtr<U>& that) : CFX_RetainPtr(that.Get()) {}
26 : CFX_RetainPtr(that.Get()) {}
27 26
28 void Reset(T* obj = nullptr) { 27 void Reset(T* obj = nullptr) {
29 if (obj) 28 if (obj)
30 obj->Retain(); 29 obj->Retain();
31 m_pObj.reset(obj); 30 m_pObj.reset(obj);
32 } 31 }
33 32
34 T* Get() const { return m_pObj.get(); } 33 T* Get() const { return m_pObj.get(); }
35 void Swap(CFX_RetainPtr& that) { m_pObj.swap(that.m_pObj); } 34 void Swap(CFX_RetainPtr& that) { m_pObj.swap(that.m_pObj); }
36 35
(...skipping 10 matching lines...) Expand all
47 bool operator!=(const CFX_RetainPtr& that) const { return !(*this == that); } 46 bool operator!=(const CFX_RetainPtr& that) const { return !(*this == that); }
48 47
49 explicit operator bool() const { return !!m_pObj; } 48 explicit operator bool() const { return !!m_pObj; }
50 T& operator*() const { return *m_pObj.get(); } 49 T& operator*() const { return *m_pObj.get(); }
51 T* operator->() const { return m_pObj.get(); } 50 T* operator->() const { return m_pObj.get(); }
52 51
53 private: 52 private:
54 std::unique_ptr<T, ReleaseDeleter<T>> m_pObj; 53 std::unique_ptr<T, ReleaseDeleter<T>> m_pObj;
55 }; 54 };
56 55
57 #endif // CORE_FXCRT_INCLUDE_CFX_RETAIN_PTR_H_ 56 #endif // CORE_FXCRT_CFX_RETAIN_PTR_H_
OLDNEW
« no previous file with comments | « core/fxcrt/cfx_observable_unittest.cpp ('k') | core/fxcrt/cfx_retain_ptr_unittest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698