Main Page   Modules   Namespace List   Class Hierarchy   Compound List   Namespace Members   Compound Members   Related Pages  

GNE::SmartPtr< T > Class Template Reference
[Mid-Level API]

#include <SmartPtr.h>

Inheritance diagram for GNE::SmartPtr< T >:

List of all members.

Public Member Functions

template<class Y>  SmartPtr (Y *p)
template<class Y, class D>  SmartPtr (Y *p, D d)
 SmartPtr (const boost::shared_ptr< T > &o)
template<class Y>  SmartPtr (const SmartPtr< Y > &o)
template<class Y> SmartPtr & operator= (const boost::shared_ptr< Y > &r)
T * operator-> () const

Detailed Description

template<class T>
class GNE::SmartPtr< T >

The SmartPtr class is a reference-counted smart pointer implementation for general use

These smart pointers hold a reference count to their object. When the last handle to the object is lost, then the object is automatically destroyed using the deleter object (the default object simply calls "delete"). This works if there are no "cycles". Use weak pointers to break cycles (see URL below for details).

The reference counting makes it easy to manage objects in multiple threads. It is safe to use handles to the same object in different threads. It is NOT safe to share the exact same SmartPtr instance between threads, but this should not be a problem since SmartPtrs are meant to be copied.

Because the smart pointers are CopyConstructable, Assignable and implement operator &lt;, they can be used in the STL containers, including std::map.

An object managed by any of the smart pointer classes must be on the heap when using the default deleter.

Very simple example usage (see expointers example for more):

void func() { SmartPtr<MyObject> oPtr ( new MyObject() ); oPtr->method(); } //oPtr will automatically destroy its object.

The reason for not using boost::shared_ptr directly is because I wanted to abstract the implementation of the pointer. Right now it uses a passive reference count but an intrusive reference count may have better performance so I may switch in the future, but for now it just inherits from another implementation.

So although the methods aren't all listed here, I am supporting the following methods: (you can see details at http://www.boost.org/libs/smart_ptr/shared_ptr.htm)

See also:
GNE::WeakPtr

NullDeleter


The documentation for this class was generated from the following file:
Generated on Fri Aug 22 13:40:06 2003 for GNE by doxygen1.3