Public Types | Public Member Functions | Public Attributes

mitk::WeakPointer< TObjectType > Class Template Reference

Implements a weak reference to an object. More...

#include <mitkWeakPointer.h>

Inheritance diagram for mitk::WeakPointer< TObjectType >:
Inheritance graph
[legend]
Collaboration diagram for mitk::WeakPointer< TObjectType >:
Collaboration graph
[legend]

List of all members.

Public Types

typedef TObjectType ObjectType
typedef Message1< const
itk::Object * > 
itkObjectEvent

Public Member Functions

 WeakPointer ()
 WeakPointer (const WeakPointer< ObjectType > &p)
 WeakPointer (ObjectType *p)
 ~WeakPointer ()
ObjectTypeoperator-> () const
 operator ObjectType * () const
template<typename R >
bool operator== (R r) const
template<typename R >
bool operator!= (R r) const
ObjectTypeGetPointer () const
bool operator< (const WeakPointer &r) const
bool operator> (const WeakPointer &r) const
bool operator<= (const WeakPointer &r) const
bool operator>= (const WeakPointer &r) const
bool IsNotNull () const
bool IsNull () const
WeakPointeroperator= (const WeakPointer &r)
WeakPointeroperator= (ObjectType *r)
ObjectTypePrint (std::ostream &os) const
void OnObjectDelete (const itk::Object *caller, const itk::EventObject &)
 Gets called when the object is deleted or modified.
void OnObjectModified (const itk::Object *caller, const itk::EventObject &)

Public Attributes

itkObjectEvent ObjectDelete
 AddEvent is emitted when the object pointed to gets deleted.
itkObjectEvent ObjectModified
 AddEvent is emitted when the object pointed to gets modified.

Detailed Description

template<class TObjectType>
class mitk::WeakPointer< TObjectType >

Implements a weak reference to an object.

Extends the standard itk WeakPointer by listening to delete events of itk::Objects. When an itk::Object is deleted the WeakPointer sets its internal Pointer to 0. This enables checking against 0 and avoids crashes by accessing changed memory. Furthermore it dispatches Modified events with the mitkMessageDelegate system which is much easier to use.

Definition at line 40 of file mitkWeakPointer.h.


Member Typedef Documentation

template<class TObjectType>
typedef Message1<const itk::Object*> mitk::WeakPointer< TObjectType >::itkObjectEvent

Definition at line 46 of file mitkWeakPointer.h.

template<class TObjectType>
typedef TObjectType mitk::WeakPointer< TObjectType >::ObjectType

Extract infoirmation from template parameter.

Definition at line 44 of file mitkWeakPointer.h.


Constructor & Destructor Documentation

template<class TObjectType>
mitk::WeakPointer< TObjectType >::WeakPointer (  ) [inline]

Constructor.

Definition at line 56 of file mitkWeakPointer.h.

    : m_DeleteObserverTag(-1)
    , m_ModifiedObserverTag(-1)
    , m_Pointer(0)
  {
  }
template<class TObjectType>
mitk::WeakPointer< TObjectType >::WeakPointer ( const WeakPointer< ObjectType > &  p ) [inline]

Copy constructor.

Definition at line 64 of file mitkWeakPointer.h.

    : m_DeleteObserverTag(-1)
    , m_ModifiedObserverTag(-1)
    , m_Pointer(p.m_Pointer)
  {
    this->AddDeleteAndModifiedObserver();
  }
template<class TObjectType>
mitk::WeakPointer< TObjectType >::WeakPointer ( ObjectType p ) [inline]

Constructor to pointer p.

Definition at line 73 of file mitkWeakPointer.h.

    : m_DeleteObserverTag(-1),
      m_ModifiedObserverTag(-1),
      m_Pointer(p) 
  {
    this->AddDeleteAndModifiedObserver();
  }
template<class TObjectType>
mitk::WeakPointer< TObjectType >::~WeakPointer (  ) [inline]

Destructor.

Definition at line 82 of file mitkWeakPointer.h.

  { 
    this->RemoveDeleteAndModifiedObserver();

    m_Pointer = 0; 
  }

Member Function Documentation

template<class TObjectType>
ObjectType* mitk::WeakPointer< TObjectType >::GetPointer (  ) const [inline]
template<class TObjectType>
bool mitk::WeakPointer< TObjectType >::IsNotNull (  ) const [inline]
template<class TObjectType>
bool mitk::WeakPointer< TObjectType >::IsNull (  ) const [inline]
template<class TObjectType>
void mitk::WeakPointer< TObjectType >::OnObjectDelete ( const itk::Object *  caller,
const itk::EventObject &   
) [inline]

Gets called when the object is deleted or modified.

