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.

92 lines
1.8 KiB

  1. //+----------------------------------------------------------------------------
  2. //
  3. // Copyright (C) 1996, Microsoft Corporation
  4. //
  5. // File: cref.hxx
  6. //
  7. // Contents: Class to implement simple reference counting suitable for
  8. // object life cycle management.
  9. //
  10. // Classes: CReference
  11. //
  12. // Functions:
  13. //
  14. // History: Sept 17, 1996 Milans created.
  15. //
  16. //-----------------------------------------------------------------------------
  17. #ifndef _DFSM_REFERENCE_
  18. #define _DFSM_REFERENCE_
  19. //+----------------------------------------------------------------------------
  20. //
  21. // Class: CReference
  22. //
  23. // Synopsis: Class to abstract object life cycle management via ref
  24. // counting.
  25. //
  26. //-----------------------------------------------------------------------------
  27. class CReference {
  28. public:
  29. CReference();
  30. virtual ~CReference();
  31. virtual ULONG AddRef();
  32. virtual ULONG Release();
  33. protected:
  34. ULONG _cRef;
  35. };
  36. //---------------------------------------------------------------------------
  37. //
  38. // Inline Methods
  39. //
  40. //---------------------------------------------------------------------------
  41. inline CReference::CReference() {
  42. IDfsVolInlineDebOut((
  43. DEB_TRACE, "CReference::+CReference(0x%x)\n",
  44. this));
  45. _cRef = 1;
  46. }
  47. inline CReference::~CReference() {
  48. IDfsVolInlineDebOut((
  49. DEB_TRACE, "CReference::~CReference(0x%x)\n",
  50. this));
  51. ASSERT(_cRef == 0);
  52. }
  53. inline ULONG CReference::AddRef() {
  54. _cRef++;
  55. return( _cRef);
  56. }
  57. inline ULONG CReference::Release() {
  58. ULONG cReturn;
  59. IDfsVolInlineDebOut((DEB_TRACE, "CReference::Release()\n"));
  60. cReturn = --_cRef;
  61. if (_cRef == 0) {
  62. delete this;
  63. }
  64. IDfsVolInlineDebOut((DEB_TRACE, "CReference::Release() exit\n"));
  65. return( cReturn );
  66. }
  67. #endif _DFSM_REFERENCE_