SGSharedPtr< T > Class Template Reference

This class is a pointer proxy doing reference counting on the object it is pointing to. More...

#include <SGSharedPtr.hxx>

List of all members.

Public Member Functions

 SGSharedPtr (void)
 SGSharedPtr (T *ptr)
 SGSharedPtr (const SGSharedPtr &p)
template<typename U>
 SGSharedPtr (const SGSharedPtr< U > &p)
 ~SGSharedPtr (void)
SGSharedPtroperator= (const SGSharedPtr &p)
template<typename U>
SGSharedPtroperator= (const SGSharedPtr< U > &p)
template<typename U>
SGSharedPtroperator= (U *p)
T * operator-> (void) const
T & operator * (void) const
 operator T * (void) const
T * ptr (void) const
bool isShared (void) const
unsigned getNumRefs (void) const
bool valid (void) const


Detailed Description

template<typename T>
class SGSharedPtr< T >

This class is a pointer proxy doing reference counting on the object it is pointing to.

The SGSharedPtr class handles reference counting and possible destruction if no nore references are in use automatically. Classes derived from can be handled with SGSharedPtr. Once you have a SGSharedPtr available you can use it just like a usual pointer with the exception that you don't need to delete it. Such a reference is initialized by zero if not initialized with a class pointer. One thing you need to avoid are cyclic loops with such pointers. As long as such a cyclic loop exists the reference count never drops to zero and consequently the objects will never be destroyed. Always try to use directed graphs where the references away from the top node are made with SGSharedPtr's and the back references are done with ordinary pointers. There is a very good description of OpenSceneGraphs ref_ptr which is pretty much the same than this one at http://dburns.dhs.org/OSG/Articles/RefPointers/RefPointers.html

Definition at line 46 of file SGSharedPtr.hxx.


The documentation for this class was generated from the following file:
Generated on Mon Dec 17 09:30:57 2007 for SimGear by  doxygen 1.5.1