RCPointer.h 1.2 KB

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