Handle< T > Class Template Reference

Template class for smart pointers. More...

#include <ttl/utils/Handle.h>

List of all members.

Public Member Functions

 Handle ()
 Handle (const T &ref)
 Handle (T *p)
 Handle (const Handle< T > &ref)
 ~Handle ()
void rebind (const T *pc)
void rebind (const T &p)
const T * operator-> () const
T * operator-> ()
const T & operator() () const
T & operator() ()
const T & operator* () const
T & operator* ()
const T * getPtr () const
T * getPtr ()
const T & getRef () const
T & getRef ()
void operator= (const Handle< T > &h)
void operator= (const T *p)
void operator= (const T &p)
bool operator== (const Handle< T > &h) const
bool operator!= (const Handle< T > &h) const
bool operator< (const Handle< T > &h) const
bool operator> (const Handle< T > &h) const

Protected Attributes

T * classptr

Detailed Description

template<class T>
class Handle< T >

Template class for smart pointers.

The actual class must inherit from HandleId

Definition at line 43 of file Handle.h.


Constructor & Destructor Documentation

template<class T>
Handle< T >::Handle (  )  [inline]

Definition at line 49 of file Handle.h.

00049 { classptr = 0; }

template<class T>
Handle< T >::Handle ( const T &  ref  )  [inline]

Definition at line 51 of file Handle.h.

00051                        {
00052     classptr = (T*) &ref;
00053     classptr->increment();
00054   }

template<class T>
Handle< T >::Handle ( T *  p  )  [inline]

Definition at line 56 of file Handle.h.

00056                {
00057     classptr = p;
00058     if (classptr != 0) classptr->increment();
00059   }

template<class T>
Handle< T >::Handle ( const Handle< T > &  ref  )  [inline]

Definition at line 61 of file Handle.h.

00061                                {
00062     classptr = ref.classptr;
00063     if (classptr != 0)
00064       classptr->increment();
00065   }

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

Definition at line 67 of file Handle.h.

00067             {
00068     if (classptr != 0) {
00069       classptr->decrement ();
00070       assert(classptr->getNoRefs() >= 0);
00071       if (!classptr->isReferenced()) {
00072         if (classptr->dynamicObj())
00073           delete classptr;
00074       }
00075     }
00076   }


Member Function Documentation

template<class T>
T* Handle< T >::getPtr (  )  [inline]

Definition at line 102 of file Handle.h.

00102 { return  classptr; }

template<class T>
const T* Handle< T >::getPtr (  )  const [inline]

Definition at line 101 of file Handle.h.

Referenced by hed::Edge::getSourceNode(), and Handle< Node >::operator=().

00101 { return  classptr; }

template<class T>
T& Handle< T >::getRef (  )  [inline]

Definition at line 104 of file Handle.h.

00104 { return *classptr; }

template<class T>
const T& Handle< T >::getRef (  )  const [inline]

Definition at line 103 of file Handle.h.

00103 { return *classptr; }

template<class T>
bool Handle< T >::operator!= ( const Handle< T > &  h  )  const [inline]

Definition at line 111 of file Handle.h.

00111 { return classptr != h.classptr; }

template<class T>
T& Handle< T >::operator() (  )  [inline]

Definition at line 98 of file Handle.h.

00098 { return *classptr; }

template<class T>
const T& Handle< T >::operator() (  )  const [inline]

Definition at line 97 of file Handle.h.

00097 { return *classptr; }

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

Definition at line 100 of file Handle.h.

00100 { return *classptr; }

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

Definition at line 99 of file Handle.h.

00099 { return *classptr; }

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

Definition at line 96 of file Handle.h.

00096 { return  classptr; }

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

Definition at line 95 of file Handle.h.

00095 { return  classptr; }

template<class T>
bool Handle< T >::operator< ( const Handle< T > &  h  )  const [inline]

Definition at line 112 of file Handle.h.

00112 { return classptr < h.classptr; }

template<class T>
void Handle< T >::operator= ( const T &  p  )  [inline]

Definition at line 108 of file Handle.h.

00108 { rebind(p); }

template<class T>
void Handle< T >::operator= ( const T *  p  )  [inline]

Definition at line 107 of file Handle.h.

00107 { rebind(p); }

template<class T>
void Handle< T >::operator= ( const Handle< T > &  h  )  [inline]

Definition at line 106 of file Handle.h.

00106 { rebind(h.getPtr()); }

template<class T>
bool Handle< T >::operator== ( const Handle< T > &  h  )  const [inline]

Definition at line 110 of file Handle.h.

00110 { return classptr == h.classptr; }

template<class T>
bool Handle< T >::operator> ( const Handle< T > &  h  )  const [inline]

Definition at line 113 of file Handle.h.

00113 { return classptr > h.classptr; }

template<class T>
void Handle< T >::rebind ( const T &  p  )  [inline]

Definition at line 93 of file Handle.h.

Referenced by Handle< Node >::rebind().

00093 { rebind(&p); }

template<class T>
void Handle< T >::rebind ( const T *  pc  )  [inline]

Definition at line 78 of file Handle.h.

Referenced by Handle< Node >::operator=().

00078                             {
00079     if (classptr != pc) {
00080       T* p = (T*) pc; // cast const away
00081       if (p != 0)
00082         p->increment();
00083       if (classptr != 0) {
00084         classptr->decrement ();
00085         assert(classptr->getNoRefs() >= 0);
00086         if (!classptr->isReferenced() && classptr->dynamicObj())
00087           delete classptr;
00088       }
00089       classptr = p;
00090     }
00091   }


Member Data Documentation

template<class T>
T* Handle< T >::classptr [protected]

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

Generated on Wed Nov 17 17:44:27 2010 for TTL by  doxygen 1.6.1