vbl_scoped_ptr mimics a built-in pointer except that it guarantees deletion of the object pointed to, either on destruction of the vbl_scoped_ptr or via an explicit reset(). More...
#include <vbl_scoped_ptr.h>
Public Types | |
typedef T | element_type |
Public Member Functions | |
vbl_scoped_ptr (T *p=0) | |
~vbl_scoped_ptr () | |
T must be complete when this destructor is instantiated. | |
void | reset (T *p=0) |
Make this own p , releasing any existing pointer. | |
T & | operator* () const |
T * | operator-> () const |
T * | get_pointer () const |
operator safe_bool () const | |
Safe implicit conversion to bool. | |
bool | operator! () const |
void | swap (vbl_scoped_ptr &b) |
Private Types | |
typedef vbl_scoped_ptr< T > | this_type |
Private Member Functions | |
vbl_scoped_ptr (vbl_scoped_ptr const &) | |
vbl_scoped_ptr & | operator= (vbl_scoped_ptr const &) |
Private Attributes | |
T * | ptr_ |
VCL_SAFE_BOOL_DEFINE |
vbl_scoped_ptr mimics a built-in pointer except that it guarantees deletion of the object pointed to, either on destruction of the vbl_scoped_ptr or via an explicit reset().
vbl_scoped_ptr is a simple solution for simple needs; use vbl_shared_ptr or std::auto_ptr if your needs are more complex.
To use this to manage pointer member variables using forward declaration, explicitly define a destructor in your .cxx so that the vbl_scoped_ptr destructor is called there rather than being inlined. For example, Y.h:
struct X; struct Y { vbl_scoped_ptr<X> member; ~Y() { } // NO: causes ~vbl_scoped_ptr<X> to be instantiated, which means X must be complete. ~Y(); // YES: destructor not yet generated };
Y.cxx:
#include "X.h" Y::~Y() { } // causes ~vbl_scoped_ptr<X> to be instantiated and inlined, but X is complete here, so all is well.
Definition at line 51 of file vbl_scoped_ptr.h.
typedef T vbl_scoped_ptr< T >::element_type |
Definition at line 65 of file vbl_scoped_ptr.h.
typedef vbl_scoped_ptr<T> vbl_scoped_ptr< T >::this_type [private] |
Definition at line 60 of file vbl_scoped_ptr.h.
vbl_scoped_ptr< T >::vbl_scoped_ptr | ( | vbl_scoped_ptr< T > const & | ) | [private] |
vbl_scoped_ptr< T >::vbl_scoped_ptr | ( | T * | p = 0 | ) | [inline, explicit] |
Definition at line 68 of file vbl_scoped_ptr.h.
vbl_scoped_ptr< T >::~vbl_scoped_ptr | ( | ) | [inline] |
T must be complete when this destructor is instantiated.
Definition at line 75 of file vbl_scoped_ptr.h.
T* vbl_scoped_ptr< T >::get_pointer | ( | ) | const [inline] |
Definition at line 99 of file vbl_scoped_ptr.h.
vbl_scoped_ptr< T >::operator safe_bool | ( | ) | const [inline] |
Safe implicit conversion to bool.
This allows for if (sp) type of usage.
Definition at line 109 of file vbl_scoped_ptr.h.
bool vbl_scoped_ptr< T >::operator! | ( | ) | const [inline] |
Definition at line 115 of file vbl_scoped_ptr.h.
T& vbl_scoped_ptr< T >::operator* | ( | ) | const [inline] |
Definition at line 87 of file vbl_scoped_ptr.h.
T* vbl_scoped_ptr< T >::operator-> | ( | ) | const [inline] |
Definition at line 93 of file vbl_scoped_ptr.h.
vbl_scoped_ptr& vbl_scoped_ptr< T >::operator= | ( | vbl_scoped_ptr< T > const & | ) | [private] |
void vbl_scoped_ptr< T >::reset | ( | T * | p = 0 | ) | [inline] |
Make this own p
, releasing any existing pointer.
Definition at line 81 of file vbl_scoped_ptr.h.
void vbl_scoped_ptr< T >::swap | ( | vbl_scoped_ptr< T > & | b | ) | [inline] |
Definition at line 121 of file vbl_scoped_ptr.h.
T* vbl_scoped_ptr< T >::ptr_ [private] |
Definition at line 54 of file vbl_scoped_ptr.h.
vbl_scoped_ptr< T >::VCL_SAFE_BOOL_DEFINE [private] |
Definition at line 62 of file vbl_scoped_ptr.h.