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

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

Issue 2366673003: Rename CPDF_CountedObject to CFX_WeakPtr::Handle (Closed)
Patch Set: comment 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/fpdfapi/fpdf_render/render_int.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2016 PDFium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6
7 #ifndef CORE_FXCRT_INCLUDE_CFX_WEAK_PTR_H_
8 #define CORE_FXCRT_INCLUDE_CFX_WEAK_PTR_H_
9
10 #include "core/fxcrt/include/fx_system.h"
11
12 template <class T>
13 class CFX_WeakPtr {
14 public:
15 class Handle {
16 public:
17 explicit Handle(T* ptr) : m_nCount(1), m_pObj(ptr) {}
18 void reset(T* ptr) { // CAUTION: tosses prior ref counts.
19 m_nCount = 1;
20 m_pObj = ptr;
21 }
22 void clear() { // Now you're all weak ptrs ...
23 // Guard against accidental re-entry.
24 T* pObj = m_pObj;
25 m_pObj = nullptr;
26 delete pObj;
27 }
28 T* get() const { return m_pObj; }
29 T* AddRef() {
30 ASSERT(m_pObj);
31 ++m_nCount;
32 return m_pObj;
33 }
34 void RemoveRef() {
35 if (m_nCount)
36 --m_nCount;
37 }
38 size_t use_count() const { return m_nCount; }
39
40 protected:
41 size_t m_nCount;
42 T* m_pObj;
43 };
44
45 // TODO(tsepez): implement weak pointer operations themselves.
46 };
47
48 #endif // CORE_FXCRT_INCLUDE_CFX_WEAK_PTR_H_
OLDNEW
« no previous file with comments | « core/fpdfapi/fpdf_render/render_int.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698