13 #ifndef mitkWeakPointer_h
14 #define mitkWeakPointer_h
16 #include <itkCommand.h>
28 : m_RawPointer(
nullptr)
33 : m_RawPointer(rawPointer)
35 this->AddDeleteEventObserver();
39 : m_RawPointer(other.m_RawPointer)
41 this->AddDeleteEventObserver();
45 : m_RawPointer(other.m_RawPointer)
47 other.RemoveDeleteEventObserver();
48 other.m_RawPointer =
nullptr;
49 this->AddDeleteEventObserver();
56 this->RemoveDeleteEventObserver();
72 this->RemoveDeleteEventObserver();
73 m_RawPointer = other.m_RawPointer;
74 this->AddDeleteEventObserver();
85 this->RemoveDeleteEventObserver();
86 m_RawPointer = other.m_RawPointer;
87 other.m_RawPointer =
nullptr;
88 this->AddDeleteEventObserver();
95 this->RemoveDeleteEventObserver();
96 m_RawPointer =
nullptr;
103 if (m_RawPointer != other)
105 this->RemoveDeleteEventObserver();
106 m_RawPointer = other;
107 this->AddDeleteEventObserver();
113 explicit operator bool() const noexcept
115 return nullptr != m_RawPointer;
130 m_DeleteEventCallback = callback;
134 void AddDeleteEventObserver()
136 if (
nullptr != m_RawPointer)
138 auto command = itk::SimpleMemberCommand<WeakPointer>::New();
139 command->SetCallbackFunction(
this, &WeakPointer::OnDeleteEvent);
140 m_ObserverTag = m_RawPointer->AddObserver(itk::DeleteEvent(), command);
144 void RemoveDeleteEventObserver()
146 if (
nullptr != m_RawPointer)
147 m_RawPointer->RemoveObserver(m_ObserverTag);
150 void OnDeleteEvent() noexcept
155 m_RawPointer =
nullptr;
157 if (m_DeleteEventCallback)
158 m_DeleteEventCallback();
168 return left.m_RawPointer == right.m_RawPointer;
175 return left.m_RawPointer == right;
182 return std::less<T*>()(left.m_RawPointer, right.m_RawPointer);
187 return std::less<T*>()(left.m_RawPointer, right);
192 return std::less<T*>()(left, right.m_RawPointer);
197 return std::less<T*>()(left.m_RawPointer, right);
202 return std::less<T*>()(left, right.m_RawPointer);
210 unsigned long m_ObserverTag;
219 return !(left == right);
225 return !(right < left);
237 return !(left < right);
249 return !(left == right);
261 return !(left == right);
267 return !(right < left);
279 return !(left < right);
285 return !(right < left);
297 return !(left < right);
303 return !(left == right);
309 return !(right < left);
321 return !(left < right);
327 return right == left;
333 return !(right == left);
339 return !(right < left);
351 return !(left < right);
357 return !(left == right);
363 return !(right < left);
375 return !(left < right);
381 return right == left;
387 return !(right == left);
393 return !(right < left);
405 return !(left < right);