Public Types | Public Member Functions | Private Types | Private Member Functions | Private Attributes | List of all members
vbl_scoped_ptr< T > Class Template Reference

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_fwd.h>

Public Types

typedef T element_type
 

Public Member Functions

 vbl_scoped_ptr (T *p=nullptr)
 
 ~vbl_scoped_ptr ()
 T must be complete when this destructor is instantiated. More...
 
void reset (T *p=nullptr)
 Make this own p, releasing any existing pointer. More...
 
T & operator * () const
 
T * operator-> () const
 
T * get_pointer () const
 
 operator bool () const
 Safe implicit conversion to bool. More...
 
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 &)=delete
 
vbl_scoped_ptroperator= (vbl_scoped_ptr const &)=delete
 

Private Attributes

T * ptr_
 

Detailed Description

template<class T>
class vbl_scoped_ptr< T >

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::unique_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 {
~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 19 of file vbl_fwd.h.

Member Typedef Documentation

◆ element_type

template<class T>
typedef T vbl_scoped_ptr< T >::element_type

Definition at line 67 of file vbl_scoped_ptr.h.

◆ this_type

template<class T>
typedef vbl_scoped_ptr<T> vbl_scoped_ptr< T >::this_type
private

Definition at line 62 of file vbl_scoped_ptr.h.

Constructor & Destructor Documentation

◆ vbl_scoped_ptr() [1/2]

template<class T>
vbl_scoped_ptr< T >::vbl_scoped_ptr ( vbl_scoped_ptr< T > const &  )
privatedelete

◆ vbl_scoped_ptr() [2/2]

template<class T>
vbl_scoped_ptr< T >::vbl_scoped_ptr ( T *  p = nullptr)
inlineexplicit

Definition at line 70 of file vbl_scoped_ptr.h.

◆ ~vbl_scoped_ptr()

template<class T>
vbl_scoped_ptr< T >::~vbl_scoped_ptr ( )
inline

T must be complete when this destructor is instantiated.

Definition at line 77 of file vbl_scoped_ptr.h.

Member Function Documentation

◆ get_pointer()

template<class T>
T* vbl_scoped_ptr< T >::get_pointer ( ) const
inline

Definition at line 101 of file vbl_scoped_ptr.h.

◆ operator *()

template<class T>
T& vbl_scoped_ptr< T >::operator * ( ) const
inline

Definition at line 89 of file vbl_scoped_ptr.h.

◆ operator bool()

template<class T>
vbl_scoped_ptr< T >::operator bool ( ) const
inlineexplicit

Safe implicit conversion to bool.

This allows for if (sp) type of usage.

Definition at line 111 of file vbl_scoped_ptr.h.

◆ operator!()

template<class T>
bool vbl_scoped_ptr< T >::operator! ( ) const
inline

Definition at line 117 of file vbl_scoped_ptr.h.

◆ operator->()

template<class T>
T* vbl_scoped_ptr< T >::operator-> ( ) const
inline

Definition at line 95 of file vbl_scoped_ptr.h.

◆ operator=()

template<class T>
vbl_scoped_ptr& vbl_scoped_ptr< T >::operator= ( vbl_scoped_ptr< T > const &  )
privatedelete

◆ reset()

template<class T>
void vbl_scoped_ptr< T >::reset ( T *  p = nullptr)
inline

Make this own p, releasing any existing pointer.

Definition at line 83 of file vbl_scoped_ptr.h.

◆ swap()

template<class T>
void vbl_scoped_ptr< T >::swap ( vbl_scoped_ptr< T > &  b)
inline

Definition at line 123 of file vbl_scoped_ptr.h.

Member Data Documentation

◆ ptr_

template<class T>
T* vbl_scoped_ptr< T >::ptr_
private

Definition at line 56 of file vbl_scoped_ptr.h.


The documentation for this class was generated from the following files: