Source code of Windows XP (NT5)
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.

79 lines
1.4 KiB

  1. /*****************************************************************************
  2. *
  3. * (C) COPYRIGHT MICROSOFT CORPORATION, 2000
  4. *
  5. * TITLE: gensph.h
  6. *
  7. * VERSION: 1.0
  8. *
  9. * AUTHOR: LazarI
  10. *
  11. * DATE: 23-Dec-2000
  12. *
  13. * DESCRIPTION: generic smart pointers & smart handles templates
  14. *
  15. *****************************************************************************/
  16. ////////////////////////////////////////////////
  17. //
  18. // class CRefPtrCOM
  19. //
  20. // referenced smart COM pointer (ATL style)
  21. //
  22. template <class T>
  23. inline void CRefPtrCOM<T>::_AddRefAttach(T *p)
  24. {
  25. if( IsntNull(p) )
  26. {
  27. p->AddRef();
  28. }
  29. Reset();
  30. m_p = (p ? p : GetNull());
  31. }
  32. template <class T>
  33. inline HRESULT CRefPtrCOM<T>::CopyFrom(T *p)
  34. {
  35. _AddRefAttach(p);
  36. return S_OK;
  37. }
  38. template <class T>
  39. inline HRESULT CRefPtrCOM<T>::CopyTo(T **ppObj)
  40. {
  41. HRESULT hr = E_INVALIDARG;
  42. if( ppObj )
  43. {
  44. *ppObj = m_p;
  45. if( IsntNull(*ppObj) )
  46. {
  47. (*ppObj)->AddRef();
  48. }
  49. hr = S_OK;
  50. }
  51. return hr;
  52. }
  53. template <class T>
  54. inline HRESULT CRefPtrCOM<T>::TransferTo(T **ppObj)
  55. {
  56. HRESULT hr = E_INVALIDARG;
  57. if( ppObj )
  58. {
  59. *ppObj = m_p;
  60. m_p = GetNull();
  61. hr = S_OK;
  62. }
  63. return hr;
  64. }
  65. template <class T>
  66. inline HRESULT CRefPtrCOM<T>::Adopt(T *p)
  67. {
  68. Reset();
  69. m_p = (p ? p : GetNull());
  70. return S_OK;
  71. }