17 #ifndef __mitkWeakPointer_h
18 #define __mitkWeakPointer_h
24 #include <itkCommand.h>
37 template <
class TObjectType>
54 WeakPointer() : m_DeleteObserverTag(-1), m_ModifiedObserverTag(-1), m_Pointer(nullptr) {}
57 : m_DeleteObserverTag(-1), m_ModifiedObserverTag(-1), m_Pointer(p.m_Pointer)
59 this->AddDeleteAndModifiedObserver();
63 WeakPointer(ObjectType *p) : m_DeleteObserverTag(-1), m_ModifiedObserverTag(-1), m_Pointer(p)
65 this->AddDeleteAndModifiedObserver();
71 this->RemoveDeleteAndModifiedObserver();
79 operator ObjectType *()
const {
return m_Pointer; }
84 return (m_Pointer == (ObjectType *)r);
89 return (m_Pointer != (ObjectType *)r);
104 bool IsNull()
const {
return m_Pointer ==
nullptr; }
110 this->RemoveDeleteAndModifiedObserver();
112 this->AddDeleteAndModifiedObserver();
117 ObjectType *
Print(std::ostream &os)
const
120 (*m_Pointer).Print(os);
134 m_DeleteObserverTag = -1;
135 m_ModifiedObserverTag = -1;
136 ObjectDelete.
Send(caller);
141 void AddDeleteAndModifiedObserver()
143 if (m_DeleteObserverTag == -1 && m_ModifiedObserverTag == -1 && m_Pointer !=
nullptr)
146 typename itk::MemberCommand<WeakPointer<TObjectType>>
::Pointer onObjectDelete =
147 itk::MemberCommand<WeakPointer<TObjectType>>
::New();
150 m_DeleteObserverTag = m_Pointer->AddObserver(itk::DeleteEvent(), onObjectDelete);
153 typename itk::MemberCommand<WeakPointer<TObjectType>>
::Pointer onObjectModified =
154 itk::MemberCommand<WeakPointer<TObjectType>>
::New();
157 m_ModifiedObserverTag = m_Pointer->AddObserver(itk::ModifiedEvent(), onObjectModified);
161 void RemoveDeleteAndModifiedObserver()
163 if (m_DeleteObserverTag >= 0 && m_ModifiedObserverTag >= 0 && m_Pointer !=
nullptr)
165 m_Pointer->RemoveObserver(m_DeleteObserverTag);
166 m_Pointer->RemoveObserver(m_ModifiedObserverTag);
168 m_DeleteObserverTag = -1;
169 m_ModifiedObserverTag = -1;
173 long m_DeleteObserverTag;
174 long m_ModifiedObserverTag;
177 ObjectType *m_Pointer;
180 template <
typename T>
181 std::ostream &operator<<(std::ostream &os, WeakPointer<T> p)
bool operator<(const WeakPointer &r) const
Message1< const itk::Object * > itkObjectEvent
bool operator!=(R r) const
ObjectType * Print(std::ostream &os) const
itkObjectEvent ObjectDelete
AddEvent is emitted when the object pointed to gets deleted.
bool operator>=(const WeakPointer &r) const
void OnObjectDelete(const itk::Object *caller, const itk::EventObject &)
Gets called when the object is deleted or modified.
DataCollection - Class to facilitate loading/accessing structured data.
bool operator>(const WeakPointer &r) const
void OnObjectModified(const itk::Object *caller, const itk::EventObject &)
bool operator<=(const WeakPointer &r) const
ObjectType * GetPointer() const
bool operator==(R r) const
WeakPointer & operator=(const WeakPointer &r)
Implements a weak reference to an object.
ObjectType * operator->() const
itkObjectEvent ObjectModified
AddEvent is emitted when the object pointed to gets modified.
WeakPointer(ObjectType *p)
WeakPointer(const WeakPointer< ObjectType > &p)
WeakPointer & operator=(ObjectType *r)
static itkEventMacro(BoundingShapeInteractionEvent, itk::AnyEvent) class MITKBOUNDINGSHAPE_EXPORT BoundingShapeInteractor Pointer New()
Basic interaction methods for mitk::GeometryData.