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.

49 lines
1.1 KiB

  1. #ifndef __reference_HXX
  2. #define __reference_HXX
  3. #pragma once
  4. /*
  5. * @(#)_reference.hxx 1.0 2/27/98
  6. *
  7. * Copyright (C) 1998,1999 Microsoft Corporation. All rights reserved. *
  8. */
  9. void _assign(IUnknown ** ppref, IUnknown * pref);
  10. void _release(IUnknown ** ppref);
  11. template <class T>
  12. void assign(T ** ppref, T * pref){ _assign((IUnknown **) ppref, pref);}
  13. //----------------------------------------------------------------------------
  14. template <class T> class _reference
  15. {
  16. private:
  17. T * _p;
  18. public:
  19. _reference() : _p(NULL) {}
  20. _reference(T * p) : _p(p) { if (_p) _p->AddRef(); }
  21. _reference(const _reference<T> & r) { _p = r._p; if (_p) _p->AddRef(); }
  22. ~_reference() { _release((IUnknown **)&_p); }
  23. operator T * () { return _p; }
  24. operator T * () const { return _p; }
  25. T & operator * () { return *_p; }
  26. T * operator -> () { return _p; }
  27. T * operator -> () const { return _p; }
  28. T** operator & () { return &_p; }
  29. _reference & operator = (T * p) { assign(&_p, p); return *this; }
  30. _reference & operator = (const _reference<T> & r) { return operator=(r._p); }
  31. };
  32. #endif __reference_HXX