MDSTk Libraries  1.1.0
Medical Data Segmentation Toolkit
Public Types | Public Member Functions | Friends
mds::base::CScopedPtr< T > Class Template Reference

Base smart pointer which transfers ownership of a handled object. More...

#include <mdsScopedPtr.h>

Inheritance diagram for mds::base::CScopedPtr< T >:
Inheritance graph
[legend]

List of all members.

Public Types

typedef T tPointee
 Pointee type.
typedef T * tPointer
 Stored pointer type.

Public Member Functions

 CScopedPtr ()
 Default constructor.
 CScopedPtr (T *p)
 Constructor from a raw pointer.
 CScopedPtr (CScopedPtr &p)
 Copy constructor.
void destroy ()
 Deletes the encapsulated object if required and initializes the internal pointer to NULL.
T * get ()
 Returns pointer to the encapsulated object.
const T * get () const
 operator T * ()
 Conversion to the raw pointer.
 operator void * ()
 Added conversion to the void pointer to avoid raw pointer deletion.
bool operator! () const
 Enables "if (!sp) ...".
template<typename U >
bool operator!= (const CScopedPtr< U > &r) const
T & operator* () const
 Returns reference to the stored object.
T * operator-> () const
 Returns pointer to the encapsulated object.
template<typename U >
bool operator< (const CScopedPtr< U > &r) const
CScopedPtroperator= (CScopedPtr &p)
 Assignment operator.
CScopedPtroperator= (T *p)
 Assignment operator.
template<typename U >
bool operator== (const CScopedPtr< U > &r) const
 Ambiguity buster solving the comparision of two smart pointers.
T * release ()
 Returns pointer to the encapsulated object and clears the m_bDestroy flag, therefore an user must handle the object deletion on his own.
void setDestroyFlag ()
 Sets the m_bDestroy flag.
 ~CScopedPtr ()
 Destructor.

Friends

bool operator!= (const CScopedPtr &l, const T *r)
bool operator!= (const T *l, const CScopedPtr &r)
template<typename U >
bool operator!= (const CScopedPtr &l, const U *r)
template<typename U >
bool operator!= (const U *l, const CScopedPtr &r)
bool operator< (const CScopedPtr &l, const T *r)
bool operator< (const T *l, const CScopedPtr &r)
template<typename U >
bool operator< (const CScopedPtr &l, const U *r)
template<typename U >
bool operator< (const U *l, const CScopedPtr &r)
bool operator== (const CScopedPtr &l, const T *r)
 Comparision operators.
bool operator== (const T *l, const CScopedPtr &r)
template<typename U >
bool operator== (const CScopedPtr &l, const U *r)
 Ambiquity buster that solves problem using comparision like "if( p == sp ) ...".
template<typename U >
bool operator== (const U *l, const CScopedPtr &r)

Detailed Description

template<typename T>
class mds::base::CScopedPtr< T >

Base smart pointer which transfers ownership of a handled object.

Once the pointer is initialized, it takes control over the pointer including object deletion.


Member Typedef Documentation

template<typename T>
typedef T mds::base::CScopedPtr< T >::tPointee

Pointee type.

template<typename T>
typedef T* mds::base::CScopedPtr< T >::tPointer

Stored pointer type.


Constructor & Destructor Documentation

template<typename T>
mds::base::CScopedPtr< T >::CScopedPtr ( )

Default constructor.

  • Internal pointer is initialized to the NULL!
  • Use with care!
template<typename T>
mds::base::CScopedPtr< T >::CScopedPtr ( T *  p)

Constructor from a raw pointer.

  • NULL can be given too.
template<typename T>
mds::base::CScopedPtr< T >::CScopedPtr ( CScopedPtr< T > &  p)

Copy constructor.

  • Transfers ownership from one pointer to another.
template<typename T>
mds::base::CScopedPtr< T >::~CScopedPtr ( )

Destructor.


Member Function Documentation

template<typename T>
void mds::base::CScopedPtr< T >::destroy ( )

Deletes the encapsulated object if required and initializes the internal pointer to NULL.

template<typename T>
T* mds::base::CScopedPtr< T >::get ( )

Returns pointer to the encapsulated object.

template<typename T>
const T* mds::base::CScopedPtr< T >::get ( ) const
template<typename T>
mds::base::CScopedPtr< T >::operator T * ( )

Conversion to the raw pointer.

template<typename T>
mds::base::CScopedPtr< T >::operator void * ( )

Added conversion to the void pointer to avoid raw pointer deletion.

template<typename T>
bool mds::base::CScopedPtr< T >::operator! ( ) const

Enables "if (!sp) ...".

template<typename T>
template<typename U >
bool mds::base::CScopedPtr< T >::operator!= ( const CScopedPtr< U > &  r) const
template<typename T>
T& mds::base::CScopedPtr< T >::operator* ( ) const

Returns reference to the stored object.

template<typename T>
T* mds::base::CScopedPtr< T >::operator-> ( ) const

Returns pointer to the encapsulated object.

template<typename T>
template<typename U >
bool mds::base::CScopedPtr< T >::operator< ( const CScopedPtr< U > &  r) const
template<typename T>
CScopedPtr& mds::base::CScopedPtr< T >::operator= ( CScopedPtr< T > &  p)

Assignment operator.

  • Transfers ownership from one pointer to another.
template<typename T>
CScopedPtr& mds::base::CScopedPtr< T >::operator= ( T *  p)

Assignment operator.

  • Makes a reference to the object
template<typename T>
template<typename U >
bool mds::base::CScopedPtr< T >::operator== ( const CScopedPtr< U > &  r) const

Ambiguity buster solving the comparision of two smart pointers.

template<typename T>
T* mds::base::CScopedPtr< T >::release ( )

Returns pointer to the encapsulated object and clears the m_bDestroy flag, therefore an user must handle the object deletion on his own.

  • Use with care!
template<typename T>
void mds::base::CScopedPtr< T >::setDestroyFlag ( )

Sets the m_bDestroy flag.

  • Use with care!

Friends And Related Function Documentation

template<typename T>
bool operator!= ( const CScopedPtr< T > &  l,
const T *  r 
) [friend]
template<typename T>
bool operator!= ( const T *  l,
const CScopedPtr< T > &  r 
) [friend]
template<typename T>
template<typename U >
bool operator!= ( const CScopedPtr< T > &  l,
const U *  r 
) [friend]
template<typename T>
template<typename U >
bool operator!= ( const U *  l,
const CScopedPtr< T > &  r 
) [friend]
template<typename T>
bool operator< ( const CScopedPtr< T > &  l,
const T *  r 
) [friend]
template<typename T>
bool operator< ( const T *  l,
const CScopedPtr< T > &  r 
) [friend]
template<typename T>
template<typename U >
bool operator< ( const CScopedPtr< T > &  l,
const U *  r 
) [friend]
template<typename T>
template<typename U >
bool operator< ( const U *  l,
const CScopedPtr< T > &  r 
) [friend]
template<typename T>
bool operator== ( const CScopedPtr< T > &  l,
const T *  r 
) [friend]

Comparision operators.

template<typename T>
bool operator== ( const T *  l,
const CScopedPtr< T > &  r 
) [friend]
template<typename T>
template<typename U >
bool operator== ( const CScopedPtr< T > &  l,
const U *  r 
) [friend]

Ambiquity buster that solves problem using comparision like "if( p == sp ) ...".

template<typename T>
template<typename U >
bool operator== ( const U *  l,
const CScopedPtr< T > &  r 
) [friend]

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