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.

139 lines
1.7 KiB

  1. /*++
  2. Copyright (C) 1996-1999 Microsoft Corporation
  3. Module Name:
  4. SMARTPTR.INL
  5. History:
  6. --*/
  7. template <class T>
  8. SmartPtr< T >::SmartPtr()
  9. {
  10. m_pObject = NULL;
  11. }
  12. template <class T>
  13. SmartPtr< T >::SmartPtr(
  14. T *pObject)
  15. {
  16. m_pObject = pObject;
  17. }
  18. template <class T>
  19. T &
  20. SmartPtr< T >::operator*(void)
  21. const
  22. {
  23. LTASSERT(m_pObject != NULL);
  24. return *m_pObject;
  25. }
  26. template <class T>
  27. T *
  28. SmartPtr< T >::operator->(void)
  29. const
  30. {
  31. LTASSERT(m_pObject != NULL);
  32. return m_pObject;
  33. }
  34. template <class T>
  35. T *
  36. SmartPtr< T >::Extract(void)
  37. {
  38. T *pObj = m_pObject;
  39. m_pObject = NULL;
  40. return pObj;
  41. }
  42. template <class T>
  43. T*
  44. SmartPtr< T >::GetPointer(void)
  45. {
  46. return m_pObject;
  47. }
  48. template <class T>
  49. const T*
  50. SmartPtr< T >::GetPointer(void) const
  51. {
  52. return m_pObject;
  53. }
  54. template <class T>
  55. BOOL
  56. SmartPtr< T >::IsNull(void)
  57. const
  58. {
  59. return m_pObject == NULL;
  60. }
  61. template <class T>
  62. void
  63. SmartPtr< T >::operator=(
  64. T *pObject)
  65. {
  66. LTASSERT(m_pObject == NULL);
  67. if (m_pObject != NULL)
  68. {
  69. delete m_pObject;
  70. }
  71. m_pObject = pObject;
  72. }
  73. //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  74. //
  75. // This should only be used to init a smart pointer.
  76. //
  77. //-----------------------------------------------------------------------------
  78. template <class T>
  79. SmartPtr< T >::operator T * & (void)
  80. {
  81. LTASSERT(m_pObject == NULL);
  82. return m_pObject;
  83. }
  84. template <class T>
  85. void
  86. SmartPtr< T >::operator delete(
  87. void *)
  88. {
  89. LTASSERT(m_pObject != NULL);
  90. delete m_pObject;
  91. m_pObject = NULL;
  92. }
  93. template <class T>
  94. SmartPtr< T >::~SmartPtr()
  95. {
  96. if (m_pObject != NULL)
  97. {
  98. delete m_pObject;
  99. }
  100. }