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

Side by Side Diff: core/fxcrt/include/cfx_count_ref.h

Issue 2287313004: Make CPDF_TextState have a CPDF_TextStateData rather than inheriting one. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@moar_better_constness
Patch Set: Casts, Casts, New -> Emplace. Created 4 years, 3 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_count_ref_unittest.cpp ('k') | core/fxge/agg/fx_agg_driver.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 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6 6
7 #ifndef CORE_FXCRT_INCLUDE_CFX_COUNT_REF_H_ 7 #ifndef CORE_FXCRT_INCLUDE_CFX_COUNT_REF_H_
8 #define CORE_FXCRT_INCLUDE_CFX_COUNT_REF_H_ 8 #define CORE_FXCRT_INCLUDE_CFX_COUNT_REF_H_
9 9
10 #include "core/fxcrt/include/cfx_retain_ptr.h" 10 #include "core/fxcrt/include/cfx_retain_ptr.h"
11 #include "core/fxcrt/include/fx_system.h" 11 #include "core/fxcrt/include/fx_system.h"
12 12
13 template <class ObjClass> 13 template <class ObjClass>
14 class CFX_CountRef { 14 class CFX_CountRef {
15 public: 15 public:
16 CFX_CountRef() {} 16 CFX_CountRef() {}
17 CFX_CountRef(const CFX_CountRef& other) : m_pObject(other.m_pObject) {} 17 CFX_CountRef(const CFX_CountRef& other) : m_pObject(other.m_pObject) {}
18 ~CFX_CountRef() {} 18 ~CFX_CountRef() {}
19 19
20 template <typename... Args> 20 template <typename... Args>
21 ObjClass* New(Args... params) { 21 ObjClass* Emplace(Args... params) {
22 m_pObject.Reset(new CountedObj(params...)); 22 m_pObject.Reset(new CountedObj(params...));
23 return m_pObject.Get(); 23 return m_pObject.Get();
24 } 24 }
25 25
26 CFX_CountRef& operator=(const CFX_CountRef& that) { 26 CFX_CountRef& operator=(const CFX_CountRef& that) {
27 if (*this != that) 27 if (*this != that)
28 m_pObject = that.m_pObject; 28 m_pObject = that.m_pObject;
29 return *this; 29 return *this;
30 } 30 }
31 31
32 void SetNull() { m_pObject.Reset(); } 32 void SetNull() { m_pObject.Reset(); }
33 const ObjClass* GetObject() const { return m_pObject.Get(); } 33 const ObjClass* GetObject() const { return m_pObject.Get(); }
34 34
35 template <typename... Args> 35 template <typename... Args>
36 ObjClass* GetPrivateCopy(Args... params) { 36 ObjClass* GetPrivateCopy(Args... params) {
37 if (!m_pObject) 37 if (!m_pObject)
38 return New(params...); 38 return Emplace(params...);
39 if (!m_pObject->HasOneRef()) 39 if (!m_pObject->HasOneRef())
40 m_pObject.Reset(new CountedObj(*m_pObject)); 40 m_pObject.Reset(new CountedObj(*m_pObject));
41 return m_pObject.Get(); 41 return m_pObject.Get();
42 } 42 }
43 43
44 bool operator==(const CFX_CountRef& that) const { 44 bool operator==(const CFX_CountRef& that) const {
45 return m_pObject == that.m_pObject; 45 return m_pObject == that.m_pObject;
46 } 46 }
47 bool operator!=(const CFX_CountRef& that) const { return !(*this == that); } 47 bool operator!=(const CFX_CountRef& that) const { return !(*this == that); }
48 operator bool() const { return m_pObject; } 48 operator bool() const { return m_pObject; }
(...skipping 14 matching lines...) Expand all
63 } 63 }
64 64
65 private: 65 private:
66 intptr_t m_RefCount; 66 intptr_t m_RefCount;
67 }; 67 };
68 68
69 CFX_RetainPtr<CountedObj> m_pObject; 69 CFX_RetainPtr<CountedObj> m_pObject;
70 }; 70 };
71 71
72 #endif // CORE_FXCRT_INCLUDE_CFX_COUNT_REF_H_ 72 #endif // CORE_FXCRT_INCLUDE_CFX_COUNT_REF_H_
OLDNEW
« no previous file with comments | « core/fxcrt/cfx_count_ref_unittest.cpp ('k') | core/fxge/agg/fx_agg_driver.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698