//----------------------------------------------------------------------------- // // File: SmartRef.inl // Copyright (C) 1994-1997 Microsoft Corporation // All rights reserved. // // // //----------------------------------------------------------------------------- template SmartRef< T >::SmartRef( const SmartRef &other) { m_pInterface = const_cast(other.m_pInterface); m_pInterface->AddRef(); } template void SmartRef< T >::operator=( const SmartRef &pInterface) { if (m_pInterface != NULL) { m_pInterface->Release(); } m_pInterface = ((SmartRef &)pInterface).GetInterface(TRUE); } template T ** SmartRef< T >::operator&(void) { if (m_pInterface != NULL) { m_pInterface->Release(); m_pInterface = NULL; } return &m_pInterface; } template T * SmartRef< T >::ExtractImpl(void) { T *pInterface = m_pInterface; m_pInterface = NULL; return pInterface; } template T * SmartRef< T >::GetInterfaceImpl( BOOL fAddRef /*= FALSE*/) { // Should never ask to AddRef with a NULL pointer LTASSERT(!fAddRef || NULL != m_pInterface); if (fAddRef) { m_pInterface->AddRef(); } return m_pInterface; } //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ // // This should only be used to init a smart pointer. // //----------------------------------------------------------------------------- template T * & SmartRef< T >::opTpRef(void) { LTASSERT(m_pInterface == NULL); return m_pInterface; } template void SmartRef< T >::opEqImpl( T *pOther) { if (m_pInterface != NULL) { m_pInterface->Release(); } m_pInterface = pOther; }