summaryrefslogtreecommitdiff
path: root/core/include/fpdfapi/fpdf_resource.h
diff options
context:
space:
mode:
authorTom Sepez <tsepez@chromium.org>2015-06-15 16:43:26 -0700
committerTom Sepez <tsepez@chromium.org>2015-06-15 16:43:26 -0700
commit9869e6782f247177955eab27d3d480026365e75b (patch)
treeef76adf8379bcdce8eecc61eda9a3e3e0e295071 /core/include/fpdfapi/fpdf_resource.h
parent38f5c338fdc2daf79668cf7567298d9f62e4ba23 (diff)
downloadpdfium-9869e6782f247177955eab27d3d480026365e75b.tar.xz
Provide a constructor for CPDF_CountedObject.
Make members protected and remove external manipulations. Move "*" into template since its always an indirection. R=thestig@chromium.org Review URL: https://codereview.chromium.org/1182903002.
Diffstat (limited to 'core/include/fpdfapi/fpdf_resource.h')
-rw-r--r--core/include/fpdfapi/fpdf_resource.h26
1 files changed, 21 insertions, 5 deletions
diff --git a/core/include/fpdfapi/fpdf_resource.h b/core/include/fpdfapi/fpdf_resource.h
index 1aa0347c6e..19ba818180 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 ObjClass> class CPDF_CountedObject
+template <class T> 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<CPDF_ColorSpace*>;
-using CPDF_CountedPattern = CPDF_CountedObject<CPDF_Pattern*>;
+using CPDF_CountedColorSpace = CPDF_CountedObject<CPDF_ColorSpace>;
+using CPDF_CountedPattern = CPDF_CountedObject<CPDF_Pattern>;
#define PDFFONT_TYPE1 1
#define PDFFONT_TRUETYPE 2