From 917d24852841f4919f418076c0277d2742f961ca Mon Sep 17 00:00:00 2001 From: tsepez Date: Thu, 22 Sep 2016 18:46:45 -0700 Subject: Make CPDF_ColorSpace::Load() return a unique_ptr Specialize default_delete to avoid having to say ReleaseDeleter throughout the code. Review-Url: https://codereview.chromium.org/2368433003 --- core/fpdfapi/fpdf_page/include/cpdf_colorspace.h | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) (limited to 'core/fpdfapi/fpdf_page/include') diff --git a/core/fpdfapi/fpdf_page/include/cpdf_colorspace.h b/core/fpdfapi/fpdf_page/include/cpdf_colorspace.h index fc0433f52f..2166f9b3a8 100644 --- a/core/fpdfapi/fpdf_page/include/cpdf_colorspace.h +++ b/core/fpdfapi/fpdf_page/include/cpdf_colorspace.h @@ -7,6 +7,8 @@ #ifndef CORE_FPDFAPI_FPDF_PAGE_INCLUDE_CPDF_COLORSPACE_H_ #define CORE_FPDFAPI_FPDF_PAGE_INCLUDE_CPDF_COLORSPACE_H_ +#include + #include "core/fxcrt/include/cfx_weak_ptr.h" #include "core/fxcrt/include/fx_string.h" #include "core/fxcrt/include/fx_system.h" @@ -30,10 +32,11 @@ class CPDF_Object; class CPDF_ColorSpace { public: static CPDF_ColorSpace* GetStockCS(int Family); - static CPDF_ColorSpace* Load(CPDF_Document* pDoc, CPDF_Object* pCSObj); static CPDF_ColorSpace* ColorspaceFromName(const CFX_ByteString& name); + static std::unique_ptr Load(CPDF_Document* pDoc, + CPDF_Object* pCSObj); - void ReleaseCS(); + void Release(); int GetBufSize() const; FX_FLOAT* CreateBuf(); @@ -104,4 +107,18 @@ class CPDF_ColorSpace { using CPDF_CountedColorSpace = CFX_WeakPtr::Handle; +namespace std { + +// Make std::unique_ptr call Release() rather than +// simply deleting the object. +template <> +struct default_delete { + void operator()(CPDF_ColorSpace* pColorSpace) const { + if (pColorSpace) + pColorSpace->Release(); + } +}; + +} // namespace std + #endif // CORE_FPDFAPI_FPDF_PAGE_INCLUDE_CPDF_COLORSPACE_H_ -- cgit v1.2.3