Version: 3.2.8
Loading...
Searching...
No Matches

#include <wx/scopedptr.h>

Detailed Description

template<typename T>
class wxScopedPtr< T >

A scoped pointer template class.

It is the template version of the old-style scoped pointer macros.

Notice that objects of this class intentionally cannot be copied.

Library:  wxBase
Category:  Smart Pointers
See also
wxSharedPtr<T>, wxWeakRef<T>

Public Member Functions

 wxScopedPtr (T *ptr=NULL)
 Constructor takes ownership of the pointer.
 
 ~wxScopedPtr ()
 Destructor deletes the pointer.
 
T * get () const
 Returns pointer to 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).
 
T & operator* () const
 Returns a reference to the object.
 
T * operator-> () const
 Smart pointer member access.
 
T * release ()
 Releases the current pointer and returns it.
 
void reset (T *ptr=NULL)
 Reset pointer to the value of ptr.
 
void swap (wxScopedPtr< T > &ot)
 Swaps pointers.
 
 wxScopedPtr (type *T=NULL)
 Creates the smart pointer with the given pointer or none if NULL.
 
 ~wxScopedPtr ()
 Destructor frees the pointer help by this object if it is not NULL.
 
T * get () const
 This operator gets the pointer stored in the smart pointer or returns NULL if there is none.
 
T & operator* () const
 This operator works like the standard C++ pointer operator to return the object being pointed to by the pointer.
 
T * operator-> () const
 Smart pointer member access.
 
T * release ()
 Returns the currently hold pointer and resets the smart pointer object to NULL.
 
 reset (T *p=NULL)
 Deletes the currently held pointer and sets it to p or to NULL if no arguments are specified.
 
 swap (wxScopedPtr &other)
 Swap the pointer inside the smart pointer with other.
 

Constructor & Destructor Documentation

◆ wxScopedPtr() [1/2]

template<typename T>
wxScopedPtr< T >::wxScopedPtr ( T * ptr = NULL)

Constructor takes ownership of the pointer.

Parameters
ptrPointer allocated with new or NULL.

◆ ~wxScopedPtr() [1/2]

template<typename T>
wxScopedPtr< T >::~wxScopedPtr ( )

Destructor deletes the pointer.

◆ wxScopedPtr() [2/2]

wxScopedPtr::wxScopedPtr ( type * T = NULL)
explicit

Creates the smart pointer with the given pointer or none if NULL.

On compilers that support it, this uses the explicit keyword.

◆ ~wxScopedPtr() [2/2]

wxScopedPtr::~wxScopedPtr ( )

Destructor frees the pointer help by this object if it is not NULL.

Member Function Documentation

◆ get() [1/2]

T * wxScopedPtr::get ( ) const

This operator gets the pointer stored in the smart pointer or returns NULL if there is none.

◆ get() [2/2]

template<typename T>
T * wxScopedPtr< T >::get ( ) const

Returns pointer to object or NULL.

◆ operator unspecified_bool_type()

template<typename T>
wxScopedPtr< T >::operator unspecified_bool_type ( ) const

Conversion to a boolean expression (in a variant which is not convertible to anything but a boolean expression).

If this class contains a valid pointer it will return true, if it contains a NULL pointer it will return false.

◆ operator*() [1/2]

T & wxScopedPtr::operator* ( ) const

This operator works like the standard C++ pointer operator to return the object being pointed to by the pointer.

If the internal pointer is NULL this method will cause an assert in debug mode.

◆ operator*() [2/2]

template<typename T>
T & wxScopedPtr< T >::operator* ( ) const

Returns a reference to the object.

If the internal pointer is NULL this method will cause an assert in debug mode.

◆ operator->() [1/2]

T * wxScopedPtr::operator-> ( ) const

Smart pointer member access.

Returns pointer to its object.

If the internal pointer is NULL this method will cause an assert in debug mode.

◆ operator->() [2/2]

template<typename T>
T * wxScopedPtr< T >::operator-> ( ) const

Smart pointer member access.

Returns pointer to object.

If the internal pointer is NULL this method will cause an assert in debug mode.

◆ release() [1/2]

T * wxScopedPtr::release ( )

Returns the currently hold pointer and resets the smart pointer object to NULL.

Remarks
After a call to this function the caller is responsible for deleting the pointer.

◆ release() [2/2]

template<typename T>
T * wxScopedPtr< T >::release ( )

Releases the current pointer and returns it.

Remarks
Afterwards the caller is responsible for deleting the data contained in the scoped pointer before.

◆ reset() [1/2]

wxScopedPtr::reset ( T * p = NULL)

Deletes the currently held pointer and sets it to p or to NULL if no arguments are specified.

Note
This function does check to make sure that the pointer you are assigning is not the same pointer that is already stored.

◆ reset() [2/2]

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

Reset pointer to the value of ptr.

The previous pointer will be deleted.

◆ swap() [1/2]

wxScopedPtr::swap ( wxScopedPtr< T > & other)

Swap the pointer inside the smart pointer with other.

The pointer being swapped must be of the same type (hence the same class name).

◆ swap() [2/2]

template<typename T>
void wxScopedPtr< T >::swap ( wxScopedPtr< T > & ot)

Swaps pointers.