GClasses
GClasses::smart_ptr< T > Class Template Reference

A reference-counting smart-pointer. More...

#include <GHolders.h>

Public Member Functions

 smart_ptr ()
 
 smart_ptr (const smart_ptr &other)
 
template<class S >
 smart_ptr (const smart_ptr< S > &other, T *)
 Make a smart pointer of a different type (T) that shares referent and ownership with other. More...
 
template<class S >
 smart_ptr (S *pThat)
 
 ~smart_ptr ()
 
T * get () const
 
T & operator* () const
 
T * operator-> () const
 
smart_ptroperator= (const smart_ptr &that)
 
template<class S >
smart_ptroperator= (S *pThat)
 
size_t refCount ()
 
void reset ()
 

Protected Attributes

smart_ptr_ref_counter< T > * m_pRefCounter
 

Friends

template<class S >
class smart_ptr
 

Detailed Description

template<class T>
class GClasses::smart_ptr< T >

A reference-counting smart-pointer.

Constructor & Destructor Documentation

template<class T>
GClasses::smart_ptr< T >::smart_ptr ( )
inline
template<class T>
GClasses::smart_ptr< T >::smart_ptr ( const smart_ptr< T > &  other)
inline
template<class T>
template<class S >
GClasses::smart_ptr< T >::smart_ptr ( const smart_ptr< S > &  other,
T *   
)
inline

Make a smart pointer of a different type (T) that shares referent and ownership with other.

This is mainly for creating smart_pointer<const T> from smart_pointer<T>.

The basic use is:

smart_ptr<int> original_ptr(new int);
int const* type_tag = NULL;
smart_ptr<const int> new_ptr(original_ptr, type_tag);
Warning
Using this code for anything other than creating a smart_pointer<const T> from smart_pointer<T> is dangerous and may do bad things due to pointer aliasing. You do it at your own risk.
Postcondition
get() == (T*)other.get() and when other goes out of scope, it decreases the reference count for *this and vice-versa
template<class T>
template<class S >
GClasses::smart_ptr< T >::smart_ptr ( S *  pThat)
inline
template<class T>
GClasses::smart_ptr< T >::~smart_ptr ( )
inline

Member Function Documentation

template<class T>
T* GClasses::smart_ptr< T >::get ( ) const
inline
template<class T>
T& GClasses::smart_ptr< T >::operator* ( ) const
inline
template<class T>
T* GClasses::smart_ptr< T >::operator-> ( ) const
inline
template<class T>
smart_ptr& GClasses::smart_ptr< T >::operator= ( const smart_ptr< T > &  that)
inline
template<class T>
template<class S >
smart_ptr& GClasses::smart_ptr< T >::operator= ( S *  pThat)
inline
template<class T>
size_t GClasses::smart_ptr< T >::refCount ( )
inline
template<class T>
void GClasses::smart_ptr< T >::reset ( )
inline

Friends And Related Function Documentation

template<class T>
template<class S >
friend class smart_ptr
friend

Member Data Documentation

template<class T>
smart_ptr_ref_counter<T>* GClasses::smart_ptr< T >::m_pRefCounter
protected