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.

54 lines
766 B

  1. /*++
  2. Copyright (c) 1991 Microsoft Corporation
  3. Module Name:
  4. smartp.h
  5. Abstract:
  6. Safe pointer classes
  7. Author:
  8. Anirudh Sahni (anirudhs) 21-Oct-1996
  9. Environment:
  10. User Mode -Win32
  11. Revision History:
  12. 21-Oct-1996 AnirudhS
  13. Created.
  14. --*/
  15. #ifndef SMARTP_H
  16. #define SMARTP_H
  17. //
  18. // Template pointer class that automatically calls LocalFree when it goes
  19. // out of scope
  20. // T is a pointer type, like LPWSTR or LPVOID, that can be initialized to NULL
  21. //
  22. template <class T>
  23. class CHeapPtr
  24. {
  25. public:
  26. CHeapPtr() : _p(NULL) { }
  27. ~CHeapPtr() { LocalFree(_p); }
  28. operator T() { return _p; }
  29. T operator*() { return *_p; }
  30. T * operator& () { return &_p; }
  31. private:
  32. T _p;
  33. };
  34. #endif // def SMARTP_H