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.

42 lines
963 B

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1994 - 1995.
  5. //
  6. // File: xbuffer.hxx
  7. //
  8. // Contents: Buffer template that allows delayed allocation of the buffer
  9. // and reference counting. The buffer is not freed until the
  10. // object is deleted -- not when the refcount goes to 0.
  11. //
  12. // Templates: XBuffer
  13. //
  14. // History: 10 Mar 1995 dlee Created
  15. //
  16. //--------------------------------------------------------------------------
  17. #pragma once
  18. template<class T> class XBuffer : public XArray<T>
  19. {
  20. public:
  21. XBuffer() : XArray<T>(), _cRefs(0)
  22. {
  23. }
  24. BOOL InUse() { return _cRefs > 0; }
  25. void AddRef() { _cRefs++; }
  26. void Release() { Win4Assert(0 != _cRefs); _cRefs--; }
  27. void Init( unsigned cElems )
  28. {
  29. XArray<T>::Init( cElems );
  30. AddRef();
  31. }
  32. private:
  33. unsigned _cRefs;
  34. };