Public Types | Public Member Functions

ts::IntrusivePtr< T > Class Template Reference

Shared pointer. More...

#include <IntrusivePtr.h>

Inherits ts::IntrusivePtrBase.

Collaboration diagram for ts::IntrusivePtr< T >:
Collaboration graph
[legend]

Public Types

typedef super::Counter Counter
 Promote type for reference counter.

Public Member Functions

 IntrusivePtr ()
 Default constructor (0 initialized).
 IntrusivePtr (T *obj)
 Construct from instance.
 ~IntrusivePtr ()
 Destructor.
 IntrusivePtr (const self &src)
 Copy constructor.
selfoperator= (const self &src)
 Self assignement.
selfoperator= (T *obj)
 Assign from instance.
selfassign (T *obj)
 Assign from instance.
void reset (T *obj)
 Assign from instance.
bool release ()
 Clear reference without cleanup.
bool isNull () const
 Test if the pointer is zero (NULL).
T * operator-> () const
 Member dereference.
T & operator* () const
 Dereference.
T * get () const
 Access raw pointer.
 operator T * () const
 User conversion to raw pointer.
template<typename X >
 IntrusivePtr (IntrusivePtr< X > const &that)
 Cross type construction.
template<typename X >
selfoperator= (IntrusivePtr< X > const &that)
 Cross type assignment.
bool isShared () const
 Check for multiple references.
bool unique () const
 Check for a single reference (shared_ptr compatibility).
Counter useCount () const
 Reference count.

Detailed Description

template<typename T>
class ts::IntrusivePtr< T >

Shared pointer.

This is a reference counted smart pointer. A single object is jointly ownded by a set of pointers. When the last of the pointers is destructed the target object is also destructed.

The smart pointer actions can be changed through class specific policy by specializing the IntrusivePtrPolicy template class.

Definition at line 135 of file IntrusivePtr.h.


Member Typedef Documentation

template<typename T>
typedef super::Counter ts::IntrusivePtr< T >::Counter

Promote type for reference counter.

Reimplemented from ts::IntrusivePtrBase.

Definition at line 142 of file IntrusivePtr.h.


Constructor & Destructor Documentation

template<typename T >
ts::IntrusivePtr< T >::IntrusivePtr (  ) 

Default constructor (0 initialized).

Definition at line 403 of file IntrusivePtr.h.

template<typename T>
ts::IntrusivePtr< T >::IntrusivePtr ( T *  obj  ) 

Construct from instance.

The instance becomes referenced and owned by the pointer.

Definition at line 408 of file IntrusivePtr.h.

template<typename T >
ts::IntrusivePtr< T >::~IntrusivePtr (  ) 

Destructor.

Definition at line 413 of file IntrusivePtr.h.

template<typename T>
ts::IntrusivePtr< T >::IntrusivePtr ( const self src  ) 

Copy constructor.

Definition at line 418 of file IntrusivePtr.h.

template<typename T >
template<typename X >
ts::IntrusivePtr< T >::IntrusivePtr ( IntrusivePtr< X > const &  that  ) 

Cross type construction.

This succeeds if an X* can be implicitly converted to a T*.

Parameters:
that Foreign pointer.

Definition at line 424 of file IntrusivePtr.h.


Member Function Documentation

template<typename T>
IntrusivePtr< T > & ts::IntrusivePtr< T >::assign ( T *  obj  ) 

Assign from instance.

The instance becomes referenced and owned by the pointer. The reference to the current object is dropped.

Note:
A synonym for operator= for compatibility.
Parameters:
obj Target instance.

Definition at line 452 of file IntrusivePtr.h.

template<typename T >
T * ts::IntrusivePtr< T >::get ( void   )  const
template<typename T >
bool ts::IntrusivePtr< T >::isNull (  )  const

Test if the pointer is zero (NULL).

Definition at line 544 of file IntrusivePtr.h.

template<typename T >
bool ts::IntrusivePtr< T >::isShared (  )  const

Check for multiple references.

Returns:
true if more than one smart pointer references the object, false otherwise.

Definition at line 592 of file IntrusivePtr.h.

Referenced by ts::config::Path::reset().

template<typename T >
ts::IntrusivePtr< T >::operator T * (  )  const

User conversion to raw pointer.

Definition at line 587 of file IntrusivePtr.h.

template<typename T >
T & ts::IntrusivePtr< T >::operator* (  )  const

Dereference.

Definition at line 463 of file IntrusivePtr.h.

template<typename T >
T * ts::IntrusivePtr< T >::operator-> (  )  const

Member dereference.

Definition at line 457 of file IntrusivePtr.h.

template<typename T>
IntrusivePtr< T > & ts::IntrusivePtr< T >::operator= ( T *  obj  ) 

Assign from instance.

The instance becomes referenced and owned by the pointer. The reference to the current object is dropped.

Parameters:
obj Target instance.

Definition at line 446 of file IntrusivePtr.h.

References ts::IntrusivePtr< T >::reset().

template<typename T >
template<typename X >
IntrusivePtr< T > & ts::IntrusivePtr< T >::operator= ( IntrusivePtr< X > const &  that  ) 

Cross type assignment.

This succeeds if an X* can be implicitily converted to a T*.

Parameters:
that Foreign pointer.

Definition at line 438 of file IntrusivePtr.h.

References ts::IntrusivePtr< T >::get(), and ts::IntrusivePtr< T >::reset().

template<typename T >
IntrusivePtr< T > & ts::IntrusivePtr< T >::operator= ( const self src  ) 

Self assignement.

Definition at line 430 of file IntrusivePtr.h.

References ts::IntrusivePtr< T >::reset().

template<typename T >
bool ts::IntrusivePtr< T >::release (  ) 

Clear reference without cleanup.

This unsets this smart pointer and decrements the reference count, but does not perform any finalization on the target object. This can easily lead to memory leaks and in some sense vitiates the point of this class, but it is occasionally the right thing to do. Use with caution.

Returns:
true if there are no references upon return, false if the reference count is not zero.

Definition at line 529 of file IntrusivePtr.h.

template<typename T>
void ts::IntrusivePtr< T >::reset ( T *  obj  ) 

Assign from instance.

The instance becomes referenced and owned by the pointer. The reference to the current object is dropped.

Definition at line 521 of file IntrusivePtr.h.

Referenced by ts::config::detail::ValueTable::instance(), and ts::IntrusivePtr< T >::operator=().

template<typename T >
bool ts::IntrusivePtr< T >::unique (  )  const

Check for a single reference (shared_ptr compatibility).

Returns:
true if this object is not shared.

Definition at line 597 of file IntrusivePtr.h.

template<typename T >
IntrusivePtr< T >::Counter ts::IntrusivePtr< T >::useCount (  )  const

Reference count.

Returns:
Number of references.

Definition at line 602 of file IntrusivePtr.h.

Referenced by ts::Errata::pre_write().


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