#ifndef _INTRUSIVE_PTR_H_ #define _INTRUSIVE_PTR_H_ template< class T > class intrusive_ptr { public: intrusive_ptr():m_pPtr( NULL ) { }; intrusive_ptr( const intrusive_ptr<T> &intrptr ):m_pPtr( NULL ) { if( intrptr.m_pPtr!=NULL ) { this->m_pPtr = intrptr.m_pPtr; this->m_pPtr->AddRef(); } }; intrusive_ptr( T *in_ptr ):m_pPtr( NULL ) { if( in_ptr!=NULL ) { this->m_pPtr = in_ptr; this->m_pPtr->AddRef(); } }; virtual ~intrusive_ptr() { if( m_pPtr!=NULL ) { this->m_pPtr->Release(); } }; intrusive_ptr<T>& operator= (const intrusive_ptr<T> intrptr) { if( *this != intrptr ) { if( this->m_pPtr!=NULL ) { this->m_pPtr->Release() ; } this->m_pPtr = intrptr.m_pPtr ; this->m_pPtr->AddRef(); } return *this ; }; intrusive_ptr<T>& operator= ( T *in_ptr ) { if( this->m_pPtr!=NULL ) { this->m_pPtr->Release() ; } this->m_pPtr = in_ptr ; this->m_pPtr->AddRef(); return *this ; }; T* operator-> (void) const { return m_pPtr ? m_pPtr : NULL; }; T& operator*(void) const { return *m_pPtr; }; operator T*(void) const { return m_pPtr ? m_pPtr : NULL ; } bool operator == ( intrusive_ptr<T> intrptr) { return m_pPtr == intrptr.m_pPtr ; } bool operator != ( intrusive_ptr<T> intrptr ) { return m_pPtr != intrptr.m_pPtr ; } bool operator != ( T* intrptr ) { return m_pPtr != intrptr ; } private: T *m_pPtr; }; #endif