Version: 3.1.0
wxWindowPtr< T > Class Template Reference

#include <wx/windowptr.h>

+ Inheritance diagram for wxWindowPtr< T >:

Detailed Description

template<typename T>
class wxWindowPtr< T >

A reference-counted smart pointer for holding wxWindow instances.

This specialization of wxSharedPtr<T> is useful for holding wxWindow-derived objects. Unlike wxSharedPtr<T> or std::shared_ptr<>, it doesn't use the delete operator to destroy the value when reference count drops to zero, but calls wxWindow::Destroy() to safely destroy the window.

The template parameter T must be wxWindow or a class derived from it.

Library:  wxCore
Category:  Smart Pointers
Since
3.0
See Also
wxSharedPtr<T>

Public Member Functions

 wxWindowPtr ()
 Default constructor.
 
 wxWindowPtr (T *ptr)
 Constructor.
 
template<typename Deleter >
 wxWindowPtr (T *ptr, Deleter d)
 Constructor.
 
 wxWindowPtr (const wxWindowPtr< T > &tocopy)
 Copy constructor.
 
wxWindowPtr< T > & operator= (T *ptr)
 Assignment operator.
 
wxWindowPtr< T > & operator= (const wxWindowPtr< T > &tocopy)
 Assignment operator.
 
void reset (T *ptr=NULL)
 Reset pointer to ptr.
 
- Public Member Functions inherited from wxSharedPtr< T >
wxEXPLICIT wxSharedPtr (T *ptr=NULL)
 Constructor.
 
template<typename Deleter >
wxEXPLICIT wxSharedPtr (T *ptr, Deleter d)
 Constructor.
 
 wxSharedPtr (const wxSharedPtr< T > &tocopy)
 Copy constructor.
 
 ~wxSharedPtr ()
 Destructor.
 
T * get () const
 Returns pointer to its object or NULL.
 
 operator unspecified_bool_type () const
 Conversion to a boolean expression (in a variant which is not convertible to anything but a boolean expression).
 
operator* () const
 Returns a reference to the object.
 
T * operator-> () const
 Smart pointer member access.
 
wxSharedPtr< T > & operator= (T *ptr)
 Assignment operator.
 
wxSharedPtr< T > & operator= (const wxSharedPtr< T > &tocopy)
 Assignment operator.
 
void reset (T *ptr=NULL)
 Reset pointer to ptr.
 
template<typename Deleter >
void reset (T *ptr, Deleter d)
 Reset pointer to ptr.
 
bool unique () const
 Returns true if this is the only pointer pointing to its object.
 
long use_count () const
 Returns the number of pointers pointing to its object.
 

Constructor & Destructor Documentation

template<typename T >
wxWindowPtr< T >::wxWindowPtr ( )

Default constructor.

template<typename T >
wxWindowPtr< T >::wxWindowPtr ( T *  ptr)
explicit

Constructor.

Creates shared pointer from the raw pointer ptr and takes ownership of it.

template<typename T >
template<typename Deleter >
wxWindowPtr< T >::wxWindowPtr ( T *  ptr,
Deleter  d 
)
explicit

Constructor.

Creates shared pointer from the raw pointer ptr and deleter d and takes ownership of it.

Parameters
ptrThe raw pointer.
dDeleter - a functor that is called instead of delete to free the ptr raw pointer when its reference count drops to zero.
template<typename T >
wxWindowPtr< T >::wxWindowPtr ( const wxWindowPtr< T > &  tocopy)

Copy constructor.

Member Function Documentation

template<typename T >
wxWindowPtr<T>& wxWindowPtr< T >::operator= ( T *  ptr)

Assignment operator.

Releases any previously held pointer and creates a reference to ptr.

template<typename T >
wxWindowPtr<T>& wxWindowPtr< T >::operator= ( const wxWindowPtr< T > &  tocopy)

Assignment operator.

Releases any previously held pointer and creates a reference to the same object as topcopy.

template<typename T >
void wxWindowPtr< T >::reset ( T *  ptr = NULL)

Reset pointer to ptr.

If the reference count of the previously owned pointer was 1 it will be deleted.