ExclusiveHolder.tli 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. // ExclusiveHolder.tli
  2. //
  3. #pragma once
  4. #include "ExclusiveHolder.tlh"
  5. template <typename T>
  6. ExclusiveHolder <T>::ExclusiveHolder ()
  7. {
  8. m_pObject = NULL;
  9. }
  10. template <typename T>
  11. ExclusiveHolder <T>::~ExclusiveHolder ()
  12. {
  13. LockHolder Lock (this);
  14. delete m_pObject;
  15. }
  16. template <typename T>
  17. ExclusiveHolder <T>::ExclusiveHolder (T * object)
  18. {
  19. m_pObject = object;
  20. }
  21. template <typename T>
  22. void ExclusiveHolder <T>::Attach (T * object)
  23. {
  24. LockHolder Lock (this);
  25. delete m_pObject;
  26. m_pObject = object;
  27. }
  28. template <typename T>
  29. T * ExclusiveHolder <T>::Detach ()
  30. {
  31. LockHolder Lock (this);
  32. T * old = m_pObject;
  33. m_pObject = NULL;
  34. Release ();
  35. return old;
  36. }
  37. template <typename T>
  38. void ExclusiveHolder <T>::Release ()
  39. {
  40. LockHolder Lock (this);
  41. delete m_pObject;
  42. m_pObject = NULL;
  43. }
  44. template <typename T>
  45. ExclusiveHolder <T> & ExclusiveHolder <T>::operator = (T * object)
  46. {
  47. Attach (object);
  48. return *this;
  49. }
  50. template <typename T>
  51. bool ExclusiveHolder <T>::IsEmpty () const
  52. {
  53. LockHolder Lock (this);
  54. return (m_pObject == NULL);
  55. }