From 3403db90496fc87269d7bb1d033347ee19fc0c38 Mon Sep 17 00:00:00 2001 From: Tom Sepez Date: Mon, 15 Jun 2015 16:58:19 -0700 Subject: Merge to XFA: Provide a constructor for CPDF_CountedObject. Original Review URL: https://codereview.chromium.org/1182903002. TBR=thestig@chromium.org Review URL: https://codereview.chromium.org/1191553005. --- core/include/fpdfapi/fpdf_resource.h | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) (limited to 'core/include') diff --git a/core/include/fpdfapi/fpdf_resource.h b/core/include/fpdfapi/fpdf_resource.h index 268e75c7bf..2787d97329 100644 --- a/core/include/fpdfapi/fpdf_resource.h +++ b/core/include/fpdfapi/fpdf_resource.h @@ -7,6 +7,7 @@ #ifndef CORE_INCLUDE_FPDFAPI_FPDF_RESOURCE_H_ #define CORE_INCLUDE_FPDFAPI_FPDF_RESOURCE_H_ +#include "../fxcrt/fx_system.h" #include "../fxge/fx_font.h" #include "fpdf_parser.h" @@ -37,14 +38,29 @@ class CPDF_Type1Font; class CPDF_Type3Font; typedef struct FT_FaceRec_* FXFT_Face; -template class CPDF_CountedObject +template class CPDF_CountedObject { public: - ObjClass m_Obj; - FX_DWORD m_nCount; + explicit CPDF_CountedObject(T* ptr) : m_nCount(1), m_pObj(ptr) { } + void reset(T* ptr) { // CAUTION: tosses prior ref counts. + m_nCount = 1; + m_pObj = ptr; + } + void clear() { // Now you're all weak ptrs ... + delete m_pObj; + m_pObj = nullptr; + } + T* get() const { return m_pObj; } + T* AddRef() { FXSYS_assert(m_pObj); ++m_nCount; return m_pObj; } + void RemoveRef() { if (m_nCount) --m_nCount; } + size_t use_count() const { return m_nCount; } + +protected: + size_t m_nCount; + T* m_pObj; }; -using CPDF_CountedColorSpace = CPDF_CountedObject; -using CPDF_CountedPattern = CPDF_CountedObject; +using CPDF_CountedColorSpace = CPDF_CountedObject; +using CPDF_CountedPattern = CPDF_CountedObject; #define PDFFONT_TYPE1 1 #define PDFFONT_TRUETYPE 2 -- cgit v1.2.3