Auto-destructing pointer class. More...
#include <smart_ptr.h>
Public Member Functions | |
smart_ptr (T *pT=NULL) throw () | |
template<class X > | |
smart_ptr (IN const smart_ptr< X > &from) throw () | |
smart_ptr (IN const smart_ptr< T > &from) throw () | |
~smart_ptr (void) throw () | |
T * | operator-> (void) throw () |
const T * | operator-> (void) const throw () |
operator T * (void) throw () | |
operator const T * (void) const throw () | |
bool | operator! (void) const throw () |
const smart_ptr< T > & | operator= (IN T *pT) throw () |
template<class X > | |
const smart_ptr< T > & | operator= (IN const smart_ptr< X > &from) throw () |
const smart_ptr< T > & | operator= (IN const smart_ptr< T > &from) throw () |
long | get_ref_count (void) const throw () |
T * | disown (void) throw () |
Auto-destructing pointer class.
This is a ref-counting class. It keeps the ref struct as a separate struct on the heap, and all smart pointers share it.
WARNING: you will really hose yourself if you have two or more smart_ptr's wrapping the same underlying pointer if they use different ref structs. The way to avoid this is to use smart_ptr<T>'s everywhere (never convert to a raw T* and then pass to another smart_ptr<T>, for instance).
This class is PARTLY threadsafe! That is, there is a mutex protecting the ref count. This is a slight overhead for single-threaded applications, but is probably worth it overall. General smart_ptr<T> accesses such as
p->doSomething()
don't pay any synchronization overhead. Only operations that impact the ref count (assignment, destruction, etc.) will synchronize.
Put another way, accessing the pointer is NOT synchronized (and therefore not generally threadsafe). If your class needs that, you'll need to make the class itself threadsafe.
Definition at line 69 of file smart_ptr.h.
Definition at line 45 of file smart_ptr.h.
smart_ptr< T >::smart_ptr | ( | IN const smart_ptr< X > & | from | ) | throw () [inline] |
Definition at line 50 of file smart_ptr.h.
Definition at line 55 of file smart_ptr.h.
Definition at line 61 of file smart_ptr.h.
T* smart_ptr< T >::operator-> | ( | void | ) | throw () [inline] |
Definition at line 64 of file smart_ptr.h.
const T* smart_ptr< T >::operator-> | ( | void | ) | const throw () [inline] |
Definition at line 69 of file smart_ptr.h.
smart_ptr< T >::operator T * | ( | void | ) | throw () [inline] |
Definition at line 74 of file smart_ptr.h.
smart_ptr< T >::operator const T * | ( | void | ) | const throw () [inline] |
Definition at line 78 of file smart_ptr.h.
bool smart_ptr< T >::operator! | ( | void | ) | const throw () [inline] |
Definition at line 82 of file smart_ptr.h.
Definition at line 86 of file smart_ptr.h.
const smart_ptr<T>& smart_ptr< T >::operator= | ( | IN const smart_ptr< X > & | from | ) | throw () [inline] |
Definition at line 92 of file smart_ptr.h.
const smart_ptr<T>& smart_ptr< T >::operator= | ( | IN const smart_ptr< T > & | from | ) | throw () [inline] |
Definition at line 97 of file smart_ptr.h.
long smart_ptr< T >::get_ref_count | ( | void | ) | const throw () [inline] |
Definition at line 102 of file smart_ptr.h.
T* smart_ptr< T >::disown | ( | void | ) | throw () [inline] |
Definition at line 106 of file smart_ptr.h.