ETL  0.04.19
Public Types | Public Member Functions | Static Public Member Functions | Private Attributes | List of all members
smart_ptr< T, D > Class Template Reference

Object Smart Pointer. More...

#include <ETL/smart_ptr>

Public Types

typedef T value_type
typedef T & reference
typedef const T & const_reference
typedef T * pointer
typedef const T * const_pointer
typedef int count_type
typedef int size_type
typedef D destructor_type

Public Member Functions

 smart_ptr (value_type *obj, reference_counter refcount)
 smart_ptr ()
 Default constructor - empty smart_ptr.
 smart_ptr (value_type *x)
 Constructor that constructs from a pointer to new object.
 smart_ptr (const smart_ptr< value_type > &x)
 Template copy constructor.
 smart_ptr (const value_type &x)
 ~smart_ptr ()
 smart_ptr is released on deletion
template<class U >
const smart_ptr< value_type > & operator= (const smart_ptr< U > &x)
 Template Assignment operator.
const smart_ptr< value_type > & operator= (const smart_ptr< value_type > &x)
 Assignment operator.
void reset ()
 smart_ptr reset procedure
void spawn ()
const count_typecount () const
 Returns number of instances.
bool unique () const
 Returns true if there is only one instance of the object.
smart_ptr< const value_typeconstant ()
 Returns a constant handle to our object.
reference operator* () const
pointer operator-> () const
 operator smart_ptr< const value_type > () const
pointer get () const
 operator bool () const
 More explicit bool cast.
bool operator! () const
template<class U >
 operator smart_ptr< U > ()
 Overloaded cast operator – useful for implicit casts.

Static Public Member Functions

template<class U >
static smart_ptr< T > cast_static (const smart_ptr< U > &x)
 static_cast<> wrapper
template<class U >
static smart_ptr< T > cast_dynamic (const smart_ptr< U > &x)
 dynamic_cast<> wrapper
template<class U >
static smart_ptr< T > cast_const (const smart_ptr< U > &x)
 const_cast<> wrapper

Private Attributes

value_typeobj
reference_counter refcount

Detailed Description

template<class T, class D = generic_deleter<T>>
class smart_ptr< T, D >

Object Smart Pointer.

See Also
loose_smart_ptr
Todo:
This needs to be documented

Definition at line 62 of file _smart_ptr.h.

Member Typedef Documentation

template<class T, class D = generic_deleter<T>>
typedef T smart_ptr< T, D >::value_type

Definition at line 66 of file _smart_ptr.h.

template<class T, class D = generic_deleter<T>>
typedef T& smart_ptr< T, D >::reference

Definition at line 67 of file _smart_ptr.h.

template<class T, class D = generic_deleter<T>>
typedef const T& smart_ptr< T, D >::const_reference

Definition at line 68 of file _smart_ptr.h.

template<class T, class D = generic_deleter<T>>
typedef T* smart_ptr< T, D >::pointer

Definition at line 69 of file _smart_ptr.h.

template<class T, class D = generic_deleter<T>>
typedef const T* smart_ptr< T, D >::const_pointer

Definition at line 70 of file _smart_ptr.h.

template<class T, class D = generic_deleter<T>>
typedef int smart_ptr< T, D >::count_type

Definition at line 71 of file _smart_ptr.h.

template<class T, class D = generic_deleter<T>>
typedef int smart_ptr< T, D >::size_type

Definition at line 72 of file _smart_ptr.h.

template<class T, class D = generic_deleter<T>>
typedef D smart_ptr< T, D >::destructor_type

Definition at line 73 of file _smart_ptr.h.

Constructor & Destructor Documentation

template<class T, class D = generic_deleter<T>>
smart_ptr< T, D >::smart_ptr ( value_type obj,
reference_counter  refcount 
)
inline

Definition at line 83 of file _smart_ptr.h.

template<class T, class D = generic_deleter<T>>
smart_ptr< T, D >::smart_ptr ( )
inline

Default constructor - empty smart_ptr.

Definition at line 86 of file _smart_ptr.h.

Referenced by smart_ptr< T, D >::spawn().

template<class T, class D = generic_deleter<T>>
smart_ptr< T, D >::smart_ptr ( value_type x)
inlineexplicit

Constructor that constructs from a pointer to new object.

A new smart_ptr is created with a pointer to a newly allocated object. We need to be explicit with this so we don't accidently have two smart_ptrs for one object – that would be bad.

Definition at line 94 of file _smart_ptr.h.

template<class T, class D = generic_deleter<T>>
smart_ptr< T, D >::smart_ptr ( const smart_ptr< value_type > &  x)
inline

Template copy constructor.

This template constructor allows us to cast smart_ptrs much like we would pointers. Default copy constructor

The template above is not good enough for all compilers. We need to explicitly define the copy constructor for this class to work on those compilers.

Definition at line 110 of file _smart_ptr.h.

template<class T, class D = generic_deleter<T>>
smart_ptr< T, D >::smart_ptr ( const value_type x)
inlineexplicit

