3#ifndef PDFSDK_CXX_PDF_WRAPPER_BASE_H_INCLUDED_
4#define PDFSDK_CXX_PDF_WRAPPER_BASE_H_INCLUDED_
10#include <pdfsdk/cxx/exception.h>
14#define PDF_CXX_CORE_WRAPPER_DEFINE_MEMBERS_(Class, HandleType) \
18 Class(HandleType handle, bool adopt = false) noexcept \
19 : detail::RefCountedHandle<HandleType>(handle, adopt) { \
21 Class(const Class& rhs) noexcept \
22 : detail::RefCountedHandle<HandleType>(rhs) { \
24 Class& operator=(const Class& rhs) noexcept { \
25 detail::RefCountedHandle<HandleType>::operator=(rhs); \
28 Class(Class&& rhs) noexcept \
29 : detail::RefCountedHandle<HandleType>(std::move(rhs)) { \
31 Class& operator=(Class&& rhs) noexcept { \
32 detail::RefCountedHandle<HandleType>::operator=(std::move(rhs)); \
35 ~Class() noexcept = default;
38#undef PDF_CXX_CORE_WRAPPER_DEFINE_MEMBERS_
39#define PDF_CXX_CORE_WRAPPER_DEFINE_MEMBERS_(Class, HandleType) \
42 Class(const Class& rhs) noexcept;
47template<
typename HandleType>
48class RefCountedHandle {
50 ~RefCountedHandle() noexcept {
54 RefCountedHandle() noexcept
58 RefCountedHandle(HandleType handle,
bool adopt =
false) noexcept
64 RefCountedHandle(
const RefCountedHandle& that) noexcept
65 : m_handle(that.m_handle) {
69 RefCountedHandle& operator=(
const RefCountedHandle& rhs)
noexcept {
75 RefCountedHandle(RefCountedHandle&& that) noexcept
76 : m_handle(that.m_handle) {
77 that.m_handle =
nullptr;
80 RefCountedHandle& operator=(RefCountedHandle&& rhs)
noexcept {
82 m_handle = rhs.m_handle;
83 rhs.m_handle =
nullptr;
88 void reset(HandleType handle,
bool adopt =
false) noexcept {
89 if (m_handle != handle) {
99 void reset() noexcept {
103 HandleType* operator&() noexcept {
108 HandleType get() const noexcept {
return m_handle; }
110 HandleType detach() noexcept {
return std::exchange(m_handle,
nullptr); }
112 bool operator==(
const RefCountedHandle& rhs)
const noexcept =
default;
114 bool operator==(
const HandleType& handle)
const noexcept {
return (m_handle == handle); }
115 friend bool operator==(
const HandleType& handle,
const RefCountedHandle& wrapper)
noexcept {
return (wrapper == handle); }
117 bool operator!=(
const HandleType& handle)
const noexcept {
return !(*
this == handle); }
118 friend bool operator!=(
const HandleType& handle,
const RefCountedHandle& wrapper)
noexcept {
return (wrapper != handle); }
120 explicit operator bool() const noexcept {
return !!m_handle; }
122 bool operator<(
const RefCountedHandle& rhs)
const noexcept {
return m_handle < rhs.m_handle; }
125 void Acquire() noexcept {
127 PDHandleAcquire(m_handle);
129 void Release() noexcept {
131 PDHandleRelease(m_handle);