RCPointer.h 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. #include "Betriebssystem.h"
  2. namespace Framework
  3. {
  4. template<typename T>
  5. 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( RCPointer &ptr )
  19. {
  20. this->pointer = ptr.pointer ? dynamic_cast<T *>( ptr.pointer->getThis() ) : 0;
  21. }
  22. ~RCPointer()
  23. {
  24. if( pointer )
  25. pointer->release();
  26. }
  27. RCPointer<T> &operator=( RCPointer<T> &ptr )
  28. {
  29. if( this->pointer )
  30. this->pointer->release();
  31. this->pointer = ptr.pointer ? dynamic_cast<T *>( ptr.pointer->getThis() ) : 0;
  32. return *this;
  33. }
  34. RCPointer<T> &operator=( T *ptr )
  35. {
  36. if( this->pointer )
  37. this->pointer->release();
  38. this->pointer = ptr;
  39. return *this;
  40. }
  41. T *operator->()
  42. {
  43. return pointer;
  44. }
  45. operator T *( )
  46. {
  47. return pointer;
  48. }
  49. };
  50. }