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)); \
37#undef PDF_CXX_CORE_WRAPPER_DEFINE_MEMBERS_
38#define PDF_CXX_CORE_WRAPPER_DEFINE_MEMBERS_(Class, HandleType) \
41 Class(const Class& rhs) noexcept;
46template<
typename HandleType>
47class RefCountedHandle {
53 RefCountedHandle() noexcept
57 RefCountedHandle(HandleType handle,
bool adopt =
false) noexcept
63 RefCountedHandle(
const RefCountedHandle& that) noexcept
64 : m_handle(that.m_handle) {
68 RefCountedHandle& operator=(
const RefCountedHandle& rhs)
noexcept {
74 RefCountedHandle(RefCountedHandle&& that) noexcept
75 : m_handle(that.m_handle) {
76 that.m_handle =
nullptr;
79 RefCountedHandle& operator=(RefCountedHandle&& rhs)
noexcept {
80 reset(rhs.m_handle,
true);
81 rhs.m_handle =
nullptr;
86 void reset(HandleType handle,
bool adopt =
false) noexcept {
87 if (m_handle != handle) {
95 void reset() noexcept {
99 HandleType* operator&() noexcept {
104 HandleType get() const noexcept {
return m_handle; }
106 HandleType detach() noexcept {
107 auto detached = m_handle;
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);