ders::sh_ptr< T > Class Template Reference

Shared smart pointer that uses destroy() function to destruct passed objects. More...

#include <sh_ptr.hpp>

List of all members.

Public Member Functions

 sh_ptr (mem_pool &mp, T *ptr)
 sh_ptr (const sh_ptr &shp)
 ~sh_ptr ()
sh_ptroperator= (const sh_ptr &shp)
mem_poolpool () const
void swap (sh_ptr &shp)
T & operator* ()
const T & operator* () const
T * operator-> ()
const T * operator-> () const
T * get ()
const T * get () const
void set (T *ptr)
int refs () const


Detailed Description

template<class T>
class ders::sh_ptr< T >

Shared smart pointer that uses destroy() function to destruct passed objects.

Definition at line 41 of file sh_ptr.hpp.


Constructor & Destructor Documentation

template<class T>
ders::sh_ptr< T >::sh_ptr ( mem_pool mp,
T *  ptr 
) [inline]

Definition at line 82 of file sh_ptr.hpp.

00083 {
00084  try { cr=new(mp.allocate(sizeof(core))) core(mp, ptr); }
00085  catch (...) {
00086        destroy(ptr, mp);
00087        throw;
00088  }
00089 }

template<class T>
ders::sh_ptr< T >::sh_ptr ( const sh_ptr< T > &  shp  )  [inline]

Definition at line 48 of file sh_ptr.hpp.

00049       {
00050        cr=shp.cr;
00051        cr->refs++;
00052       }

template<class T>
ders::sh_ptr< T >::~sh_ptr (  )  [inline]

Definition at line 92 of file sh_ptr.hpp.

00093 {
00094  if (--cr->refs==0) destroy(cr, cr->mp);
00095 }


Member Function Documentation

template<class T>
sh_ptr< T > & ders::sh_ptr< T >::operator= ( const sh_ptr< T > &  shp  )  [inline]

Definition at line 98 of file sh_ptr.hpp.

00099 {
00100  shp.cr->refs++;
00101  if (--cr->refs==0) destroy(cr, cr->mp);
00102  cr=shp.cr;
00103 
00104  return *this;
00105 }

template<class T>
mem_pool& ders::sh_ptr< T >::pool (  )  const [inline]

Definition at line 58 of file sh_ptr.hpp.

00058 { return cr->mp; }

template<class T>
void ders::sh_ptr< T >::swap ( sh_ptr< T > &  shp  )  [inline]

Definition at line 60 of file sh_ptr.hpp.

00061       {
00062        core* tmp=cr;
00063        cr=shp.cr;
00064        shp.cr=tmp;
00065       }

template<class T>
T& ders::sh_ptr< T >::operator* (  )  [inline]

Definition at line 67 of file sh_ptr.hpp.

00067 { return *cr->ptr; }

template<class T>
const T& ders::sh_ptr< T >::operator* (  )  const [inline]

Definition at line 68 of file sh_ptr.hpp.

00068 { return *cr->ptr; }

template<class T>
T* ders::sh_ptr< T >::operator-> (  )  [inline]

Definition at line 70 of file sh_ptr.hpp.

00070 { return cr->ptr; }

template<class T>
const T* ders::sh_ptr< T >::operator-> (  )  const [inline]

Definition at line 71 of file sh_ptr.hpp.

00071 { return cr->ptr; }

template<class T>
T* ders::sh_ptr< T >::get (  )  [inline]

Definition at line 73 of file sh_ptr.hpp.

00073 { return cr->ptr; }

template<class T>
const T* ders::sh_ptr< T >::get (  )  const [inline]

Definition at line 74 of file sh_ptr.hpp.

00074 { return cr->ptr; }

template<class T>
void ders::sh_ptr< T >::set ( T *  ptr  )  [inline]

Definition at line 76 of file sh_ptr.hpp.

00076 { cr->ptr=ptr; }

template<class T>
int ders::sh_ptr< T >::refs (  )  const [inline]

Definition at line 78 of file sh_ptr.hpp.

00078 { return cr->refs; }


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

Generated on Tue Dec 8 11:35:33 2009 for derslib by  doxygen 1.5.5