Go to the documentation of this file.
30 #include "../../Primitives/interface/Object.h"
31 #include "../../Platforms/interface/Atomics.hpp"
89 pObj->QueryInterface(IID,
reinterpret_cast<IObject**
>(&m_pObject));
94 m_pObject{AutoPtr.m_pObject}
100 template <typename DerivedType, typename = typename std::enable_if<std::is_base_of<T, DerivedType>::value>::type>
108 m_pObject{std::move(AutoPtr.m_pObject)}
111 AutoPtr.m_pObject =
nullptr;
114 template <typename DerivedType, typename = typename std::enable_if<std::is_base_of<T, DerivedType>::value>::type>
116 m_pObject{std::move(AutoPtr.m_pObject)}
119 AutoPtr.m_pObject =
nullptr;
129 std::swap(m_pObject, AutoPtr.m_pObject);
149 m_pObject->Release();
156 if (m_pObject != pObj)
159 m_pObject->Release();
169 return *
this = AutoPtr.m_pObject;
172 template <typename DerivedType, typename = typename std::enable_if<std::is_base_of<T, DerivedType>::value>::type>
175 return *
this =
static_cast<T*
>(AutoPtr.m_pObject);
180 if (m_pObject != AutoPtr.m_pObject)
186 template <typename DerivedType, typename = typename std::enable_if<std::is_base_of<T, DerivedType>::value>::type>
189 if (m_pObject != AutoPtr.m_pObject)
198 bool operator!() const noexcept {
return m_pObject ==
nullptr; }
199 explicit operator bool() const noexcept {
return m_pObject !=
nullptr; }
202 bool operator<(
const RefCntAutoPtr& Ptr)
const noexcept {
return static_cast<const T*
>(*this) <
static_cast<const T*
>(Ptr); }
205 const T&
operator*() const noexcept {
return *m_pObject; }
207 T*
RawPtr() noexcept {
return m_pObject; }
208 const T*
RawPtr() const noexcept {
return m_pObject; }
210 template <
typename DstType>
211 DstType*
RawPtr() noexcept {
return ValidatedCast<DstType>(m_pObject); }
212 template <
typename DstType>
213 DstType*
RawPtr() const noexcept {
return ValidatedCast<DstType>(m_pObject); }
215 operator T*() noexcept {
return RawPtr(); }
216 operator const T*()
const noexcept {
return RawPtr(); }
221 template <
typename InterfaceType>
231 template <
typename DstType>
232 class DoublePtrHelper
236 NewRawPtr{
static_cast<DstType*
>(AutoPtr)},
237 m_pAutoPtr{std::addressof(AutoPtr)}
241 DoublePtrHelper(DoublePtrHelper&& Helper) noexcept :
242 NewRawPtr{Helper.NewRawPtr},
243 m_pAutoPtr{Helper.m_pAutoPtr}
245 Helper.m_pAutoPtr =
nullptr;
246 Helper.NewRawPtr =
nullptr;
251 if (m_pAutoPtr && *m_pAutoPtr !=
static_cast<T*
>(NewRawPtr))
253 m_pAutoPtr->Attach(
static_cast<T*
>(NewRawPtr));
257 DstType*&
operator*() noexcept {
return NewRawPtr; }
258 const DstType*
operator*() const noexcept {
return NewRawPtr; }
261 operator DstType**() noexcept {
return &NewRawPtr; }
262 operator const DstType**()
const noexcept {
return &NewRawPtr; }
270 DoublePtrHelper (
const DoublePtrHelper&) =
delete;
271 DoublePtrHelper&
operator = (
const DoublePtrHelper&) =
delete;
272 DoublePtrHelper&
operator = (DoublePtrHelper&&) =
delete;
277 template <typename DstType, typename = typename std::enable_if<std::is_convertible<T*, DstType*>::value>::type>
278 DoublePtrHelper<DstType>
DblPtr() noexcept {
return DoublePtrHelper<DstType>(*
this); }
279 template <typename DstType, typename = typename std::enable_if<std::is_convertible<T*, DstType*>::value>::type>
280 DoublePtrHelper<DstType>
DblPtr() const noexcept {
return DoublePtrHelper<DstType>(*
this); }
293 const T**
RawDblPtr() const noexcept {
return &m_pObject; }
295 template <typename DstType, typename = typename std::enable_if<std::is_convertible<T*, DstType*>::value>::type>
296 DstType**
RawDblPtr() noexcept {
return reinterpret_cast<DstType**
>(&m_pObject); }
297 template <typename DstType, typename = typename std::enable_if<std::is_convertible<T*, DstType*>::value>::type>
298 DstType**
RawDblPtr() const noexcept {
return reinterpret_cast<DstType**
>(&m_pObject); }
301 template <
typename OtherType>
304 T* m_pObject =
nullptr;
308 template <
typename T>
340 WeakPtr.m_pRefCounters =
nullptr;
341 WeakPtr.m_pObject =
nullptr;
345 m_pRefCounters{AutoPtr ? ValidatedCast<RefCountersImpl>(AutoPtr->GetReferenceCounters()) :
nullptr},
354 if (*
this == WeakPtr)
372 if (*
this == WeakPtr)
376 m_pObject = std::move(WeakPtr.m_pObject);
378 WeakPtr.m_pRefCounters =
nullptr;
379 WeakPtr.m_pObject =
nullptr;
RefCntWeakPtr & operator=(RefCntWeakPtr &&WeakPtr) noexcept
Definition: RefCntAutoPtr.hpp:370
RefCntAutoPtr(const RefCntAutoPtr< DerivedType > &AutoPtr) noexcept
Definition: RefCntAutoPtr.hpp:101
RefCntAutoPtr< InterfaceType > Cast(const INTERFACE_ID &IID) const
Definition: RefCntAutoPtr.hpp:222
bool operator!=(const RefCntAutoPtr &Ptr) const noexcept
Definition: RefCntAutoPtr.hpp:201
void Release() noexcept
Definition: RefCntAutoPtr.hpp:393
RefCntWeakPtr & operator=(RefCntAutoPtr< T > &AutoPtr) noexcept
Definition: RefCntAutoPtr.hpp:383
bool IsValid() const noexcept
Definition: RefCntAutoPtr.hpp:404
RefCntWeakPtr & operator=(T *pObj) noexcept
Definition: RefCntAutoPtr.hpp:365
virtual ReferenceCounterValueType AddWeakRef() override final
Definition: RefCountedObjectImpl.hpp:77
Implementation of weak pointers.
Definition: RefCntAutoPtr.hpp:40
Base interface for all dynamic objects in the engine.
Definition: Object.h:41
RefCntAutoPtr(IObject *pObj, const INTERFACE_ID &IID) noexcept
Definition: RefCntAutoPtr.hpp:85
bool operator!() const noexcept
Definition: RefCntAutoPtr.hpp:198
friend class RefCntAutoPtr
Definition: RefCntAutoPtr.hpp:302
~RefCntWeakPtr()
Definition: RefCntAutoPtr.hpp:323
virtual ReferenceCounterValueType ReleaseWeakRef() override final
Definition: RefCountedObjectImpl.hpp:82
void Release() noexcept
Definition: RefCntAutoPtr.hpp:145
RefCntWeakPtr & operator=(const RefCntWeakPtr &WeakPtr) noexcept
Definition: RefCntAutoPtr.hpp:352
const T & operator*() const noexcept
Definition: RefCntAutoPtr.hpp:205
Unique interface identifier.
Definition: InterfaceID.h:37
RefCntAutoPtr & operator=(RefCntAutoPtr< DerivedType > &&AutoPtr) noexcept
Definition: RefCntAutoPtr.hpp:187
~RefCntAutoPtr()
Definition: RefCntAutoPtr.hpp:122
T * RawPtr() noexcept
Definition: RefCntAutoPtr.hpp:207
bool operator==(const RefCntAutoPtr &Ptr) const noexcept
Definition: RefCntAutoPtr.hpp:200
T * Detach() noexcept
Definition: RefCntAutoPtr.hpp:138
RefCntAutoPtr(T *pObj) noexcept
Definition: RefCntAutoPtr.hpp:78
const T ** RawDblPtr() const noexcept
Definition: RefCntAutoPtr.hpp:293
DstType * RawPtr() noexcept
Definition: RefCntAutoPtr.hpp:211
DstType ** RawDblPtr() noexcept
Definition: RefCntAutoPtr.hpp:296
RefCntAutoPtr(const RefCntAutoPtr &AutoPtr) noexcept
Definition: RefCntAutoPtr.hpp:93
void swap(RefCntAutoPtr &AutoPtr) noexcept
Definition: RefCntAutoPtr.hpp:127
T * operator->() noexcept
Definition: RefCntAutoPtr.hpp:218
Template class that implements reference counting.
Definition: RefCntAutoPtr.hpp:73
virtual void GetObject(struct IObject **ppObject) override final
Definition: RefCountedObjectImpl.hpp:154
virtual ReferenceCounterValueType GetNumStrongRefs() const override final
Definition: RefCountedObjectImpl.hpp:205
DoublePtrHelper< DstType > DblPtr() const noexcept
Definition: RefCntAutoPtr.hpp:280
T ** RawDblPtr() noexcept
Definition: RefCntAutoPtr.hpp:292
RefCountersImpl * m_pRefCounters
Definition: RefCntAutoPtr.hpp:441
RefCntWeakPtr(RefCntAutoPtr< T > &AutoPtr) noexcept
Definition: RefCntAutoPtr.hpp:344
void Attach(T *pObj) noexcept
Definition: RefCntAutoPtr.hpp:132
RefCntWeakPtr(T *pObj=nullptr) noexcept
Definition: RefCntAutoPtr.hpp:312
T * m_pObject
Definition: RefCntAutoPtr.hpp:446
RefCntAutoPtr() noexcept
Definition: RefCntAutoPtr.hpp:76
Definition: RefCountedObjectImpl.hpp:44
RefCntAutoPtr(RefCntAutoPtr &&AutoPtr) noexcept
Definition: RefCntAutoPtr.hpp:107
DstType ** RawDblPtr() const noexcept
Definition: RefCntAutoPtr.hpp:298
RefCntAutoPtr(RefCntAutoPtr< DerivedType > &&AutoPtr) noexcept
Definition: RefCntAutoPtr.hpp:115
RefCntAutoPtr & operator=(T *pObj) noexcept
Definition: RefCntAutoPtr.hpp:154
T & operator*() noexcept
Definition: RefCntAutoPtr.hpp:204
const T * operator->() const noexcept
Definition: RefCntAutoPtr.hpp:219
bool operator==(const RefCntWeakPtr &Ptr) const noexcept
Definition: RefCntAutoPtr.hpp:437
RefCntAutoPtr & operator=(const RefCntAutoPtr< DerivedType > &AutoPtr) noexcept
Definition: RefCntAutoPtr.hpp:173
const T * RawPtr() const noexcept
Definition: RefCntAutoPtr.hpp:208
RefCntAutoPtr & operator=(const RefCntAutoPtr &AutoPtr) noexcept
Definition: RefCntAutoPtr.hpp:167
RefCntWeakPtr(const RefCntWeakPtr &WeakPtr) noexcept
Definition: RefCntAutoPtr.hpp:328
bool operator!=(const RefCntWeakPtr &Ptr) const noexcept
Definition: RefCntAutoPtr.hpp:438
RefCntAutoPtr< T > Lock()
Obtains a strong reference to the object.
Definition: RefCntAutoPtr.hpp:410
bool operator<(const RefCntAutoPtr &Ptr) const noexcept
Definition: RefCntAutoPtr.hpp:202
RefCntAutoPtr & operator=(RefCntAutoPtr &&AutoPtr) noexcept
Definition: RefCntAutoPtr.hpp:178
RefCntWeakPtr(RefCntWeakPtr &&WeakPtr) noexcept
Definition: RefCntAutoPtr.hpp:336
DoublePtrHelper< DstType > DblPtr() noexcept
Definition: RefCntAutoPtr.hpp:278
DstType * RawPtr() const noexcept
Definition: RefCntAutoPtr.hpp:213
DoublePtrHelper< T > operator&()
Definition: RefCntAutoPtr.hpp:282
The library uses Direct3D-style math:
Definition: AdvancedMath.hpp:37
const DoublePtrHelper< T > operator&() const
Definition: RefCntAutoPtr.hpp:287