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 // 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 // A shared object with Copy on Write semantics that makes it appear as |
| 14 // if each one were independent. |
13 template <class ObjClass> | 15 template <class ObjClass> |
14 class CFX_CountRef { | 16 class CFX_CountRef { |
15 public: | 17 public: |
16 CFX_CountRef() {} | 18 CFX_CountRef() {} |
17 CFX_CountRef(const CFX_CountRef& other) : m_pObject(other.m_pObject) {} | 19 CFX_CountRef(const CFX_CountRef& other) : m_pObject(other.m_pObject) {} |
18 ~CFX_CountRef() {} | 20 ~CFX_CountRef() {} |
19 | 21 |
20 template <typename... Args> | 22 template <typename... Args> |
21 ObjClass* Emplace(Args... params) { | 23 ObjClass* Emplace(Args... params) { |
22 m_pObject.Reset(new CountedObj(params...)); | 24 m_pObject.Reset(new CountedObj(params...)); |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
63 } | 65 } |
64 | 66 |
65 private: | 67 private: |
66 intptr_t m_RefCount; | 68 intptr_t m_RefCount; |
67 }; | 69 }; |
68 | 70 |
69 CFX_RetainPtr<CountedObj> m_pObject; | 71 CFX_RetainPtr<CountedObj> m_pObject; |
70 }; | 72 }; |
71 | 73 |
72 #endif // CORE_FXCRT_INCLUDE_CFX_COUNT_REF_H_ | 74 #endif // CORE_FXCRT_INCLUDE_CFX_COUNT_REF_H_ |
OLD | NEW |