Guiliani  Version 2.5 revision 7293 (documentation build 13)
NSmartPtr::SharedPtr< C > Class Template Reference

The reference counted pointer class used with RefCounted. More...

#include <SharedPtr.h>

Public Member Functions

 SharedPtr ()
 Creates a shared NULL pointer.
 
 SharedPtr (C *rawPtr)
 
 SharedPtr (const SharedPtr &rhs)
 
template<class C2 >
 SharedPtr (const SharedPtr< C2 > &otherSharedPtr)
 
 ~SharedPtr ()
 Destroys the SharedPtr.
 
 operator bool () const
 
bool operator! () const
 
C & operator* () const
 
C * operator-> () const
 
template<class C2 >
SharedPtroperator= (C2 *rawPtr)
 
SharedPtroperator= (const SharedPtr &rhs)
 
template<class C2 >
SharedPtr< C > & operator= (const SharedPtr< C2 > &otherSharedPtr)
 
C * RawPtr () const
 

Detailed Description

template<class C>
class NSmartPtr::SharedPtr< C >

The reference counted pointer class used with RefCounted.

A SharedPtr manages access to a shared object of a pointer type C.

The pointee type is specified as template parameter.

The SharedPtr calls C::AddRef a construction and C::Release on destruction. The implementor of the class is responsible to provide the AddRef and Release methods. A convenient way to provide these methods is the RefCounted class, which provides an automatic destruction of allocated objects based on reference counts.

For most operations a SharedPtr behaves like a raw C++ pointer:

  • A SharedPtr can be NULL.
  • The -> operator of a SharedPtr returns the raw pointer. If the pointee class type is const, the returned pointer is also const.
  • The * operator of a SharedPtr dereferences the raw pointer.
  • Shared pointers are equal if the raw pointers are equal. The == operator is used to check for equality. The == operator can also be used to compare shared pointers and raw pointers.
  • Shared pointers are assignment compatible if the raw pointers are assignment compatible, e.g. a SharedPtr<Derived> class may be assigned to SharedPtr<Base> if class Derived is derived from Base.

However, there are some differences between shared pointers and raw pointers:

  • Shared pointers can only be defined for pointee types that provide an AddRef and Release method.
  • Explicit casts (static_cast, const_cast, dynamic_cast) for SharedPtrs are currently not provided.
  • A SharedPtr is always typed. Defining a SharedPtr for a generic pointee type, like SharedPtr<void*> is not possible.

Constructor & Destructor Documentation

◆ SharedPtr() [1/3]

template<class C >
NSmartPtr::SharedPtr< C >::SharedPtr ( C *  rawPtr)
inline

Creates a shared pointer for a given raw pointer.

Parameters
rawPtr

◆ SharedPtr() [2/3]

template<class C >
NSmartPtr::SharedPtr< C >::SharedPtr ( const SharedPtr< C > &  rhs)
inline

Creates a copy of a shared pointer.

Parameters
rhs

◆ SharedPtr() [3/3]

template<class C >
template<class C2 >
NSmartPtr::SharedPtr< C >::SharedPtr ( const SharedPtr< C2 > &  otherSharedPtr)
inline

Creates a copy of a shared pointer with implicit conversion from derived type.

Parameters
otherSharedPtrThe source to copy from

Member Function Documentation

◆ operator bool()

template<class C >
NSmartPtr::SharedPtr< C >::operator bool
inline

Check for NULL pointer.

Returns
False if this SharedPtr is NULL, else True.

◆ operator!()

template<class C >
bool NSmartPtr::SharedPtr< C >::operator!
inline

Check for NULL pointer.

Returns
True if this SharedPtr is NULL, else False.

◆ operator*()

template<class C >
C & NSmartPtr::SharedPtr< C >::operator*
inline
Returns
Access the dereferenced raw pointer.

◆ operator->()

template<class C >
C * NSmartPtr::SharedPtr< C >::operator->
inline
Returns
Access the raw pointer.

◆ operator=() [1/3]

template<class C >
template<class C2 >
SharedPtr & NSmartPtr::SharedPtr< C >::operator= ( C2 *  rawPtr)
inline

Assignment of raw pointer to this SharedPtr with implicit conversion from derived type.

Parameters
rawPtrThe source of the assignment
Returns
The addignment destination

◆ operator=() [2/3]

template<class C >
SharedPtr & NSmartPtr::SharedPtr< C >::operator= ( const SharedPtr< C > &  rhs)
inline

Assignment operator with shared pointer of same type.

Parameters
rhs
Returns
copy

◆ operator=() [3/3]

template<class C >
template<class C2 >
SharedPtr< C > & NSmartPtr::SharedPtr< C >::operator= ( const SharedPtr< C2 > &  otherSharedPtr)
inline

Assignment of SharedPtr of derived type.

Parameters
otherSharedPtr
Returns
copy

◆ RawPtr()

template<class C >
C * NSmartPtr::SharedPtr< C >::RawPtr
inline

Get the raw pointer.

Returns
The raw pointer.

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