버전
menu_open
link

include/AK/Tools/Common/AkSmartPtr.h

Go to the documentation of this file.
00001 
00002 //
00003 // Copyright (c) 2006 Audiokinetic Inc. / All Rights Reserved
00004 //
00006 
00007 // AkSmartPtr.h
00008 
00011 
00012 #ifndef _AK_SMARTPTR_H
00013 #define _AK_SMARTPTR_H
00014 
00015 #include <AK/SoundEngine/Common/AkTypes.h>
00016 
00017 template <class T> class CAkSmartPtr
00018 {
00019 public:
00021     AkForceInline CAkSmartPtr()
00022         : m_pT( NULL )
00023     {
00024     }
00025 
00027     AkForceInline CAkSmartPtr( T* in_pT )
00028     {
00029         m_pT = in_pT;
00030         if (m_pT)
00031             m_pT->AddRef();
00032     }
00033 
00035     AkForceInline CAkSmartPtr( const CAkSmartPtr<T>& in_rPtr )
00036     {
00037         m_pT = in_rPtr.m_pT;
00038         if (m_pT)
00039             m_pT->AddRef();
00040     }
00041 
00043     ~CAkSmartPtr()
00044     {
00045         Release();
00046     }
00047 
00049     AkForceInline void Release()
00050     {
00051         if( m_pT )
00052         {
00053             m_pT->Release();
00054             m_pT = NULL;
00055         }
00056     }
00057 
00059     AkForceInline void Attach( T* in_pObj )
00060     {
00061         _Assign( in_pObj, false );   
00062     }
00063 
00065     AkForceInline T* Detach()
00066     {
00067         T* pObj = m_pT;
00068         m_pT = NULL;
00069 
00070         return pObj;
00071     }
00072 
00074     const CAkSmartPtr<T>& operator=( const CAkSmartPtr<T>& in_pObj )
00075     {
00076         _Assign( in_pObj.m_pT );
00077         return *this;
00078     }
00079 
00081     const CAkSmartPtr<T>& operator=( T* in_pObj )
00082     {
00083         _Assign( in_pObj );
00084         return *this;
00085     }
00086 
00088     T& operator*() { return *m_pT; }
00089 
00091     T* operator->() const { return m_pT; }
00092 
00094     operator T*() const { return m_pT; }
00095 
00097     T** operator &() { return &m_pT; }
00098 
00100     const T& operator*() const { return *m_pT; }
00101 
00103     T* Cast() { return m_pT; }
00104 
00106     const T* Cast() const { return m_pT; }
00107 
00108 protected:
00109 
00111     void _Assign( T* in_pObj, bool in_bAddRef = true )
00112     {
00113         if (in_pObj != NULL && in_bAddRef)
00114             in_pObj->AddRef();
00115 
00116         // Must use a local pointer since we cannot call Release(); without having set the m_pT to its final value.
00117         T* l_Ptr = m_pT;
00118         m_pT = in_pObj;
00119         if (l_Ptr)
00120             l_Ptr->Release();
00121     }
00122 
00124     bool _Compare( const T* in_pObj ) const
00125     {
00126         return m_pT == in_pObj;
00127     }
00128 
00130     T* m_pT; 
00131 };
00132 
00133 #endif // _AK_SMARTPTR_H
00134 

이 페이지가 도움이 되었나요?

지원이 필요하신가요?

질문이 있으신가요? 문제를 겪고 계신가요? 더 많은 정보가 필요하신가요? 저희에게 문의해주시면 도와드리겠습니다!

지원 페이지를 방문해 주세요

작업하는 프로젝트에 대해 알려주세요. 언제든지 도와드릴 준비가 되어 있습니다.

프로젝트를 등록하세요. 아무런 조건이나 의무 사항 없이 빠른 시작을 도와드리겠습니다.

Wwise를 시작해 보세요