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.

97 lines
1.7 KiB

  1. //-----------------------------------------------------------------------------
  2. //
  3. // File: SmartRef.h
  4. // Copyright (C) 1994-1997 Microsoft Corporation
  5. // All rights reserved.
  6. //
  7. //
  8. //
  9. //-----------------------------------------------------------------------------
  10. #ifndef ESPUTIL_SmartRef_H
  11. #define ESPUTIL_SmartRef_H
  12. template<class T>
  13. class SmartRef
  14. {
  15. private:
  16. T *m_pInterface;
  17. public:
  18. NOTHROW SmartRef()
  19. {
  20. m_pInterface = NULL;
  21. }
  22. // Compiler bug, must be inline!
  23. NOTHROW SmartRef(T *pI) {m_pInterface = pI;};
  24. NOTHROW SmartRef(const SmartRef<T> &);
  25. NOTHROW T * operator->(void)
  26. {
  27. LTASSERT(m_pInterface != NULL);
  28. return m_pInterface;
  29. }
  30. NOTHROW const T * operator->(void) const
  31. {
  32. LTASSERT(m_pInterface != NULL);
  33. return m_pInterface;
  34. }
  35. NOTHROW T & operator*(void)
  36. {
  37. LTASSERT(m_pInterface != NULL);
  38. return *m_pInterface;
  39. }
  40. NOTHROW T * Extract(void)
  41. {
  42. return ExtractImpl();
  43. };
  44. NOTHROW T * GetInterface(BOOL fAddRef = FALSE)
  45. {
  46. return GetInterfaceImpl(fAddRef);
  47. };
  48. NOTHROW const T * GetInterface(void) const
  49. {
  50. return m_pInterface;
  51. }
  52. NOTHROW BOOL IsNull(void) const
  53. {
  54. return m_pInterface == NULL;
  55. }
  56. NOTHROW ~SmartRef()
  57. {
  58. if (m_pInterface != NULL)
  59. {
  60. m_pInterface->Release();
  61. }
  62. }
  63. void operator=(T* pOther)
  64. {
  65. opEqImpl(pOther);
  66. }
  67. void operator=(const SmartRef<T> &other);
  68. T ** operator&(void);
  69. operator T* &(void) {return opTpRef();};
  70. private:
  71. void operator delete(void *);
  72. NOTHROW T * ExtractImpl(void);
  73. NOTHROW T * GetInterfaceImpl(BOOL fAddRef);
  74. NOTHROW T * & opTpRef(void);
  75. void opEqImpl(T* pOther);
  76. };
  77. #include "SmartRef.inl"
  78. #endif