Definition at line 112 of file _smart_ptr.h.

template<class T, class D = generic_deleter<T>>
smart_ptr< T, D >::~smart_ptr ( )
inline

smart_ptr is released on deletion

Definition at line 115 of file _smart_ptr.h.

References smart_ptr< T, D >::obj, smart_ptr< T, D >::refcount, and reference_counter::unique().

Member Function Documentation

template<class T, class D = generic_deleter<T>>
template<class U >
const smart_ptr<value_type>& smart_ptr< T, D >::operator= ( const smart_ptr< U > &  x)
inline

Template Assignment operator.

Definition at line 119 of file _smart_ptr.h.

References smart_ptr< T, D >::get(), smart_ptr< T, D >::obj, smart_ptr< T, D >::refcount, and smart_ptr< T, D >::reset().

Referenced by smart_ptr< T, D >::spawn().

template<class T, class D = generic_deleter<T>>
const smart_ptr<value_type>& smart_ptr< T, D >::operator= ( const smart_ptr< value_type > &  x)
inline
template<class T, class D = generic_deleter<T>>
void smart_ptr< T, D >::reset ( )
inline
template<class T, class D = generic_deleter<T>>
void smart_ptr< T, D >::spawn ( )
inline

Definition at line 166 of file _smart_ptr.h.

References smart_ptr< T, D >::operator=(), and smart_ptr< T, D >::smart_ptr().

template<class T, class D = generic_deleter<T>>
const count_type& smart_ptr< T, D >::count ( ) const
inline

Returns number of instances.

Definition at line 169 of file _smart_ptr.h.

References smart_ptr< T, D >::refcount.

template<class T, class D = generic_deleter<T>>
bool smart_ptr< T, D >::unique ( ) const
inline

Returns true if there is only one instance of the object.

Definition at line 172 of file _smart_ptr.h.

References smart_ptr< T, D >::refcount, and reference_counter::unique().

template<class T, class D = generic_deleter<T>>
smart_ptr<const value_type> smart_ptr< T, D >::constant ( )
inline

Returns a constant handle to our object.

Definition at line 175 of file _smart_ptr.h.

template<class T, class D = generic_deleter<T>>
reference smart_ptr< T, D >::operator* ( ) const
inline

Definition at line 177 of file _smart_ptr.h.

References smart_ptr< T, D >::obj.

template<class T, class D = generic_deleter<T>>
pointer smart_ptr< T, D >::operator-> ( ) const
inline

Definition at line 179 of file _smart_ptr.h.

References smart_ptr< T, D >::obj.

template<class T, class D = generic_deleter<T>>
smart_ptr< T, D >::operator smart_ptr< const value_type > ( ) const
inline

Definition at line 182 of file _smart_ptr.h.

References smart_ptr< T, D >::obj.

template<class T, class D = generic_deleter<T>>
template<class U >
static smart_ptr<T> smart_ptr< T, D >::cast_static ( const smart_ptr< U > &  x)
inlinestatic

static_cast<> wrapper

Definition at line 187 of file _smart_ptr.h.

References smart_ptr< T, D >::get(), NULL, and smart_ptr< T, D >::refcount.

template<class T, class D = generic_deleter<T>>
template<class U >
static smart_ptr<T> smart_ptr< T, D >::cast_dynamic ( const smart_ptr< U > &  x)
inlinestatic

dynamic_cast<> wrapper

Definition at line 192 of file _smart_ptr.h.

References smart_ptr< T, D >::get(), and smart_ptr< T, D >::refcount.

template<class T, class D = generic_deleter<T>>
template<class U >
static smart_ptr<T> smart_ptr< T, D >::cast_const ( const smart_ptr< U > &  x)
inlinestatic

const_cast<> wrapper

Definition at line 197 of file _smart_ptr.h.

References smart_ptr< T, D >::get(), and smart_ptr< T, D >::refcount.

template<class T, class D = generic_deleter<T>>
pointer smart_ptr< T, D >::get ( ) const
inline
template<class T, class D = generic_deleter<T>>
smart_ptr< T, D >::operator bool ( ) const
inline

More explicit bool cast.

Definition at line 203 of file _smart_ptr.h.

References smart_ptr< T, D >::obj.

template<class T, class D = generic_deleter<T>>
bool smart_ptr< T, D >::operator! ( ) const
inline

Definition at line 205 of file _smart_ptr.h.

References smart_ptr< T, D >::obj.

template<class T, class D = generic_deleter<T>>
template<class U >
smart_ptr< T, D >::operator smart_ptr< U > ( )
inline

Overloaded cast operator – useful for implicit casts.

Definition at line 209 of file _smart_ptr.h.

Member Data Documentation

template<class T, class D = generic_deleter<T>>
value_type* smart_ptr< T, D >::obj
private
template<class T, class D = generic_deleter<T>>
reference_counter smart_ptr< T, D >::refcount
private

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