123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169 |
- #ifndef _AK_SMARTPTR_H
- #define _AK_SMARTPTR_H
- #include <AK/SoundEngine/Common/AkTypes.h>
- template <class T> class CAkSmartPtr
- {
- public:
-
- AkForceInline CAkSmartPtr()
- : m_pT( NULL )
- {
- }
-
- AkForceInline CAkSmartPtr( T* in_pT )
- {
- m_pT = in_pT;
- if (m_pT)
- m_pT->AddRef();
- }
-
- AkForceInline CAkSmartPtr( const CAkSmartPtr<T>& in_rPtr )
- {
- m_pT = in_rPtr.m_pT;
- if (m_pT)
- m_pT->AddRef();
- }
-
- AkForceInline CAkSmartPtr( CAkSmartPtr<T>&& in_rPtr )
- {
- m_pT = in_rPtr.m_pT;
- in_rPtr.m_pT = NULL;
- }
-
- ~CAkSmartPtr()
- {
- Release();
- }
-
- AkForceInline void Release()
- {
- if( m_pT )
- {
- m_pT->Release();
- m_pT = NULL;
- }
- }
-
- AkForceInline void Attach( T* in_pObj )
- {
- _Assign( in_pObj, false );
- }
-
- AkForceInline T* Detach()
- {
- T* pObj = m_pT;
- m_pT = NULL;
- return pObj;
- }
-
- const CAkSmartPtr<T>& operator=( const CAkSmartPtr<T>& in_pObj )
- {
- _Assign( in_pObj.m_pT );
- return *this;
- }
-
- CAkSmartPtr<T>& operator=( CAkSmartPtr<T>&& in_pObj )
- {
- _Assign( in_pObj.m_pT, false );
- in_pObj.m_pT = NULL;
- return *this;
- }
-
- const CAkSmartPtr<T>& operator=( T* in_pObj )
- {
- _Assign( in_pObj );
- return *this;
- }
-
- T& operator*() { return *m_pT; }
-
- T* operator->() const { return m_pT; }
-
- operator T*() const { return m_pT; }
-
- T** operator &() { return &m_pT; }
-
- const T& operator*() const { return *m_pT; }
-
- T* Cast() { return m_pT; }
-
- const T* Cast() const { return m_pT; }
- protected:
-
- void _Assign( T* in_pObj, bool in_bAddRef = true )
- {
- if (in_pObj != NULL && in_bAddRef)
- in_pObj->AddRef();
-
- T* l_Ptr = m_pT;
- m_pT = in_pObj;
- if (l_Ptr)
- l_Ptr->Release();
- }
-
- bool _Compare( const T* in_pObj ) const
- {
- return m_pT == in_pObj;
- }
-
- T* m_pT;
- };
- #endif
|