ReferenceCounting.h 447 B

12345678910111213141516171819202122232425262728293031
  1. #pragma once
  2. namespace Framework
  3. {
  4. template< class T >
  5. class ReferenceCounting : public T
  6. {
  7. private:
  8. int ref;
  9. public:
  10. ReferenceCounting()
  11. : T()
  12. {
  13. ref = 1;
  14. }
  15. T *getThis()
  16. {
  17. ref++;
  18. return this;
  19. }
  20. T *release()
  21. {
  22. if( !--ref )
  23. delete this;
  24. return 0;
  25. }
  26. };
  27. }