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.

85 lines
3.0 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) 1992, Microsoft Corporation.
  5. //
  6. // File: otrack.hxx
  7. //
  8. // Contents: This file defines facilities for a standard implementation
  9. // of reference-counted objects, incorporating mechanisms for
  10. // tracking the usage history of the objects.
  11. //
  12. // Classes: ObjectTracker
  13. //
  14. // History: 6-Apr-92 MikeSe Created
  15. //
  16. //----------------------------------------------------------------------------
  17. #ifndef __OTRACK_HXX__
  18. #define __OTRACK_HXX__
  19. #include <windows.h>
  20. //+-------------------------------------------------------------------------
  21. //
  22. // Class: ObjectTracker (otr)
  23. //
  24. // Purpose: Provides basis for tracking (OLE) objects (aka interface handles)
  25. //
  26. // History: 6-Apr-92 MikeSe Created
  27. //
  28. // Notes: Access to this class is only indirect, through the macros
  29. // defined later.
  30. //
  31. //--------------------------------------------------------------------------
  32. class ObjectTracker
  33. {
  34. protected:
  35. ObjectTracker();
  36. ULONG _cReferences;
  37. };
  38. //+-------------------------------------------------------------------------
  39. //
  40. // The following macros encapsulate use of the above
  41. //
  42. // INHERIT_TRACKING:
  43. //
  44. // For any class which implements a Cairo interface, add this macro
  45. // in the class declaration, eg:
  46. //
  47. // class CMyFoo: INHERIT_TRACKING, IFoo
  48. //
  49. // Do not repeat this in any subclass. If both INHERIT_UNWIND and
  50. // INHERIT_TRACKING are used, the former should appear first.
  51. # define INHERIT_TRACKING protected ObjectTracker
  52. inline ObjectTracker::ObjectTracker():_cReferences(1) {};
  53. # define DECLARE_STD_REFCOUNTING \
  54. STDMETHOD_(ULONG, AddRef) () \
  55. { \
  56. InterlockedIncrement((long*)&_cReferences); \
  57. return _cReferences; \
  58. }; \
  59. STDMETHOD_(ULONG, Release) () \
  60. { \
  61. if ( InterlockedDecrement((long*)&_cReferences) == 0 ) \
  62. { \
  63. delete this; \
  64. return 0; \
  65. } \
  66. else \
  67. return _cReferences; \
  68. };
  69. # define ENLIST_TRACKING(cls)
  70. # define DUMP_TRACKING_INFO()
  71. # define TRACK_CLASS(fTrack, cls)
  72. #endif // of ifndef __OTRACK_HXX__