13#ifndef OGR_REFCOUNTEDPTR_INCLUDED
14#define OGR_REFCOUNTEDPTR_INCLUDED
27template <
class T>
struct OGRRefCountedPtrBase
35 inline ~OGRRefCountedPtrBase()
44 inline OGRRefCountedPtrBase(
const OGRRefCountedPtrBase &other)
45 : OGRRefCountedPtrBase(other.m_poRawPtr, true)
55 inline OGRRefCountedPtrBase &operator=(
const OGRRefCountedPtrBase &other)
59 reset(other.m_poRawPtr);
69 inline OGRRefCountedPtrBase(OGRRefCountedPtrBase &&other)
71 std::swap(m_poRawPtr, other.m_poRawPtr);
80 inline OGRRefCountedPtrBase &operator=(OGRRefCountedPtrBase &&other)
83 std::swap(m_poRawPtr, other.m_poRawPtr);
93 inline void reset(T *poRawPtr =
nullptr,
bool add_ref =
true)
96#pragma GCC diagnostic push
97#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
100 m_poRawPtr->Release();
101 m_poRawPtr = poRawPtr;
102 if (m_poRawPtr && add_ref)
103 m_poRawPtr->Reference();
105#pragma GCC diagnostic pop
110 inline T *get()
const
120 inline T &operator*()
const
128 inline T *operator->()
const
134 inline explicit operator bool()
const
136 return m_poRawPtr !=
nullptr;
140 inline explicit OGRRefCountedPtrBase(T *poRawPtr =
nullptr,
142 : m_poRawPtr(poRawPtr)
145#pragma GCC diagnostic push
146#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
148 if (m_poRawPtr && add_ref)
149 m_poRawPtr->Reference();
151#pragma GCC diagnostic pop
168template <
class T>
struct OGRRefCountedPtr :
public OGRRefCountedPtrBase<T>
173inline bool operator==(
const OGRRefCountedPtr<T> &lhs, std::nullptr_t)
175 return lhs.get() ==
nullptr;
179inline bool operator==(std::nullptr_t,
const OGRRefCountedPtr<T> &rhs)
181 return rhs.get() ==
nullptr;
185inline bool operator!=(
const OGRRefCountedPtr<T> &lhs, std::nullptr_t)
187 return lhs.get() !=
nullptr;
191inline bool operator!=(std::nullptr_t,
const OGRRefCountedPtr<T> &rhs)
193 return rhs.get() !=
nullptr;