Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

MynahSA::SharedPtr< T > Class Template Reference

#include <spimpl.hpp>

Collaboration diagram for MynahSA::SharedPtr< T >:

Collaboration graph
[legend]
List of all members.

Public Member Functions

 SharedPtr ()
 default constructor - creates a null pointer
 SharedPtr (T *p)
 SharedPtr (const SharedPtr &p)
 copy constructor
 SharedPtr (Detail::SPBase *p)
virtual ~SharedPtr ()
 Destructor - destroyes instance if reference count goes to zero.
T * get () const
 Provides direct access to the underlying pointer.
T & operator * () const
 dereference operator.
T * operator-> () const
 pointer dereference operator
bool operator< (const SharedPtr &in) const
 LT comparable. Allows sorting of pointer objects.
SharedPtroperator= (const SharedPtr &in)
 Assignment - allows copying of a shared pointer while preserving S.P. behavior.
bool operator== (const SharedPtr &in) const
 Shared pointer equality test.
bool operator== (T *ptr) const
 Shared pointer equality to base pointer (generally used for zero test).
 operator bool () const
 cast to bool - true if pointer is not zero.
template<class B>
 operator SharedPtr () const
 Pointer conversion operator. Allows type conversion of shared pointers.

Friends

template<class B, class A>
SharedPtr< B > StaticPtrCast (const SharedPtr< A > &src)

Detailed Description

template<class T>
class MynahSA::SharedPtr< T >

Class SharedPtr is a shared pointer implementation for MynahSA. Shared poitners are used in place of standard c pointers to prevent the ills that come along with misues of standard c style pointers.

This shared pointer implementation uses template specialization and an underlying container to allow conversions to and from void types and up and down class hierarchies. The conversions are performed using the function StaticPtrCast. Casting a pointer from one type to another preserves the reference count.

When all holders of a shared pointer are deleted the object held by the shared pointer is also deleted.

Definition at line 113 of file spimpl.hpp.


Constructor & Destructor Documentation

template<class T>
MynahSA::SharedPtr< T >::SharedPtr T *  p  )  [inline]
 

Constructor - creates a new shared pointer of type T, along with pointer carrier and reference count. Initially the reference count is set to 1.

Parameters:
p - The pointer that will now be owned by this shared pointer instance.
Returns:

Definition at line 129 of file spimpl.hpp.

00129                     : _spref(new Detail::SPImpl<T>(p)) { 
00130     }

template<class T>
MynahSA::SharedPtr< T >::SharedPtr Detail::SPBase p  )  [inline]
 

This is a compiler workaround constructor. Some compilers have issues dealing with friendship relations between instances with different template parameters. This constructor is designed as a work-around by passing in the pointer carrier. It is not intended for general use.

Parameters:
p - a pointer carrier.
Returns:

Definition at line 148 of file spimpl.hpp.

References MynahSA::Detail::SPBase::ref().

00148                                : _spref(p) {
00149       if (p) { 
00150         p->ref();
00151       }
00152     }

Here is the call graph for this function:


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