Definition at line 159 of file mitkWeakPointer.h.

  {
    // do not unsubscribe from this object. this would invalidate the iterator of the
    // event listener vector (in itk::Object) and would lead to a crash
    // instead: do nothing->object is going to be dead soon...
    //this->RemoveDeleteAndModifiedObserver();
    m_Pointer = 0;
    m_DeleteObserverTag = -1;
    m_ModifiedObserverTag = -1;
    ObjectDelete.Send(caller);

  }
template<class TObjectType>
void mitk::WeakPointer< TObjectType >::OnObjectModified ( const itk::Object *  caller,
const itk::EventObject &   
) [inline]

Definition at line 172 of file mitkWeakPointer.h.

  {
    ObjectModified.Send(caller);
  }
template<class TObjectType>
mitk::WeakPointer< TObjectType >::operator ObjectType * (  ) const [inline]

Return pointer to object.

Definition at line 94 of file mitkWeakPointer.h.

    { return m_Pointer; }
template<class TObjectType>
template<typename R >
bool mitk::WeakPointer< TObjectType >::operator!= ( r ) const [inline]

Definition at line 104 of file mitkWeakPointer.h.

    {
    return (m_Pointer != (ObjectType*)r);
    }
template<class TObjectType>
ObjectType* mitk::WeakPointer< TObjectType >::operator-> (  ) const [inline]

Overload operator ->.

Definition at line 90 of file mitkWeakPointer.h.

    { return m_Pointer; }
template<class TObjectType>
bool mitk::WeakPointer< TObjectType >::operator< ( const WeakPointer< TObjectType > &  r ) const [inline]

Comparison of pointers. Less than comparison.

Definition at line 114 of file mitkWeakPointer.h.

    { return (void*)m_Pointer < (void*) r.m_Pointer; }
template<class TObjectType>
bool mitk::WeakPointer< TObjectType >::operator<= ( const WeakPointer< TObjectType > &  r ) const [inline]

Comparison of pointers. Less than or equal to comparison.

Definition at line 122 of file mitkWeakPointer.h.

    { return (void*)m_Pointer <= (void*) r.m_Pointer; }
template<class TObjectType>
WeakPointer& mitk::WeakPointer< TObjectType >::operator= ( ObjectType r ) [inline]

Overload operator assignment.

Definition at line 140 of file mitkWeakPointer.h.

  {
    this->RemoveDeleteAndModifiedObserver();
    m_Pointer = r;
    this->AddDeleteAndModifiedObserver();
    return *this;
  }
template<class TObjectType>
WeakPointer& mitk::WeakPointer< TObjectType >::operator= ( const WeakPointer< TObjectType > &  r ) [inline]

Overload operator assignment.

Definition at line 136 of file mitkWeakPointer.h.

Referenced by mitk::WeakPointer< mitk::PointSetInteractor >::operator=().

    { return this->operator = (r.GetPointer()); }
template<class TObjectType>
template<typename R >
bool mitk::WeakPointer< TObjectType >::operator== ( r ) const [inline]

Template comparison operators.

Definition at line 99 of file mitkWeakPointer.h.

    {
    return (m_Pointer == (ObjectType*)r);
    }
template<class TObjectType>
bool mitk::WeakPointer< TObjectType >::operator> ( const WeakPointer< TObjectType > &  r ) const [inline]

Comparison of pointers. Greater than comparison.

Definition at line 118 of file mitkWeakPointer.h.

    { return (void*)m_Pointer > (void*) r.m_Pointer; }
template<class TObjectType>
bool mitk::WeakPointer< TObjectType >::operator>= ( const WeakPointer< TObjectType > &  r ) const [inline]

Comparison of pointers. Greater than or equal to comparison.

Definition at line 126 of file mitkWeakPointer.h.

    { return (void*)m_Pointer >= (void*) r.m_Pointer; }
template<class TObjectType>
ObjectType* mitk::WeakPointer< TObjectType >::Print ( std::ostream &  os ) const [inline]

Function to print object pointed to.

Definition at line 149 of file mitkWeakPointer.h.

  {
  // This prints the object pointed to by the pointer
  (*m_Pointer).Print(os);
  return m_Pointer;
  }

Member Data Documentation

template<class TObjectType>
itkObjectEvent mitk::WeakPointer< TObjectType >::ObjectDelete
template<class TObjectType>
itkObjectEvent mitk::WeakPointer< TObjectType >::ObjectModified

AddEvent is emitted when the object pointed to gets modified.

Definition at line 53 of file mitkWeakPointer.h.

Referenced by mitk::WeakPointer< mitk::PointSetInteractor >::OnObjectModified(), and QmitkPointListViewWidget::SetPointSet().


The documentation for this class was generated from the following file:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines