IECore::IntrusivePtr< T > Class Template Reference

#include <IntrusivePtr.h>

List of all members.

Public Types

typedef T element_type

Public Member Functions

 IntrusivePtr ()
 IntrusivePtr (T *p)
template<typename U >
 IntrusivePtr (IntrusivePtr< U > const &rhs)
 IntrusivePtr (IntrusivePtr const &rhs)
 ~IntrusivePtr ()
template<typename U >
IntrusivePtroperator= (IntrusivePtr< U > const &rhs)
IntrusivePtroperator= (IntrusivePtr const &rhs)
IntrusivePtroperator= (T *rhs)
void reset ()
void reset (T *rhs)
T * get () const
T & operator* () const
T * operator-> () const
 operator T * ()
 operator T const * () const
template<class U >
bool operator== (IntrusivePtr< U > const &b) const
template<class U >
bool operator!= (IntrusivePtr< U > const &b) const
template<class U >
bool operator== (U *b) const
template<class U >
bool operator!= (U *b) const
bool operator< (IntrusivePtr const &b) const
void swap (IntrusivePtr &rhs)


Detailed Description

template<class T>
class IECore::IntrusivePtr< T >

Templated class following the same interface defined by boost::intrusive_ptr with one major change: implicit conversion to raw pointers. It uses the same reference increment and decrement functions used by boost: intrusive_ptr_add_ref and intrusive_ptr_release.

IntrusivePtr should be used anywhere in Cortex where it is necessary to maintain ownership of an instance derived from RefCounted, or to share ownership between several interested parties. The construction of an IntrusivePtr pointer increments the reference count and the destruction of an IntrusivePtr decrements the reference count - when the count drops to 0 the RefCounted object will self destruct. All RefCounted derived types define both a Type::Ptr and TypePtr typedef for an IntrusivePtr pointing to that type.

There is some limited overhead involved in the reference counting associated with IntrusivePtr, and for this reason, and in an attempt to strengthen the semantics of pointer usage in Cortex, we try to use the following conventions when defining programming interfaces :

When receiving a pointer as a function argument :

Pass a raw (Type *) pointer if the called function has no need to increment the reference count. For instance Renderable::render( Renderer *renderer ) takes a raw pointer as the Renderable should not need to hold a reference to the Renderer following the call.

Pass an IntrusivePtr (TypePtr) if the reference count will be changed following the function call. For instance Group::addChild( VisibleRenderablePtr child ) takes an IntrusivePtr as the group will maintain a reference to the child following the call.

When returning a pointer from a method :

Return a raw (Type *) pointer if the called object will continue to maintain a reference to the returned object following the method call. For instance CompoundObject::member() returns a raw pointer, because the CompoundObject will continue to hold a reference to the returned object following the call. The caller can assign the raw pointer to an IntrusivePtr if it wishes to own its own reference to the result, but if it merely wants to use the result temporarily it can rely on the owner to maintain a reference until the owner dies.

Return an IntrusivePtr (TypePtr) if the method or function is returning an object for which no other references are currently held. For instance Object::create() returns an ObjectPtr so that a reference to the new object exists, and to encourage the caller to maintain ownership of the new object.

When calling operator new :

Always assign the result of operator new for a RefCounted class to an IntrusivePtr immediately, to assume ownership of the new object.

Note:
Not all of Cortex has been updated to match these conventions. Please add todo items for any nonconforming APIs.

Member Typedef Documentation

template<class T>
typedef T IECore::IntrusivePtr< T >::element_type


Constructor & Destructor Documentation

template<class T>
IECore::IntrusivePtr< T >::IntrusivePtr (  ) 

template<class T>
IECore::IntrusivePtr< T >::IntrusivePtr ( T *  p  ) 

template<class T>
template<typename U >
IECore::IntrusivePtr< T >::IntrusivePtr ( IntrusivePtr< U > const &  rhs  )  [inline]

template<class T>
IECore::IntrusivePtr< T >::IntrusivePtr ( IntrusivePtr< T > const &  rhs  ) 

template<class T>
IECore::IntrusivePtr< T >::~IntrusivePtr (  ) 


Member Function Documentation

template<class T>
T* IECore::IntrusivePtr< T >::get (  )  const [inline]

template<class T>
IECore::IntrusivePtr< T >::operator T * (  )  [inline]

template<class T>
IECore::IntrusivePtr< T >::operator T const * (  )  const [inline]

template<class T>
template<class U >
bool IECore::IntrusivePtr< T >::operator!= ( U *  b  )  const [inline]

template<class T>
template<class U >
bool IECore::IntrusivePtr< T >::operator!= ( IntrusivePtr< U > const &  b  )  const [inline]

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

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

template<class T>
bool IECore::IntrusivePtr< T >::operator< ( IntrusivePtr< T > const &  b  )  const [inline]

template<class T>
IntrusivePtr& IECore::IntrusivePtr< T >::operator= ( T *  rhs  )  [inline]

template<class T>
IntrusivePtr& IECore::IntrusivePtr< T >::operator= ( IntrusivePtr< T > const &  rhs  )  [inline]

template<class T>
template<typename U >
IntrusivePtr& IECore::IntrusivePtr< T >::operator= ( IntrusivePtr< U > const &  rhs  )  [inline]

template<class T>
template<class U >
bool IECore::IntrusivePtr< T >::operator== ( U *  b  )  const [inline]

template<class T>
template<class U >
bool IECore::IntrusivePtr< T >::operator== ( IntrusivePtr< U > const &  b  )  const [inline]

template<class T>
void IECore::IntrusivePtr< T >::reset ( T *  rhs  )  [inline]

template<class T>
void IECore::IntrusivePtr< T >::reset (  )  [inline]

template<class T>
void IECore::IntrusivePtr< T >::swap ( IntrusivePtr< T > &  rhs  )  [inline]


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

Generated on Mon Jan 24 11:13:25 2011 for Cortex by doxygen 1.5.8