windowptr.h 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. ///////////////////////////////////////////////////////////////////////////////
  2. // Name: interface/wx/windowptr.h
  3. // Purpose: wxWindowPtr<T> class documentation.
  4. // Author: Vaclav Slavik
  5. // Created: 2013-09-02
  6. // Copyright: (c) 2013 Vaclav Slavik <vslavik@fastmail.fm>
  7. // Licence: wxWindows licence
  8. ///////////////////////////////////////////////////////////////////////////////
  9. /**
  10. A reference-counted smart pointer for holding wxWindow instances.
  11. This specialization of wxSharedPtr<T> is useful for holding
  12. wxWindow-derived objects. Unlike wxSharedPtr<T> or @c std::shared_ptr<>, it
  13. doesn't use the delete operator to destroy the value when reference count
  14. drops to zero, but calls wxWindow::Destroy() to safely destroy the window.
  15. The template parameter T must be wxWindow or a class derived from it.
  16. @library{wxcore}
  17. @category{smartpointers}
  18. @since 3.0
  19. @see wxSharedPtr<T>
  20. */
  21. template<typename T>
  22. class wxWindowPtr<T> : public wxSharedPtr<T>
  23. {
  24. public:
  25. /// Default constructor.
  26. wxWindowPtr();
  27. /**
  28. Constructor.
  29. Creates shared pointer from the raw pointer @a ptr and takes ownership
  30. of it.
  31. */
  32. explicit wxWindowPtr(T* ptr);
  33. /**
  34. Constructor.
  35. Creates shared pointer from the raw pointer @a ptr and deleter @a d
  36. and takes ownership of it.
  37. @param ptr The raw pointer.
  38. @param d Deleter - a functor that is called instead of delete to
  39. free the @a ptr raw pointer when its reference count drops to
  40. zero.
  41. */
  42. template<typename Deleter>
  43. explicit wxWindowPtr(T* ptr, Deleter d);
  44. /// Copy constructor.
  45. wxWindowPtr(const wxWindowPtr<T>& tocopy);
  46. /**
  47. Assignment operator.
  48. Releases any previously held pointer and creates a reference to @a ptr.
  49. */
  50. wxWindowPtr<T>& operator=(T* ptr);
  51. /**
  52. Assignment operator.
  53. Releases any previously held pointer and creates a reference to the
  54. same object as @a topcopy.
  55. */
  56. wxWindowPtr<T>& operator=(const wxWindowPtr<T>& tocopy);
  57. /**
  58. Reset pointer to @a ptr.
  59. If the reference count of the previously owned pointer was 1 it will be deleted.
  60. */
  61. void reset(T* ptr = NULL);
  62. };