26 #include "DebugUtilities.h" 27 #include "LockHelper.h" 29 #include "ValidatedCast.h" 30 #include "RefCountedObjectImpl.h" 85 pObj->QueryInterface( IID, reinterpret_cast<IObject**>(&m_pObject) );
89 m_pObject(AutoPtr.m_pObject)
96 m_pObject(std::move(AutoPtr.m_pObject))
99 AutoPtr.m_pObject =
nullptr;
109 std::swap(m_pObject, AutoPtr.m_pObject);
129 m_pObject->Release();
136 if( static_cast<T*>(*
this) == pObj )
144 if( *
this == AutoPtr )
148 m_pObject = AutoPtr.m_pObject;
157 if( *
this == AutoPtr )
161 m_pObject = std::move( AutoPtr.m_pObject );
163 AutoPtr.m_pObject =
nullptr;
170 bool operator ! ()
const{
return m_pObject ==
nullptr;}
171 operator bool ()
const{
return m_pObject !=
nullptr;}
172 bool operator == (
const RefCntAutoPtr& Ptr)
const{
return m_pObject == Ptr.m_pObject;}
173 bool operator != (
const RefCntAutoPtr& Ptr)
const{
return m_pObject != Ptr.m_pObject;}
174 bool operator < (
const RefCntAutoPtr& Ptr)
const{
return static_cast<const T*
>(*this) <
static_cast<const T*
>(Ptr);}
176 T& operator * () {
return *m_pObject; }
177 const T& operator * ()
const {
return *m_pObject; }
179 T* RawPtr() {
return m_pObject; }
180 const T* RawPtr()
const{
return m_pObject; }
182 operator T* () {
return RawPtr(); }
183 operator const T* ()
const {
return RawPtr(); }
185 T* operator -> () {
return m_pObject; }
186 const T* operator -> ()
const{
return m_pObject; }
192 class DoublePtrHelper
196 NewRawPtr( static_cast<T*>(AutoPtr) ),
197 m_pAutoPtr( std::addressof(AutoPtr) )
201 DoublePtrHelper(DoublePtrHelper&& Helper) :
202 NewRawPtr(Helper.NewRawPtr),
203 m_pAutoPtr(Helper.m_pAutoPtr)
205 Helper.m_pAutoPtr =
nullptr;
206 Helper.NewRawPtr =
nullptr;
211 if( m_pAutoPtr && static_cast<T*>(*m_pAutoPtr) != NewRawPtr )
213 m_pAutoPtr->Attach(NewRawPtr);
217 T*& operator*(){
return NewRawPtr;}
218 const T* operator*()
const{
return NewRawPtr;}
220 operator T**(){
return &NewRawPtr;}
221 operator const T**()
const{
return &NewRawPtr;}
225 DoublePtrHelper(
const DoublePtrHelper&);
226 DoublePtrHelper& operator = (
const DoublePtrHelper&);
227 DoublePtrHelper& operator = (DoublePtrHelper&&);
231 DoublePtrHelper operator& ()
233 return DoublePtrHelper(*
this);
236 const DoublePtrHelper operator& ()
const 238 return DoublePtrHelper(*
this);
241 T** GetRawDblPtr() {
return &m_pObject;}
242 const T** GetRawDblPtr()
const{
return &m_pObject;}
249 template <
typename T>
255 m_pRefCounters(nullptr)
259 m_pRefCounters = ValidatedCast<RefCountersImpl>( m_pObject->GetReferenceCounters() );
260 m_pRefCounters->AddWeakRef();
269 RefCntWeakPtr(
const RefCntWeakPtr& WeakPtr) :
270 m_pObject(WeakPtr.m_pObject),
271 m_pRefCounters(WeakPtr.m_pRefCounters)
274 m_pRefCounters->AddWeakRef();
277 RefCntWeakPtr(RefCntWeakPtr&& WeakPtr) :
278 m_pObject(
std::move(WeakPtr.m_pObject)),
279 m_pRefCounters(
std::move(WeakPtr.m_pRefCounters))
281 WeakPtr.m_pRefCounters =
nullptr;
282 WeakPtr.m_pObject =
nullptr;
285 explicit RefCntWeakPtr(RefCntAutoPtr<T>& AutoPtr) :
286 m_pObject( static_cast<T*>(AutoPtr) ),
287 m_pRefCounters(AutoPtr ? ValidatedCast<RefCountersImpl>( AutoPtr->GetReferenceCounters() ) : nullptr)
290 m_pRefCounters->AddWeakRef();
293 RefCntWeakPtr& operator = (
const RefCntWeakPtr& WeakPtr)
295 if( *
this == WeakPtr )
299 m_pObject = WeakPtr.m_pObject;
300 m_pRefCounters = WeakPtr.m_pRefCounters;
302 m_pRefCounters->AddWeakRef();
306 RefCntWeakPtr& operator = (T *pObj)
308 return operator= (RefCntWeakPtr(pObj));
311 RefCntWeakPtr& operator = (RefCntWeakPtr&& WeakPtr)
313 if( *
this == WeakPtr )
317 m_pObject = std::move(WeakPtr.m_pObject);
318 m_pRefCounters = std::move(WeakPtr.m_pRefCounters);
319 WeakPtr.m_pRefCounters =
nullptr;
320 WeakPtr.m_pObject =
nullptr;
324 RefCntWeakPtr& operator = (RefCntAutoPtr<T>& AutoPtr)
327 m_pObject =
static_cast<T*
>( AutoPtr );
328 m_pRefCounters = m_pObject ? ValidatedCast<RefCountersImpl>( m_pObject->GetReferenceCounters() ) :
nullptr;
330 m_pRefCounters->AddWeakRef();
337 m_pRefCounters->ReleaseWeakRef();
338 m_pRefCounters =
nullptr;
347 return m_pObject !=
nullptr && m_pRefCounters !=
nullptr && m_pRefCounters->GetNumStrongRefs() > 0;
361 m_pRefCounters->GetObject( &spOwner );
378 bool operator == (
const RefCntWeakPtr& Ptr)
const{
return m_pRefCounters == Ptr.m_pRefCounters;}
379 bool operator != (
const RefCntWeakPtr& Ptr)
const{
return m_pRefCounters != Ptr.m_pRefCounters;}
382 RefCountersImpl *m_pRefCounters;
Namespace for the OpenGL implementation of the graphics engine.
Definition: BufferD3D11Impl.h:34
Definition: AdvancedMath.h:316
RefCntAutoPtr< T > Lock()
Obtains a strong reference to the object.
Definition: RefCntAutoPtr.h:351
Implementation of weak pointers.
Definition: RefCntAutoPtr.h:38
Template class that implements reference counting.
Definition: RefCntAutoPtr.h:71
bool IsValid()
Definition: RefCntAutoPtr.h:345