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.

107 lines
1.8 KiB

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