Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

106 lines
1.6 KiB

  1. /*++
  2. Copyright (C) 1996-1999 Microsoft Corporation
  3. Module Name:
  4. SMARTREF.INL
  5. History:
  6. --*/
  7. template <class T>
  8. SmartRef< T >::SmartRef(
  9. const SmartRef<T> &other)
  10. {
  11. m_pInterface = const_cast<T *>(other.m_pInterface);
  12. m_pInterface->AddRef();
  13. }
  14. template <class T>
  15. void
  16. SmartRef< T >::operator=(
  17. const SmartRef<T> &pInterface)
  18. {
  19. if (m_pInterface != NULL)
  20. {
  21. m_pInterface->Release();
  22. }
  23. m_pInterface = ((SmartRef<T> &)pInterface).GetInterface(TRUE);
  24. }
  25. template <class T>
  26. T **
  27. SmartRef< T >::operator&(void)
  28. {
  29. if (m_pInterface != NULL)
  30. {
  31. m_pInterface->Release();
  32. m_pInterface = NULL;
  33. }
  34. return &m_pInterface;
  35. }
  36. template <class T>
  37. T *
  38. SmartRef< T >::ExtractImpl(void)
  39. {
  40. T *pInterface = m_pInterface;
  41. m_pInterface = NULL;
  42. return pInterface;
  43. }
  44. template <class T>
  45. T *
  46. SmartRef< T >::GetInterfaceImpl(
  47. BOOL fAddRef /*= FALSE*/)
  48. {
  49. // Should never ask to AddRef with a NULL pointer
  50. LTASSERT(!fAddRef || NULL != m_pInterface);
  51. if (fAddRef)
  52. {
  53. m_pInterface->AddRef();
  54. }
  55. return m_pInterface;
  56. }
  57. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  58. //
  59. // This should only be used to init a smart pointer.
  60. //
  61. //-----------------------------------------------------------------------------
  62. template <class T>
  63. T * &
  64. SmartRef< T >::opTpRef(void)
  65. {
  66. LTASSERT(m_pInterface == NULL);
  67. return m_pInterface;
  68. }
  69. template <class T>
  70. void
  71. SmartRef< T >::opEqImpl(
  72. T *pOther)
  73. {
  74. if (m_pInterface != NULL)
  75. {
  76. m_pInterface->Release();
  77. }
  78. m_pInterface = pOther;
  79. }