#include <IntrusivePtr.h>
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 > | |
| IntrusivePtr & | operator= (IntrusivePtr< U > const &rhs) |
| IntrusivePtr & | operator= (IntrusivePtr const &rhs) |
| IntrusivePtr & | operator= (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) |
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.
| typedef T IECore::IntrusivePtr< T >::element_type |
| IECore::IntrusivePtr< T >::IntrusivePtr | ( | ) |
| IECore::IntrusivePtr< T >::IntrusivePtr | ( | T * | p | ) |
| IECore::IntrusivePtr< T >::IntrusivePtr | ( | IntrusivePtr< U > const & | rhs | ) | [inline] |
| IECore::IntrusivePtr< T >::IntrusivePtr | ( | IntrusivePtr< T > const & | rhs | ) |
| IECore::IntrusivePtr< T >::~IntrusivePtr | ( | ) |
| T* IECore::IntrusivePtr< T >::get | ( | ) | const [inline] |
| IECore::IntrusivePtr< T >::operator T * | ( | ) | [inline] |
| IECore::IntrusivePtr< T >::operator T const * | ( | ) | const [inline] |
| bool IECore::IntrusivePtr< T >::operator!= | ( | U * | b | ) | const [inline] |
| bool IECore::IntrusivePtr< T >::operator!= | ( | IntrusivePtr< U > const & | b | ) | const [inline] |
| T& IECore::IntrusivePtr< T >::operator* | ( | ) | const [inline] |
| T* IECore::IntrusivePtr< T >::operator-> | ( | ) | const [inline] |
| bool IECore::IntrusivePtr< T >::operator< | ( | IntrusivePtr< T > const & | b | ) | const [inline] |
| IntrusivePtr& IECore::IntrusivePtr< T >::operator= | ( | T * | rhs | ) | [inline] |
| IntrusivePtr& IECore::IntrusivePtr< T >::operator= | ( | IntrusivePtr< T > const & | rhs | ) | [inline] |
| IntrusivePtr& IECore::IntrusivePtr< T >::operator= | ( | IntrusivePtr< U > const & | rhs | ) | [inline] |
| bool IECore::IntrusivePtr< T >::operator== | ( | U * | b | ) | const [inline] |
| bool IECore::IntrusivePtr< T >::operator== | ( | IntrusivePtr< U > const & | b | ) | const [inline] |
| void IECore::IntrusivePtr< T >::reset | ( | T * | rhs | ) | [inline] |
| void IECore::IntrusivePtr< T >::reset | ( | ) | [inline] |
| void IECore::IntrusivePtr< T >::swap | ( | IntrusivePtr< T > & | rhs | ) | [inline] |
1.5.8