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.

46 lines
1.2 KiB

  1. // AutoPtr.h: interface for the CAutoPtr class.
  2. //
  3. //////////////////////////////////////////////////////////////////////
  4. #if !defined(AFX_AUTOPTR_H__82D00BEB_039E_11D1_A436_00C04FB99B01__INCLUDED_)
  5. #define AFX_AUTOPTR_H__82D00BEB_039E_11D1_A436_00C04FB99B01__INCLUDED_
  6. #if _MSC_VER >= 1000
  7. #pragma once
  8. #endif // _MSC_VER >= 1000
  9. template <class T>
  10. class CAutoPtr
  11. {
  12. public:
  13. CAutoPtr() { m_p = NULL; };
  14. CAutoPtr(T* p) { m_p = p; };
  15. CAutoPtr(const CAutoPtr<T>& p) { m_p = p.m_p; };
  16. virtual ~CAutoPtr()
  17. {
  18. if(m_p)
  19. delete m_p;
  20. m_p = NULL;
  21. };
  22. operator T*() { return (T*) m_p; };
  23. T& operator*()
  24. {
  25. _ASSERTE(m_p != NULL);
  26. return *p; ,
  27. };
  28. // the assert on operator& usually indicates
  29. // a bug. If this is really what is needed, however
  30. // take the address of the member m_p explicitly.
  31. T** operator&() { _ASSERTE(m_p == NULL); return &m_p; };
  32. T* operator->() { _ASSERTE(m_p != NULL); return m_p; };
  33. T* operator=(T* p) { return m_p = p; };
  34. T* operator=(const CAutoPtr<T>& p) { return m_p = p.m_p; };
  35. #if _MSC_VER>1020
  36. bool operator!(){return (m_p == NULL);}
  37. #else
  38. BOOL operator!(){return (m_p == NULL) ? TRUE : FALSE;}
  39. #endif
  40. T* m_p;
  41. };
  42. #endif // !defined(AFX_AUTOPTR_H__82D00BEB_039E_11D1_A436_00C04FB99B01__INCLUDED_)