// Copyright 2016 The PDFium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #ifndef CORE_FXCRT_RETAIN_PTR_H_ #define CORE_FXCRT_RETAIN_PTR_H_ #include <stdint.h> #include <functional> #include <memory> #include <type_traits> #include <utility> #include "core/fxcrt/check.h" #include "core/fxcrt/compiler_specific.h" namespace fxcrt { // Used with std::unique_ptr to Release() objects that can't be deleted. template <class T> struct ReleaseDeleter { … }; // Analogous to base's scoped_refptr. template <class T> class TRIVIAL_ABI RetainPtr { … }; // Trivial implementation - internal ref count with virtual destructor. class Retainable { … }; } // namespace fxcrt ReleaseDeleter; Retainable; RetainPtr; namespace pdfium { // Helper to make a RetainPtr along the lines of std::make_unique<>(). // Arguments are forwarded to T's constructor. Classes managed by RetainPtr // should have protected (or private) constructors, and should friend this // function. template <typename T, typename... Args> RetainPtr<T> MakeRetain(Args&&... args) { … } // Type-deducing wrapper to make a RetainPtr from an ordinary pointer, // since equivalent constructor is explicit. template <typename T> RetainPtr<T> WrapRetain(T* that) { … } } // namespace pdfium // Macro to allow construction via MakeRetain<>() only, when used // with a private constructor in a class. #define CONSTRUCT_VIA_MAKE_RETAIN … #endif // CORE_FXCRT_RETAIN_PTR_H_