RCPointer.h 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. #pragma once
  2. #include "Betriebssystem.h"
  3. namespace Framework
  4. {
  5. template<typename T> class RCPointer
  6. {
  7. private:
  8. T* pointer;
  9. public:
  10. static RCPointer<T> of(T* pointer)
  11. {
  12. return RCPointer<T>() = pointer;
  13. }
  14. RCPointer()
  15. {
  16. pointer = 0;
  17. }
  18. RCPointer(const RCPointer<T>& ptr)
  19. {
  20. this->pointer
  21. = ptr.pointer ? dynamic_cast<T*>(ptr.pointer->getThis()) : 0;
  22. }
  23. ~RCPointer()
  24. {
  25. if (pointer) pointer->release();
  26. }
  27. RCPointer<T>& operator=(RCPointer<T>& ptr)
  28. {
  29. if (this->pointer) this->pointer->release();
  30. this->pointer
  31. = ptr.pointer ? dynamic_cast<T*>(ptr.pointer->getThis()) : 0;
  32. return *this;
  33. }
  34. RCPointer<T>& operator=(T* ptr)
  35. {
  36. if (this->pointer) this->pointer->release();
  37. this->pointer = ptr;
  38. return *this;
  39. }
  40. T* operator->()
  41. {
  42. return pointer;
  43. }
  44. operator T*()
  45. {
  46. return pointer;
  47. }
  48. };
  49. } // namespace Framework