#pragma once namespace rp { template< typename _Ptr > class intrusive_ptr { public: typedef intrusive_ptr this_t; typedef _Ptr pointer_t; intrusive_ptr() : pointee( 0 ) { } intrusive_ptr( pointer_t* p ) : pointee( p ) { if( pointee ) intrusive_ptr_acquire( pointee ); } intrusive_ptr( const intrusive_ptr& rhs ) : pointee( rhs.pointee ) { if( pointee ) intrusive_ptr_acquire( pointee ); } template< typename T > intrusive_ptr( const intrusive_ptr< T >& rhs ) : pointee( rhs.get() ) { if( pointee ) intrusive_ptr_acquire( pointee ); } ~intrusive_ptr() { if( pointee ) intrusive_ptr_dispose( pointee ); } intrusive_ptr& operator =( const intrusive_ptr& rhs ) { // dispose me, acquire other this_t( rhs ).swap( *this ); return *this; } template< typename T > intrusive_ptr& operator =( const intrusive_ptr< T >& rhs ) { this_t( rhs ).swap( *this ); return *this; } template< typename T > bool operator ==( const intrusive_ptr< T >& rhs ) const { return pointee == rhs; } template< typename T > bool operator !=( const intrusive_ptr< T >& rhs ) const { return pointee != rhs; } operator bool() const { return pointee != 0; } bool operator !() const { return pointee == 0; } pointer_t* operator ->() const { return pointee; } pointer_t& operator *() const { return *pointee; } pointer_t* get() const { return pointee; } operator const pointer_t*() const { return pointee; } operator pointer_t*() { return pointee; } void swap( intrusive_ptr& rhs ) { pointer_t* temp = pointee; pointee = rhs.pointee; rhs.pointee = temp; } private: pointer_t* pointee; }; } // rp